├── .github ├── CODEOWNERS ├── FUNDING.yml └── workflows │ └── ci.yml ├── .gitignore ├── .swiftlint.yml ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── Package.swift ├── README.md ├── Sources └── MarkdownGenerator │ ├── Extensions.swift │ ├── MarkdownBlockquotes.swift │ ├── MarkdownCodeBlock.swift │ ├── MarkdownCollapsibleSection.swift │ ├── MarkdownConvertible.swift │ ├── MarkdownFile.swift │ ├── MarkdownHeader.swift │ ├── MarkdownImage.swift │ ├── MarkdownLink.swift │ ├── MarkdownList.swift │ └── MarkdownTable.swift ├── Tests ├── LinuxMain.swift └── MarkdownGeneratorTests │ ├── Internal │ └── MarkdownTableInternalTests.swift │ └── PublicInterface │ ├── ConsecutiveBlankLinesTests.swift │ ├── ExtensionsTests.swift │ ├── MarkdownBlockquotesTests.swift │ ├── MarkdownCodeBlockTests.swift │ ├── MarkdownCollapsibleSectionTests.swift │ ├── MarkdownConvertibleTests.swift │ ├── MarkdownFileTests.swift │ ├── MarkdownHeaderTests.swift │ ├── MarkdownImageTests.swift │ ├── MarkdownLinkTests.swift │ ├── MarkdownListTests.swift │ └── MarkdownTableTests.swift ├── codecov.yml └── docs ├── Package.md ├── PackageModules.dot ├── PackageModules.png ├── README.md ├── enums ├── CodeBlockStyle.md ├── MarkdownHeaderLevel.md ├── MarkdownHeaderStyle.md └── MarkdownListStyle.md ├── extensions ├── Array.md ├── MarkdownConvertible.md └── String.md ├── protocols └── MarkdownConvertible.md └── structs ├── MarkdownBlockquotes.md ├── MarkdownCodeBlock.md ├── MarkdownCollapsibleSection.md ├── MarkdownFile.md ├── MarkdownHeader.md ├── MarkdownImage.md ├── MarkdownLink.md ├── MarkdownList.md └── MarkdownTable.md /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @eneko 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: eneko 4 | patreon: eneko 5 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | schedule: 8 | - cron: 0 2 * * 1-5 9 | 10 | jobs: 11 | test: 12 | name: Test on ${{ matrix.os }} 13 | runs-on: ${{ matrix.os }} 14 | strategy: 15 | matrix: 16 | os: [ubuntu-18.04, ubuntu-16.04, macOS-10.15, macos-11.0] 17 | 18 | steps: 19 | - uses: actions/checkout@v1 20 | # - name: Install SwiftEnv 21 | # run: | 22 | # eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" 23 | # swiftenv install ${{ matrix.swift_version }} 24 | # swiftenv local ${{ matrix.swift_version }} 25 | # swiftenv version 26 | - name: Test 27 | run: | 28 | swift --version 29 | swift test --parallel 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | .DS_Store 6 | /.build 7 | /build 8 | /Packages 9 | /*.xcodeproj 10 | *.tar.gz 11 | .swiftpm 12 | 13 | ## Build generated 14 | build/ 15 | DerivedData/ 16 | 17 | ## Various settings 18 | *.pbxuser 19 | !default.pbxuser 20 | *.mode1v3 21 | !default.mode1v3 22 | *.mode2v3 23 | !default.mode2v3 24 | *.perspectivev3 25 | !default.perspectivev3 26 | xcuserdata/ 27 | 28 | ## Other 29 | *.moved-aside 30 | *.xccheckout 31 | *.xcscmblueprint 32 | 33 | ## Obj-C/Swift specific 34 | *.hmap 35 | *.ipa 36 | *.dSYM.zip 37 | *.dSYM 38 | 39 | ## Playgrounds 40 | timeline.xctimeline 41 | playground.xcworkspace 42 | 43 | # Swift Package Manager 44 | # 45 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 46 | # Packages/ 47 | # Package.pins 48 | .build/ 49 | 50 | # CocoaPods 51 | # 52 | # We recommend against adding the Pods directory to your .gitignore. However 53 | # you should judge for yourself, the pros and cons are mentioned at: 54 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 55 | # 56 | # Pods/ 57 | 58 | # Carthage 59 | # 60 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 61 | # Carthage/Checkouts 62 | 63 | Carthage/Build 64 | 65 | # fastlane 66 | # 67 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 68 | # screenshots whenever they are needed. 69 | # For more information about the recommended setup visit: 70 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 71 | 72 | fastlane/report.xml 73 | fastlane/Preview.html 74 | fastlane/screenshots 75 | fastlane/test_output 76 | -------------------------------------------------------------------------------- /.swiftlint.yml: -------------------------------------------------------------------------------- 1 | opt_in_rules: 2 | - attributes 3 | - closure_end_indentation 4 | - closure_spacing 5 | - conditional_returns_on_newline 6 | - empty_count 7 | - fatal_error_message 8 | - first_where 9 | - force_unwrapping 10 | - joined_default_parameter 11 | - let_var_whitespace 12 | - nimble_operator 13 | - no_extension_access_modifier 14 | - number_separator 15 | - object_literal 16 | - operator_usage_whitespace 17 | - overridden_super_call 18 | - pattern_matching_keywords 19 | - private_outlet 20 | - prohibited_super_call 21 | - quick_discouraged_call 22 | - redundant_nil_coalescing 23 | - single_test_class 24 | - strict_fileprivate 25 | - switch_case_on_newline 26 | - trailing_closure 27 | - unneeded_parentheses_in_closure_argument 28 | - vertical_parameter_alignment_on_call 29 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: generic 2 | 3 | jobs: 4 | include: 5 | - stage: Continuous Integration 6 | name: Linux Swift 4.1 7 | os: linux 8 | dist: trusty 9 | sudo: required 10 | install: 11 | - eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" 12 | - swiftenv install 4.1 13 | - swiftenv local 4.1 14 | - swift --version 15 | script: 16 | - swift test --parallel 17 | - stage: Continuous Integration 18 | name: Linux Swift 4.2 19 | os: linux 20 | dist: trusty 21 | sudo: required 22 | install: 23 | - eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" 24 | - swiftenv install 4.2 25 | - swiftenv local 4.2 26 | - swift --version 27 | script: 28 | - swift test --parallel 29 | - stage: Continuous Integration 30 | name: macOS Swift 4.1 31 | os: osx 32 | osx_image: xcode9.3 33 | script: 34 | - swift test --parallel 35 | - stage: Continuous Integration 36 | name: macOS Swift 4.1.2 37 | os: osx 38 | osx_image: xcode9.4 39 | script: 40 | - swift test --parallel 41 | - stage: Continuous Integration 42 | name: macOS Swift 4.2 43 | os: osx 44 | osx_image: xcode10 45 | script: 46 | - swift test --parallel 47 | - stage: Continuous Integration 48 | name: Code Coverage (Swift 4.1) 49 | os: osx 50 | osx_image: xcode9.3 51 | script: 52 | - swift package generate-xcodeproj --enable-code-coverage 53 | - xcodebuild -scheme MarkdownGenerator-Package test 54 | after_success: 55 | - bash <(curl -s https://codecov.io/bash) 56 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Master 2 | 3 | ### Breaking changes 4 | - None 5 | 6 | ### Enhancements 7 | - None 8 | 9 | ### Other updates 10 | - None 11 | 12 | 13 | ## 1.0.0 14 | 15 | ### Breaking changes 16 | - None 17 | 18 | ### Enhancements 19 | - Pretty Markdown tables 20 | 21 | ### Other updates 22 | - Update license to Apache 2.0 23 | 24 | 25 | ## 0.5.0 26 | 27 | ### Breaking changes 28 | - None 29 | 30 | ### Enhancements 31 | - None 32 | 33 | ### Other updates 34 | - Fix file writing when base path is empty. 35 | 36 | 37 | ## 0.4.0 38 | 39 | ### Breaking Changes 40 | - None 41 | 42 | ### Enhancements 43 | - None 44 | 45 | ### Other updates 46 | - Add support for Swift 4.1 47 | 48 | 49 | ## 0.3.0 50 | 51 | ### Enhancements 52 | - Add support for collapsible blocks on GitHub.com and rendered GitHub Pages. 53 | 54 | 55 | ## 0.2.1 56 | 57 | ### Fixes 58 | - Fix issue where indentation was removed when removing duplicate blank lines. 59 | 60 | 61 | ## 0.2.0 62 | 63 | ### Enhancements 64 | - Add MarkdownCodeBlock 65 | - Add MarkdownCollapsibleSection 66 | 67 | 68 | ## 0.1.2 69 | 70 | ### Changes 71 | - Revert Blockquote formatting for proper rendering on GitHub.com 72 | 73 | 74 | ## 0.1.1 75 | 76 | ### Changes 77 | - Remove Blockquote for empty lines 78 | 79 | 80 | ## 0.1.0 81 | 82 | - Initial Release 83 | 84 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at github@enekoalonso.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | If you find an issue, just [open a ticket](https://github.com/eneko/MarkdownGenerator/issues/new) 2 | on it. Pull requests are warmly welcome as well. 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright (c) 2017 Eneko Alonso (https://enekoalonso.com) 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: docs 2 | 3 | docs: 4 | sourcedocs generate --clean --spm-module MarkdownGenerator --output-folder docs --min-acl public 5 | sourcedocs package -o docs 6 | 7 | test: 8 | swift test --parallel 9 | 10 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:4.0 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "MarkdownGenerator", 6 | products: [ 7 | .library(name: "MarkdownGenerator", targets: ["MarkdownGenerator"]) 8 | ], 9 | dependencies: [], 10 | targets: [ 11 | .target(name: "MarkdownGenerator", dependencies: []), 12 | .testTarget(name: "MarkdownGeneratorTests", dependencies: ["MarkdownGenerator"]) 13 | ] 14 | ) 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MarkdownGenerator 2 | 3 | 4 | ![Release](https://img.shields.io/github/release/eneko/markdowngenerator.svg) 5 | ![Swift 4.0+](https://img.shields.io/badge/Swift-4.0+-orange.svg) 6 | [![Build Status](https://travis-ci.com/eneko/MarkdownGenerator.svg?branch=main)](https://travis-ci.com/eneko/MarkdownGenerator) 7 | ![CI](https://github.com/eneko/MarkdownGenerator/workflows/CI/badge.svg) 8 | [![codecov](https://codecov.io/gh/eneko/MarkdownGenerator/branch/master/graph/badge.svg)](https://codecov.io/gh/eneko/MarkdownGenerator) 9 | [![Swift Package Manager Compatible](https://img.shields.io/badge/spm-compatible-brightgreen.svg)](https://swift.org/package-manager) 10 | ![Linux Compatible](https://img.shields.io/badge/linux-compatible%20🐧-brightgreen.svg) 11 | 12 | A small Swift library to generate Markdown documents. 13 | 14 | **Features** 15 | - ✅ Easily generate Markdown from structured data 16 | - ✅ Extendible: make your classes and structs conform to `MarkdownConvertible` 17 | - ✅ Swift Package Manager compatible (Swift 4.0+) 18 | - ✅ Linux compatible 🐧 19 | 20 | 21 | ## MarkdownConvertible 22 | Types conforming to the `MarkdownConvertible` protocol can be rendered as a 23 | markdown string, by implementing the `.markdown` computed property. 24 | 25 | Out of the box, `MarkdownGenerator` provides the following Markdown elements: 26 | 27 | - Unordered lists 28 | - Ordered lists 29 | - Tables 30 | - Block-quotes 31 | - Code Blocks 32 | - Collapsible Blocks 33 | - Images 34 | - Links 35 | - Headings 36 | 37 | Please take a look at the following examples, or read the [reference documentation](/docs). 38 | 39 | ### Lists 40 | List can be nested to any levels and contain single or multi-line items. Lists can be ordered, unordered, or mixed. 41 | 42 | ```swift 43 | let list = MarkdownList(items: ["🍏", "🍌", "🍊", "🍇"]) 44 | print(list.markdown) 45 | ``` 46 | 47 | Generates the following output: 48 | 49 | - 🍏 50 | - 🍌 51 | - 🍊 52 | - 🍇 53 | 54 | Which renders as: 55 | 56 | - 🍏 57 | - 🍌 58 | - 🍊 59 | - 🍇 60 | 61 | 62 | ### Tables 63 | While Markdown didn't have support for tables originally, most modern Markdown readers (including GitHub) properly render tables nowadays. 64 | 65 | ```swift 66 | let data: [[String]] = [ 67 | ["🍏", "Apple", "Fruits"], 68 | ["🍊", "Orange", "Fruits"], 69 | ["🥖", "Bread", "Bakery"], 70 | ] 71 | let table = MarkdownTable(headers: ["", "Name", "Department"], data: data) 72 | print(table.markdown) 73 | ``` 74 | 75 | Generates the following output: 76 | 77 | | | Name | Department | 78 | | -- | ------ | ---------- | 79 | | 🍏 | Apple | Fruits | 80 | | 🍊 | Orange | Fruits | 81 | | 🥖 | Bread | Bakery | 82 | 83 | Which renders as: 84 | 85 | | | Name | Department | 86 | | -- | ------ | ---------- | 87 | | 🍏 | Apple | Fruits | 88 | | 🍊 | Orange | Fruits | 89 | | 🥖 | Bread | Bakery | 90 | 91 | Pretty tables 🎉 92 | 93 | ### Blockquotes 94 | 95 | Any `MarkdownConvertible` content (including `String`) can be easily `.blockquoted`. 96 | 97 | ```swift 98 | let input = """ 99 | ## This is a header. 100 | 101 | 1. This is the first list item. 102 | 2. This is the second list item. 103 | 104 | Here's some example code: 105 | 106 | return shell_exec("echo $input | $markdown_script"); 107 | 108 | > This is a quote. 109 | """ 110 | 111 | print(input.blockquoted.markdown) 112 | ``` 113 | 114 | Generates the following output: 115 | 116 | > ## This is a header. 117 | > 118 | > 1. This is the first list item. 119 | > 2. This is the second list item. 120 | > 121 | > Here's some example code: 122 | > 123 | > return shell_exec("echo $input | $markdown_script"); 124 | > 125 | > > This is a quote. 126 | 127 | Which renders as: 128 | 129 | > ## This is a header. 130 | > 131 | > 1. This is the first list item. 132 | > 2. This is the second list item. 133 | > 134 | > Here's some example code: 135 | > 136 | > return shell_exec("echo $input | $markdown_script"); 137 | > 138 | > > This is a quote. 139 | 140 | 141 | ### Collapsible Blocks 142 | Collapsible blocks look great on GitHub and other Markdown viewers. Great way to provide detailed content without cluttering the output. 143 | 144 | ```swift 145 | let details: [MarkdownConvertible] = [ 146 | MarkdownHeader(title: "Title"), 147 | MarkdownList(items: ["🐶", "🐱", "🦊"]), 148 | MarkdownTable(headers: ["Name", "Count"], data: [["Dog", "1"], ["Cat", "2"]]), 149 | MarkdownCodeBlock(code: "let foo = Bar()", style: .backticks(language: "swift")) 150 | ] 151 | 152 | print(MarkdownCollapsibleSection(summary: "This is cool stuff", details: details).markdown) 153 | ``` 154 | 155 | Generates the following output: 156 | 157 |
This is cool stuff 158 | 159 | # Title 160 | 161 | - 🐶 162 | - 🐱 163 | - 🦊 164 | 165 | | Name | Count | 166 | | ---- | ----- | 167 | | Dog | 1 | 168 | | Cat | 2 | 169 | 170 | ```swift 171 | let foo = Bar() 172 | ``` 173 |
174 | 175 | Which renders as (click to expand): 176 | 177 |
This is cool stuff 178 | 179 | # Title 180 | 181 | - 🐶 182 | - 🐱 183 | - 🦊 184 | 185 | | Name | Count | 186 | | ---- | ----- | 187 | | Dog | 1 | 188 | | Cat | 2 | 189 | 190 | ```swift 191 | let foo = Bar() 192 | ``` 193 |
194 | 195 | 196 | ## Contact 197 | Follow and/or contact me on Twitter at [@eneko](https://www.twitter.com/eneko). 198 | 199 | 200 | ## Contributions 201 | If you find an issue, just [open a ticket](https://github.com/eneko/MarkdownGenerator/issues/new) 202 | on it. Pull requests are warmly welcome as well. 203 | 204 | 205 | ## License 206 | MarkdownGenerator is licensed under the Apache 2.0 license. See [LICENSE](/LICENSE) for more info. 207 | -------------------------------------------------------------------------------- /Sources/MarkdownGenerator/Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Extensions.swift 3 | // MarkdownGenerator 4 | // 5 | // Created by Eneko Alonso on 10/8/17. 6 | // 7 | 8 | import Foundation 9 | 10 | // MARK: - String: MarkdownConvertible 11 | 12 | extension String: MarkdownConvertible { 13 | 14 | /// Render a string of text as Markdown. No transformations applied. 15 | public var markdown: String { 16 | return self 17 | } 18 | 19 | /// Remove consecutive blank lines from a string output 20 | public var removingConsecutiveBlankLines: String { 21 | let lines = components(separatedBy: .newlines) 22 | let filtered: [(offset: Int, element: String)] = lines.enumerated().filter { line in 23 | return line.offset == 0 || 24 | lines[line.offset].trimmingCharacters(in: .whitespaces).isEmpty == false || 25 | lines[line.offset - 1].trimmingCharacters(in: .whitespaces).isEmpty == false 26 | } 27 | return filtered.map { $0.element }.joined(separator: String.newLine) 28 | } 29 | 30 | static let newLine = "\n" 31 | } 32 | 33 | extension Array: MarkdownConvertible { 34 | /// Render a collection of Markdown convertible elements. 35 | /// 36 | /// Elements are rendered separated by one blank line, to prevent formatting interference. 37 | public var markdown: String { 38 | return compactMap { ($0 as? MarkdownConvertible)?.markdown }.joined(separator: "\n\n") 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Sources/MarkdownGenerator/MarkdownBlockquotes.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownBlockquotes.swift 3 | // MarkdownGenerator 4 | // 5 | // Created by Eneko Alonso on 10/8/17. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Render Markdown Blockquotes 11 | /// 12 | /// Markdown uses email-style > characters for blockquoting. 13 | /// 14 | /// > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, 15 | /// > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. 16 | /// > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. 17 | /// > 18 | /// > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse 19 | /// > id sem consectetuer libero luctus adipiscing. 20 | /// 21 | public struct MarkdownBlockquotes: MarkdownConvertible { 22 | 23 | let content: MarkdownConvertible 24 | 25 | /// MarkdownBlockquotes initializer 26 | /// 27 | /// - Parameter content: Content to be block-quoted with '> ' 28 | public init(content: MarkdownConvertible) { 29 | self.content = content 30 | } 31 | 32 | /// Generated Markdown output 33 | public var markdown: String { 34 | return content.blockquoted.markdown 35 | } 36 | } 37 | 38 | // MARK: - MarkdownBlockquote 39 | extension MarkdownConvertible { 40 | /// Quoted version of the generated Markdown output of the current entity. 41 | /// 42 | /// "## H2 Header".blockquoted // > ## H2 Header 43 | /// 44 | public var blockquoted: MarkdownConvertible { 45 | let input = markdown 46 | if input.isEmpty { 47 | return "" 48 | } 49 | let lines = markdown.components(separatedBy: String.newLine) 50 | let quoted: [String] = lines.map { "> \($0)".trimmingCharacters(in: .whitespaces) } 51 | return quoted.joined(separator: String.newLine) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Sources/MarkdownGenerator/MarkdownCodeBlock.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownCodeBlock.swift 3 | // MarkdownGenerator 4 | // 5 | // Created by Eneko Alonso on 10/18/17. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct MarkdownCodeBlock: MarkdownConvertible { 11 | let code: String 12 | let style: CodeBlockStyle 13 | 14 | public init(code: String, style: CodeBlockStyle = .indented) { 15 | self.code = code 16 | self.style = style 17 | } 18 | 19 | /// Generated Markdown output 20 | public var markdown: String { 21 | switch style { 22 | case .indented: 23 | let lines = code.components(separatedBy: .newlines) 24 | let indented: [String] = lines.map { $0.isEmpty ? "" : " \($0)" } 25 | return indented.joined(separator: String.newLine) 26 | case .backticks(let language): 27 | return """ 28 | ```\(language) 29 | \(code) 30 | ``` 31 | """ 32 | } 33 | } 34 | 35 | } 36 | 37 | /// Markdown format for the generated code block 38 | /// 39 | /// - indented: Code block is indented by 4-spaces 40 | /// - backticks: Code block is wrapped with ``` 41 | public enum CodeBlockStyle { 42 | case indented 43 | case backticks(language: String) 44 | } 45 | -------------------------------------------------------------------------------- /Sources/MarkdownGenerator/MarkdownCollapsibleSection.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownCollapsibleSection.swift 3 | // MarkdownGenerator 4 | // 5 | // Created by Eneko Alonso on 10/18/17. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Collapsible blocks are a great way to hide large portions of content 11 | /// that, while valuable to the reader, would result on a lot of noise. 12 | /// 13 | /// Collapsible blocks work well in most Markdown readers, including 14 | /// GitHub.com and rendered GitHub Pages. However, because they rely on 15 | /// HTML tags, they will make the _raw_ markdown output harder to read. 16 | /// 17 | /// ```html 18 | ///
Block Title 19 | /// 20 | /// Block details. 21 | /// 22 | ///
23 | /// ``` 24 | public struct MarkdownCollapsibleSection: MarkdownConvertible { 25 | let summary: String 26 | let details: MarkdownConvertible 27 | 28 | /// MarkdownCollapsibleSection initializer 29 | /// 30 | /// - Parameters: 31 | /// - summary: Plain text or HTML string containing the block title. 32 | /// - details: Markdown convertible elements to include in the collapsible block. 33 | public init(summary: String, details: MarkdownConvertible) { 34 | self.summary = summary 35 | self.details = details 36 | } 37 | 38 | /// Generated Markdown output 39 | public var markdown: String { 40 | return """ 41 |
\(summary) 42 | 43 | \(details.markdown) 44 | 45 |
46 | """ 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Sources/MarkdownGenerator/MarkdownConvertible.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownConvertible.swift 3 | // MarkdownGenerator 4 | // 5 | // Created by Eneko Alonso on 10/8/17. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Defines an entity that can be represented as Markdown. 11 | public protocol MarkdownConvertible { 12 | 13 | /// Generated Markdown output representing the current entity. 14 | var markdown: String { get } 15 | } 16 | -------------------------------------------------------------------------------- /Sources/MarkdownGenerator/MarkdownFile.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownFile.swift 3 | // MarkdownGenerator 4 | // 5 | // Created by Eneko Alonso on 10/8/17. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Helper structure to write Markdown files to disk. 11 | public struct MarkdownFile { 12 | 13 | /// Name of the Markdown file, without extension. 14 | public let filename: String 15 | 16 | /// Path where the Markdown file will be written to. 17 | /// 18 | /// Path can be absolute or relative to the working directory. It should 19 | /// not contain a trailing slash, nor the name of the file to write. 20 | /// 21 | /// Path will be created if it doesn't already exist in the system. 22 | public let basePath: String 23 | 24 | /// MarkdownConvertible entity that will be rendered 25 | /// as the Markdown content of the file. Can be an `Array`. 26 | public var content: MarkdownConvertible 27 | 28 | /// MarkdownFile initializer 29 | /// 30 | /// - Parameters: 31 | /// - filename: Name of the Markdown file, without extension. 32 | /// - basePath: Path where the Markdown file will be written to. 33 | /// 34 | /// Path can be absolute or relative to the working directory. It should 35 | /// not contain a trailing slash, nor the name of the file to write. 36 | /// 37 | /// Path will be created if it doesn't already exist in the system. 38 | /// 39 | /// - content: MarkdownConvertible entity that will be rendered 40 | /// as the Markdown content of the file. Can be an `Array`. 41 | public init(filename: String, basePath: String = "", content: MarkdownConvertible) { 42 | self.filename = filename.trimmingCharacters(in: .whitespacesAndNewlines) 43 | self.basePath = basePath.trimmingCharacters(in: .whitespacesAndNewlines) 44 | self.content = content 45 | } 46 | 47 | /// Computed property containing the file path (`/.md`) 48 | public var filePath: String { 49 | return basePath.isEmpty ? "\(filename).md" : "\(basePath)/\(filename).md" 50 | } 51 | 52 | /// Generate and write the Markdown file to disk. 53 | /// 54 | /// - Will override the file if already existing, or create a new one. 55 | /// - Will create the path directory structure if it does not exists. 56 | /// 57 | /// - Throws: Throws an exception if the file could not be written to disk, or 58 | /// if the path could not be created. 59 | public func write() throws { 60 | try createDirectory(path: basePath) 61 | let output = content.markdown.removingConsecutiveBlankLines 62 | try output.write(toFile: filePath, atomically: true, encoding: .utf8) 63 | } 64 | 65 | private func createDirectory(path: String) throws { 66 | guard path.isEmpty == false else { 67 | return 68 | } 69 | var isDir: ObjCBool = false 70 | if FileManager.default.fileExists(atPath: path, isDirectory: &isDir) == false { 71 | try FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil) 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Sources/MarkdownGenerator/MarkdownHeader.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownHeader.swift 3 | // MarkdownGenerator 4 | // 5 | // Created by Eneko Alonso on 10/8/17. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Renders a Markdown Header 11 | /// 12 | /// Markdown supports two styles of headers, Setext and atx. 13 | /// 14 | /// Setext-style headers are “underlined” using equal signs (for first-level headers) 15 | /// and dashes (for second-level headers). For example: 16 | /// 17 | /// This is an H1 18 | /// ============= 19 | /// 20 | /// This is an H2 21 | /// ------------- 22 | /// 23 | /// Atx-style headers use 1-6 hash characters at the start of the line, corresponding 24 | /// to HTML header levels 1-6. For example: 25 | /// 26 | /// # This is an H1 27 | /// 28 | /// ## This is an H2 29 | /// 30 | /// ###### This is an H6 31 | /// 32 | /// Atx-style headers can be closed (this is purely cosmetic): 33 | /// 34 | /// # This is an H1 # 35 | /// 36 | /// ## This is an H2 ## 37 | /// 38 | /// ### This is an H3 ### 39 | /// 40 | public struct MarkdownHeader: MarkdownConvertible { 41 | let title: String 42 | let level: MarkdownHeaderLevel 43 | let style: MarkdownHeaderStyle 44 | let close: Bool 45 | 46 | /// MarkdownHeader initializer. 47 | /// 48 | /// - Parameters: 49 | /// - title: Title of the header element 50 | /// - level: Header level (`h1`, `h2`... `h6`) 51 | /// - style: Header style: `setex` (underlined) or `atx` ('#') (defaults to `atx`). 52 | /// Setex format is only available for first-level (using equal signs) and 53 | /// second-level headers (using dashes). 54 | /// - close: Close `atx` style headers (defaults to `false`). When false, headers 55 | /// only include the '#' prefix. When `true`, headers also include the 56 | /// trailing '#' suffix: 57 | /// 58 | /// ### Third-level Header ### 59 | /// 60 | /// - SeeAlso: MarkdownHeaderLevel, MarkdownHeaderStyle 61 | public init(title: String, level: MarkdownHeaderLevel = .h1, style: MarkdownHeaderStyle = .atx, 62 | close: Bool = false) { 63 | self.title = title 64 | self.level = level 65 | self.style = level.rawValue < 3 ? style : .atx 66 | self.close = close 67 | } 68 | 69 | /// Generated Markdown output 70 | public var markdown: String { 71 | switch style { 72 | case .atx: 73 | let prefix = Array(repeating: "#", count: level.rawValue).joined() 74 | let suffix = close ? prefix : "" 75 | return "\(prefix) \(title) \(suffix)".trimmingCharacters(in: .whitespacesAndNewlines) 76 | case .setex: 77 | let symbol = level == .h1 ? "=" : "-" 78 | let underline = Array(repeating: symbol, count: title.count).joined() 79 | return """ 80 | \(title) 81 | \(underline) 82 | """ 83 | } 84 | } 85 | } 86 | 87 | /// Markdown Header level 88 | /// 89 | /// - h1: first-level headers 90 | /// 91 | /// # H1 Header 92 | /// 93 | /// - h2: second-level headers 94 | /// 95 | /// ## H2 Header 96 | /// 97 | /// - h3: third-level headers 98 | /// 99 | /// ### H3 Header 100 | /// 101 | /// - h4: fourth-level headers 102 | /// 103 | /// #### H4 Header 104 | /// 105 | /// - h5: fifth-level headers 106 | /// 107 | /// ##### H5 Header 108 | /// 109 | /// - h6: sixth-level headers 110 | /// 111 | /// ###### H6 Header 112 | /// 113 | public enum MarkdownHeaderLevel: Int { 114 | case h1 = 1 115 | case h2 116 | case h3 117 | case h4 118 | case h5 119 | case h6 120 | } 121 | 122 | /// Markdown Header render style 123 | /// 124 | /// - `setex`: Setext-style headers are “underlined” using equal signs (for first-level headers) 125 | /// and dashes (for second-level headers). For example: 126 | /// 127 | /// This is a Setex H1 Header 128 | /// ========================= 129 | /// 130 | /// This is a Setex H2 Header 131 | /// ------------------------- 132 | /// 133 | /// - `atx`: Atx-style headers use 1-6 hash characters at the start of the line, corresponding 134 | /// to header levels 1-6. For example: 135 | /// 136 | /// # This is an Atx H1 Header 137 | /// 138 | /// ## This is an Atx H2 Header 139 | /// 140 | /// ###### This is a closed Atx H6 Header ###### 141 | /// 142 | public enum MarkdownHeaderStyle { 143 | case setex 144 | case atx 145 | } 146 | -------------------------------------------------------------------------------- /Sources/MarkdownGenerator/MarkdownImage.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownImage.swift 3 | // MarkdownGenerator 4 | // 5 | // Created by Eneko Alonso on 10/9/17. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Render an HTML image in Markdown format 11 | /// 12 | /// MarkdownImage(url: "http://example.com/image.jpg", altText: "SourceDocs Header").markdown 13 | /// 14 | /// Would render as: 15 | /// 16 | /// ![SourceDocs Header](http://example.com/image.jpg) 17 | /// 18 | public struct MarkdownImage: MarkdownConvertible { 19 | 20 | /// URL where the image is located. Can be absolute or relative. 21 | public let url: String 22 | 23 | /// Alternate text to display on non-graphic browsers or to be used by screen readers. 24 | public let altText: String 25 | 26 | /// MarkdownImage initializer 27 | /// 28 | /// - Parameters: 29 | /// - url: URL where the image is located. Can be absolute or relative. 30 | /// - altText: Alternate text to display on non-graphic browsers or to be used by screen readers. 31 | public init(url: String, altText: String = "") { 32 | self.url = url 33 | self.altText = altText 34 | } 35 | 36 | /// Generated Markdown output 37 | public var markdown: String { 38 | return "![\(altText)](\(url))" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Sources/MarkdownGenerator/MarkdownLink.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownLink.swift 3 | // MarkdownGenerator 4 | // 5 | // Created by Eneko Alonso on 10/9/17. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Render an HTML link in Markdown format 11 | /// 12 | /// MarkdownLink(text: "Google", url: "https://example.com").markdown 13 | /// 14 | /// Would render as: 15 | /// 16 | /// [Google](https://example.com) 17 | /// 18 | public struct MarkdownLink: MarkdownConvertible { 19 | 20 | /// Text to display as hyper-linked. 21 | public let text: String 22 | 23 | /// Link URL, can be absolute, relative, or #local. 24 | public let url: String 25 | 26 | /// MarkdownLink initializer 27 | /// 28 | /// - Parameters: 29 | /// - text: Text to display as hyper-linked. 30 | /// - url: Link URL, can be absolute, relative, or #local. 31 | public init(text: String, url: String) { 32 | self.text = text 33 | self.url = url 34 | } 35 | 36 | /// Generated Markdown output 37 | public var markdown: String { 38 | return "[\(text)](\(url))" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Sources/MarkdownGenerator/MarkdownList.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownList.swift 3 | // MarkdownGenerator 4 | // 5 | // Created by Eneko Alonso on 10/9/17. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Render a list of elements in Markdown format 11 | /// 12 | /// Unordered lists: 13 | /// 14 | /// - One item 15 | /// - Another item that expands to multiple 16 | /// lines. 17 | /// - A nested item. 18 | /// - Third-level. 19 | /// - Back to first-level. 20 | /// 21 | /// Ordered lists: 22 | /// 23 | /// 1. First item 24 | /// 1. Second item 25 | /// 1. Nested item (second-level) 26 | /// 1. Back to first-level 27 | /// 28 | public struct MarkdownList: MarkdownConvertible { 29 | let style: MarkdownListStyle 30 | 31 | /// List of items to be converted to a list. 32 | public var items: [MarkdownConvertible] 33 | 34 | /// MarkdownList initializer 35 | /// 36 | /// - Parameter items: List of items to be converted to a list. 37 | public init(items: [MarkdownConvertible], style: MarkdownListStyle = .unordered) { 38 | self.items = items 39 | self.style = style 40 | } 41 | 42 | /// Generated Markdown output 43 | public var markdown: String { 44 | return items.map { formatted(item: $0) }.joined(separator: String.newLine) 45 | } 46 | 47 | // Per Markdown documentation, indent all lines using 4 spaces. 48 | private func formatted(item: MarkdownConvertible) -> String { 49 | let symbol = style == .ordered ? "1. " : "- " 50 | var lines = item.markdown.components(separatedBy: String.newLine) 51 | let first = lines.removeFirst() 52 | let firstLine = item is MarkdownList ? " \(first)" : "\(symbol)\(first)" 53 | 54 | if lines.isEmpty { 55 | return firstLine 56 | } 57 | 58 | let blankLine = item is MarkdownList ? "" : String.newLine 59 | let indentedLines = lines.map { $0.isEmpty ? "" : " \($0)" }.joined(separator: String.newLine) + blankLine 60 | return """ 61 | \(firstLine) 62 | \(indentedLines) 63 | """ 64 | } 65 | 66 | } 67 | 68 | /// Specifies the type of list to be generated 69 | /// 70 | /// - ordered: Ordered lists use numbers followed by periods. 71 | /// - unordered: Unordered lists use hyphens as list markers. 72 | public enum MarkdownListStyle { 73 | case ordered 74 | case unordered 75 | } 76 | -------------------------------------------------------------------------------- /Sources/MarkdownGenerator/MarkdownTable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownTable.swift 3 | // MarkdownGenerator 4 | // 5 | // Created by Eneko Alonso on 10/9/17. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Render a two dimensional Markdown table. 11 | /// 12 | /// | | Name | Department | 13 | /// | -- | ------ | ---------- | 14 | /// | 🍏 | Apple | Fruits | 15 | /// | 🍊 | Orange | Fruits | 16 | /// | 🥖 | Bread | Bakery | 17 | /// 18 | /// *Notes*: 19 | /// - Markdown tables are not supported by all Markdown readers. 20 | /// - Table headers are required. 21 | /// - Table cells cannot contain multiple lines. New line characters are replaced by a space. 22 | public struct MarkdownTable: MarkdownConvertible { 23 | 24 | let headers: [String] 25 | let data: [[String]] 26 | 27 | /// MarkdownTable initializer 28 | /// 29 | /// - Parameters: 30 | /// - headers: List of table header titles. 31 | /// - data: Two-dimensional `String` array with the table content. Rows are defined by 32 | /// the outer array, columns are defined by the inner arrays. 33 | /// 34 | /// An array of rows, each row containing an array of columns. All rows should contain the same 35 | /// number of columns as the headers array, to avoid formatting issues. 36 | public init(headers: [String], data: [[String]]) { 37 | self.headers = headers.map { $0.isEmpty ? " " : $0 } 38 | self.data = data 39 | } 40 | 41 | /// Generated Markdown output 42 | public var markdown: String { 43 | let columnWidths = computeColumnWidths() 44 | if columnWidths.isEmpty { 45 | return .newLine 46 | } 47 | let headerRow = makeRow(values: pad(values: headers, lengths: columnWidths)) 48 | let separatorRow = makeRow(values: columnWidths.map { String(repeating: "-", count: $0) }) 49 | let dataRows = data.map { columns in 50 | return makeRow(values: pad(values: columns, lengths: columnWidths)) 51 | } 52 | return """ 53 | \(headerRow) 54 | \(separatorRow) 55 | \(dataRows.joined(separator: String.newLine)) 56 | """ 57 | } 58 | 59 | /// Return max length for each column, counting individual UTF16 characters for better emoji support. 60 | /// 61 | /// - Returns: Array of column widths 62 | func computeColumnWidths() -> [Int] { 63 | let rows = [headers] + data 64 | guard let maxColumns = rows.map({ $0.count }).max(), maxColumns > 0 else { 65 | return [] 66 | } 67 | let columnWidths = (0.. Int in 68 | return columnLength(values: rows.compactMap({ $0.get(at: columnIndex) })) 69 | } 70 | return columnWidths 71 | } 72 | 73 | func columnLength(values: [String]) -> Int { 74 | return values.map({ $0.utf16.count }).max() ?? 0 75 | } 76 | 77 | /// Pad array of strings to a given length, counting individual UTF16 characters 78 | /// 79 | /// - Parameters: 80 | /// - values: array of strings to pad 81 | /// - lengths: desired lengths 82 | /// - Returns: array of right-padded strings 83 | func pad(values: [String], lengths: [Int]) -> [String] { 84 | var values = values 85 | while values.count < lengths.count { 86 | values.append("") 87 | } 88 | return zip(values, lengths).map { value, length in 89 | value + String(repeating: " ", count: max(0, length - value.utf16.count)) 90 | } 91 | } 92 | 93 | /// Convert a String array into a markdown formatter table row. 94 | /// Table cells cannot contain multiple lines. New line characters are replaced by a space. 95 | /// 96 | /// - Parameter values: array of values 97 | /// - Returns: Markdown formatted row 98 | func makeRow(values: [String]) -> String { 99 | let values = values.map { value in 100 | value 101 | .replacingOccurrences(of: String.newLine, with: " ") 102 | .replacingOccurrences(of: "|", with: "\\|") 103 | } 104 | return "| " + values.joined(separator: " | ") + " |" 105 | } 106 | } 107 | 108 | extension Array { 109 | func get(at index: Int) -> Element? { 110 | guard (0.. This is a quote. 24 | """ 25 | 26 | let output = """ 27 | > ## This is a header. 28 | > 29 | > 1. This is the first list item. 30 | > 2. This is the second list item. 31 | > 32 | > Here's some example code: 33 | > 34 | > return shell_exec("echo $input | $markdown_script"); 35 | > 36 | > > This is a quote. 37 | """ 38 | 39 | func testBlockquotes() { 40 | XCTAssertEqual(MarkdownBlockquotes(content: input).markdown, output) 41 | } 42 | 43 | func testBlockquoted() { 44 | XCTAssertEqual(input.blockquoted.markdown, output) 45 | } 46 | 47 | func testNested() { 48 | XCTAssertEqual(input.blockquoted.blockquoted.markdown, output.blockquoted.markdown) 49 | } 50 | 51 | func testMultipleInputs() { 52 | XCTAssertEqual([input, input].blockquoted.markdown, [output, output].joined(separator: "\n>\n")) 53 | } 54 | 55 | func testSingleLine() { 56 | let input = """ 57 | Single line of text. 58 | """ 59 | XCTAssertEqual(input.blockquoted.markdown, "> Single line of text.") 60 | } 61 | 62 | func testWhitespaces() { 63 | XCTAssertEqual("".blockquoted.markdown, "") 64 | XCTAssertEqual("\n".blockquoted.markdown, ">\n>") 65 | XCTAssertEqual("\t".blockquoted.markdown, ">") 66 | } 67 | 68 | static var allTests = [ 69 | ("testBlockquotes", testBlockquotes), 70 | ("testBlockquoted", testBlockquoted), 71 | ("testNested", testNested), 72 | ("testMultipleInputs", testMultipleInputs), 73 | ("testSingleLine", testSingleLine), 74 | ("testWhitespaces", testWhitespaces) 75 | ] 76 | 77 | } 78 | -------------------------------------------------------------------------------- /Tests/MarkdownGeneratorTests/PublicInterface/MarkdownCodeBlockTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownCodeBlockTests.swift 3 | // MarkdownGeneratorTests 4 | // 5 | // Created by Eneko Alonso on 10/18/17. 6 | // 7 | 8 | import XCTest 9 | import MarkdownGenerator 10 | 11 | class MarkdownCodeBlockTests: XCTestCase { 12 | 13 | func testEmpty() { 14 | let input = """ 15 | """ 16 | let output = """ 17 | """ 18 | XCTAssertEqual(MarkdownCodeBlock(code: input).markdown, output) 19 | } 20 | 21 | func testIndented() { 22 | let input = """ 23 | /// Defines an entity that can be represented as Markdown. 24 | public protocol MarkdownConvertible { 25 | 26 | /// Generated Markdown output representing the current entity. 27 | var markdown: String { get } 28 | } 29 | """ 30 | let output = """ 31 | /// Defines an entity that can be represented as Markdown. 32 | public protocol MarkdownConvertible { 33 | 34 | /// Generated Markdown output representing the current entity. 35 | var markdown: String { get } 36 | } 37 | """ 38 | XCTAssertEqual(MarkdownCodeBlock(code: input).markdown, output) 39 | } 40 | 41 | func testBackticks() { 42 | let input = """ 43 | /// Defines an entity that can be represented as Markdown. 44 | public protocol MarkdownConvertible { 45 | 46 | /// Generated Markdown output representing the current entity. 47 | var markdown: String { get } 48 | } 49 | """ 50 | let output = """ 51 | ``` 52 | /// Defines an entity that can be represented as Markdown. 53 | public protocol MarkdownConvertible { 54 | 55 | /// Generated Markdown output representing the current entity. 56 | var markdown: String { get } 57 | } 58 | ``` 59 | """ 60 | XCTAssertEqual(MarkdownCodeBlock(code: input, style: .backticks(language: "")).markdown, output) 61 | } 62 | 63 | func testBackticksSwift() { 64 | let input = """ 65 | /// Defines an entity that can be represented as Markdown. 66 | public protocol MarkdownConvertible { 67 | 68 | /// Generated Markdown output representing the current entity. 69 | var markdown: String { get } 70 | } 71 | """ 72 | let output = """ 73 | ```swift 74 | /// Defines an entity that can be represented as Markdown. 75 | public protocol MarkdownConvertible { 76 | 77 | /// Generated Markdown output representing the current entity. 78 | var markdown: String { get } 79 | } 80 | ``` 81 | """ 82 | XCTAssertEqual(MarkdownCodeBlock(code: input, style: .backticks(language: "swift")).markdown, output) 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /Tests/MarkdownGeneratorTests/PublicInterface/MarkdownCollapsibleSectionTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownCollapsibleSectionTests.swift 3 | // MarkdownGeneratorTests 4 | // 5 | // Created by Eneko Alonso on 10/18/17. 6 | // 7 | 8 | import XCTest 9 | import MarkdownGenerator 10 | 11 | class MarkdownCollapsibleSectionTests: XCTestCase { 12 | 13 | func testSimple() { 14 | let output = """ 15 |
Hello 16 | 17 | World 18 | 19 |
20 | """ 21 | XCTAssertEqual(MarkdownCollapsibleSection(summary: "Hello", details: "World").markdown, output) 22 | } 23 | 24 | func testComplex() { 25 | let output = """ 26 |
This is cool stuff 27 | 28 | # Title 29 | 30 | - 🐶 31 | - 🐱 32 | - 🦊 33 | 34 | | Name | Count | 35 | | ---- | ----- | 36 | | Dog | 1 | 37 | | Cat | 2 | 38 | 39 | ```swift 40 | let foo = Bar() 41 | ``` 42 | 43 |
44 | """ 45 | 46 | let details: [MarkdownConvertible] = [ 47 | MarkdownHeader(title: "Title"), 48 | MarkdownList(items: ["🐶", "🐱", "🦊"]), 49 | MarkdownTable(headers: ["Name", "Count"], data: [["Dog", "1"], ["Cat", "2"]]), 50 | MarkdownCodeBlock(code: "let foo = Bar()", style: .backticks(language: "swift")) 51 | ] 52 | XCTAssertEqual(MarkdownCollapsibleSection(summary: "This is cool stuff", details: details).markdown, output) 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /Tests/MarkdownGeneratorTests/PublicInterface/MarkdownConvertibleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownConvertibleTests.swift 3 | // MarkdownGeneratorTests 4 | // 5 | // Created by Eneko Alonso on 10/9/17. 6 | // 7 | 8 | import XCTest 9 | import MarkdownGenerator 10 | 11 | class MarkdownConvertibleTests: XCTestCase { 12 | 13 | func testCustomStructureAdoptsProtocol() { 14 | XCTAssertEqual(Contact(firstName: "Bob", lastName: "Jones").markdown, "**Jones**, Bob") 15 | } 16 | 17 | static var allTests = [ 18 | ("testCustomStructureAdoptsProtocol", testCustomStructureAdoptsProtocol) 19 | ] 20 | 21 | } 22 | 23 | // Custom structure that can be rendered as Markdown 24 | struct Contact: MarkdownConvertible { 25 | let firstName: String 26 | let lastName: String 27 | 28 | var markdown: String { 29 | return "**\(lastName)**, \(firstName)" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tests/MarkdownGeneratorTests/PublicInterface/MarkdownFileTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownFileTests.swift 3 | // MarkdownGeneratorTests 4 | // 5 | // Created by Eneko Alonso on 10/9/17. 6 | // 7 | 8 | import XCTest 9 | import MarkdownGenerator 10 | 11 | class MarkdownFileTests: XCTestCase { 12 | 13 | func testFilePath() { 14 | let file = MarkdownFile(filename: "Test", basePath: "Path/To/File", content: "") 15 | XCTAssertEqual(file.filePath, "Path/To/File/Test.md") 16 | } 17 | 18 | func testFileWrite() throws { 19 | let content = MarkdownHeader(title: "Hello World!") 20 | let file = MarkdownFile(filename: "WriteTest", content: content) 21 | try file.write() 22 | 23 | let fileContent = try String(contentsOfFile: "WriteTest.md") 24 | XCTAssertEqual(fileContent, content.markdown) 25 | } 26 | 27 | func testFileWriteWithFolder() throws { 28 | let content = MarkdownHeader(title: "Hello World!") 29 | let file = MarkdownFile(filename: "WriteTest", basePath: "AFolder", content: content) 30 | try file.write() 31 | 32 | let fileContent = try String(contentsOfFile: "AFolder/WriteTest.md") 33 | XCTAssertEqual(fileContent, content.markdown) 34 | } 35 | 36 | static var allTests = [ 37 | ("testFilePath", testFilePath) 38 | ] 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Tests/MarkdownGeneratorTests/PublicInterface/MarkdownHeaderTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BockElementsTests.swift 3 | // MarkdownGeneratorTests 4 | // 5 | // Created by Eneko Alonso on 10/8/17. 6 | // 7 | 8 | import XCTest 9 | import MarkdownGenerator 10 | 11 | class MarkdownHeaderTests: XCTestCase { 12 | 13 | func testDefaultHeader() { 14 | XCTAssertEqual(MarkdownHeader(title: "Header Title").markdown, "# Header Title") 15 | } 16 | 17 | func testHeaderLevelsAtx() { 18 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h1).markdown, "# Header Title") 19 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h2).markdown, "## Header Title") 20 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h3).markdown, "### Header Title") 21 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h4).markdown, "#### Header Title") 22 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h5).markdown, "##### Header Title") 23 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h6).markdown, "###### Header Title") 24 | } 25 | 26 | func testHeaderLevelsSetex() { 27 | let h1 = """ 28 | Header Title 29 | ============ 30 | """ 31 | 32 | let h2 = """ 33 | Header Title 34 | ------------ 35 | """ 36 | 37 | let h3 = "### Header Title" 38 | let h4 = "#### Header Title" 39 | let h5 = "##### Header Title" 40 | let h6 = "###### Header Title" 41 | 42 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h1, style: .setex).markdown, h1) 43 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h2, style: .setex).markdown, h2) 44 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h3, style: .setex).markdown, h3) 45 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h4, style: .setex).markdown, h4) 46 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h5, style: .setex).markdown, h5) 47 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h6, style: .setex).markdown, h6) 48 | } 49 | 50 | func testHeaderLevelsAtxCosing() { 51 | let h1 = "# Header Title #" 52 | let h2 = "## Header Title ##" 53 | let h3 = "### Header Title ###" 54 | let h4 = "#### Header Title ####" 55 | let h5 = "##### Header Title #####" 56 | let h6 = "###### Header Title ######" 57 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h1, close: true).markdown, h1) 58 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h2, close: true).markdown, h2) 59 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h3, close: true).markdown, h3) 60 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h4, close: true).markdown, h4) 61 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h5, close: true).markdown, h5) 62 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h6, close: true).markdown, h6) 63 | } 64 | 65 | func testHeaderLevelsSetexClosing() { 66 | let h1 = """ 67 | Header Title 68 | ============ 69 | """ 70 | 71 | let h2 = """ 72 | Header Title 73 | ------------ 74 | """ 75 | 76 | let h3 = "### Header Title ###" 77 | let h4 = "#### Header Title ####" 78 | let h5 = "##### Header Title #####" 79 | let h6 = "###### Header Title ######" 80 | 81 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h1, style: .setex, close: true).markdown, h1) 82 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h2, style: .setex, close: true).markdown, h2) 83 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h3, style: .setex, close: true).markdown, h3) 84 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h4, style: .setex, close: true).markdown, h4) 85 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h5, style: .setex, close: true).markdown, h5) 86 | XCTAssertEqual(MarkdownHeader(title: "Header Title", level: .h6, style: .setex, close: true).markdown, h6) 87 | } 88 | 89 | func testCodeHeader() { 90 | XCTAssertEqual(MarkdownHeader(title: "`Header Title`").markdown, "# `Header Title`") 91 | } 92 | 93 | static var allTests = [ 94 | ("testDefaultHeader", testDefaultHeader), 95 | ("testHeaderLevelsAtx", testHeaderLevelsAtx), 96 | ("testHeaderLevelsSetex", testHeaderLevelsSetex), 97 | ("testHeaderLevelsAtxCosing", testHeaderLevelsAtxCosing), 98 | ("testHeaderLevelsSetexClosing", testHeaderLevelsSetexClosing), 99 | ("testCodeHeader", testCodeHeader) 100 | ] 101 | 102 | } 103 | -------------------------------------------------------------------------------- /Tests/MarkdownGeneratorTests/PublicInterface/MarkdownImageTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownImageTests.swift 3 | // MarkdownGeneratorTests 4 | // 5 | // Created by Eneko Alonso on 10/9/17. 6 | // 7 | 8 | import XCTest 9 | import MarkdownGenerator 10 | 11 | class MarkdownImageTests: XCTestCase { 12 | 13 | func testImage() { 14 | XCTAssertEqual(MarkdownImage(url: "http://example.com/image.png").markdown, "![](http://example.com/image.png)") 15 | } 16 | 17 | func testImageAltText() { 18 | let image = MarkdownImage(url: "http://example.com/image.png", altText: "Alternate Text") 19 | XCTAssertEqual(image.markdown, "![Alternate Text](http://example.com/image.png)") 20 | } 21 | 22 | static var allTests = [ 23 | ("testImage", testImage), 24 | ("testImageAltText", testImageAltText) 25 | ] 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Tests/MarkdownGeneratorTests/PublicInterface/MarkdownLinkTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownLinkTests.swift 3 | // MarkdownGeneratorTests 4 | // 5 | // Created by Eneko Alonso on 10/9/17. 6 | // 7 | 8 | import XCTest 9 | import MarkdownGenerator 10 | 11 | class MarkdownLinkTests: XCTestCase { 12 | 13 | func testLink() { 14 | let link = MarkdownLink(text: "example.com", url: "http://example.com") 15 | XCTAssertEqual(link.markdown, "[example.com](http://example.com)") 16 | } 17 | 18 | static var allTests = [ 19 | ("testLink", testLink) 20 | ] 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Tests/MarkdownGeneratorTests/PublicInterface/MarkdownListTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownListTests.swift 3 | // MarkdownGeneratorTests 4 | // 5 | // Created by Eneko Alonso on 10/9/17. 6 | // 7 | 8 | import XCTest 9 | import MarkdownGenerator 10 | 11 | class MarkdownListTests: XCTestCase { 12 | 13 | func testUnorderedSimpleList() { 14 | let input = ["🍏", "🍌", "🍊", "🍇"] 15 | 16 | let output = """ 17 | - 🍏 18 | - 🍌 19 | - 🍊 20 | - 🍇 21 | """ 22 | 23 | XCTAssertEqual(MarkdownList(items: input).markdown, output) 24 | } 25 | 26 | func testOrderedSimpleList() { 27 | let input = ["🍏", "🍌", "🍊", "🍇"] 28 | 29 | let output = """ 30 | 1. 🍏 31 | 1. 🍌 32 | 1. 🍊 33 | 1. 🍇 34 | """ 35 | 36 | XCTAssertEqual(MarkdownList(items: input, style: .ordered).markdown, output) 37 | } 38 | 39 | func testUnorderedNestedList() { 40 | let input: [MarkdownConvertible] = [ 41 | "Fruits", 42 | MarkdownList(items: ["🍏", "🍌", "🍊", "🍇"]), 43 | "Bakery", 44 | MarkdownList(items: ["🥖", "🍞", "🍰", "🎂"]) 45 | ] 46 | 47 | let output = """ 48 | - Fruits 49 | - 🍏 50 | - 🍌 51 | - 🍊 52 | - 🍇 53 | - Bakery 54 | - 🥖 55 | - 🍞 56 | - 🍰 57 | - 🎂 58 | """ 59 | 60 | XCTAssertEqual(MarkdownList(items: input).markdown, output) 61 | } 62 | 63 | func testOrderedNestedList() { 64 | let input: [MarkdownConvertible] = [ 65 | "Fruits", 66 | MarkdownList(items: ["🍏", "🍌", "🍊", "🍇"], style: .ordered), 67 | "Bakery", 68 | MarkdownList(items: ["🥖", "🍞", "🍰", "🎂"], style: .ordered) 69 | ] 70 | 71 | let output = """ 72 | 1. Fruits 73 | 1. 🍏 74 | 1. 🍌 75 | 1. 🍊 76 | 1. 🍇 77 | 1. Bakery 78 | 1. 🥖 79 | 1. 🍞 80 | 1. 🍰 81 | 1. 🎂 82 | """ 83 | 84 | XCTAssertEqual(MarkdownList(items: input, style: .ordered).markdown, output) 85 | } 86 | 87 | func testMixedNestedList() { 88 | let input: [MarkdownConvertible] = [ 89 | "Fruits", 90 | MarkdownList(items: ["🍏", "🍌", "🍊", "🍇"]), 91 | "Bakery", 92 | MarkdownList(items: ["🥖", "🍞", "🍰", "🎂"]) 93 | ] 94 | 95 | let output = """ 96 | 1. Fruits 97 | - 🍏 98 | - 🍌 99 | - 🍊 100 | - 🍇 101 | 1. Bakery 102 | - 🥖 103 | - 🍞 104 | - 🍰 105 | - 🎂 106 | """ 107 | 108 | XCTAssertEqual(MarkdownList(items: input, style: .ordered).markdown, output) 109 | } 110 | 111 | func testUnorderedThreeLevelList() { 112 | let citrics = MarkdownList(items: ["🍋", "🍊"]) 113 | let list = MarkdownList(items: ["Fruits", MarkdownList(items: ["Citrics", citrics])]) 114 | 115 | let output = """ 116 | - Fruits 117 | - Citrics 118 | - 🍋 119 | - 🍊 120 | """ 121 | 122 | XCTAssertEqual(list.markdown, output) 123 | } 124 | 125 | func testMultipleParagraphLists() { 126 | XCTAssertEqual(MarkdownList(items: multilineInput).markdown, multilineOutput) 127 | } 128 | 129 | static var allTests = [ 130 | ("testUnorderedSimpleList", testUnorderedSimpleList), 131 | ("testOrderedSimpleList", testOrderedSimpleList), 132 | ("testUnorderedNestedList", testUnorderedNestedList), 133 | ("testOrderedNestedList", testOrderedNestedList), 134 | ("testMixedNestedList", testMixedNestedList), 135 | ("testUnorderedThreeLevelList", testUnorderedThreeLevelList), 136 | ("testMultipleParagraphLists", testMultipleParagraphLists) 137 | ] 138 | 139 | } 140 | 141 | let multilineInput = [ 142 | """ 143 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. 144 | Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. 145 | Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede. 146 | 147 | Indented code block 148 | 149 | Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris 150 | sit amet orci. Aenean dignissim pellentesque felis. 151 | 152 | Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, 153 | pharetra a, ultricies in, diam. Sed arcu. Cras consequat. 154 | """, 155 | 156 | """ 157 | Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices 158 | ut, elementum vulputate, nunc. 159 | 160 | > Blockquote paragraph that expands to 161 | > multiple lines 162 | 163 | Sed adipiscing ornare risus. Morbi est est, blandit sit amet, sagittis vel, 164 | euismod vel, velit. Pellentesque egestas sem. Suspendisse commodo 165 | ullamcorper magna. 166 | """ 167 | ] 168 | 169 | let multilineOutput = """ 170 | - Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. 171 | Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. 172 | Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede. 173 | 174 | Indented code block 175 | 176 | Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris 177 | sit amet orci. Aenean dignissim pellentesque felis. 178 | 179 | Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, 180 | pharetra a, ultricies in, diam. Sed arcu. Cras consequat. 181 | 182 | - Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices 183 | ut, elementum vulputate, nunc. 184 | 185 | > Blockquote paragraph that expands to 186 | > multiple lines 187 | 188 | Sed adipiscing ornare risus. Morbi est est, blandit sit amet, sagittis vel, 189 | euismod vel, velit. Pellentesque egestas sem. Suspendisse commodo 190 | ullamcorper magna. 191 | 192 | """ 193 | -------------------------------------------------------------------------------- /Tests/MarkdownGeneratorTests/PublicInterface/MarkdownTableTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MarkdownTableTests.swift 3 | // MarkdownGeneratorTests 4 | // 5 | // Created by Eneko Alonso on 10/9/17. 6 | // 7 | 8 | import XCTest 9 | import MarkdownGenerator 10 | 11 | class MarkdownTableTests: XCTestCase { 12 | 13 | func testEmptyTable() { 14 | let table = MarkdownTable(headers: [], data: []) 15 | XCTAssertEqual(table.markdown, "\n") 16 | } 17 | 18 | func test1x1Table() { 19 | let data: [[String]] = [[]] 20 | let table = MarkdownTable(headers: ["Header"], data: data) 21 | 22 | let output = """ 23 | | Header | 24 | | ------ | 25 | | | 26 | """ 27 | 28 | XCTAssertEqual(table.markdown, output) 29 | } 30 | 31 | func test3x3Table() { 32 | let data: [[String]] = [ 33 | ["🍏", "Apple", "Fruits"], 34 | ["🍊", "Orange", "Fruits"], 35 | ["🥖", "Bread", "Bakery"] 36 | ] 37 | let table = MarkdownTable(headers: ["", "Name", "Department"], data: data) 38 | 39 | let output = """ 40 | | | Name | Department | 41 | | -- | ------ | ---------- | 42 | | 🍏 | Apple | Fruits | 43 | | 🍊 | Orange | Fruits | 44 | | 🥖 | Bread | Bakery | 45 | """ 46 | 47 | XCTAssertEqual(table.markdown, output) 48 | } 49 | 50 | func testMultilineValues() { 51 | let data: [[String]] = [ 52 | ["Single-line value", "Multi-line\n\nvalue"], 53 | ["Single-line value", "Multi-line\n\nvalue"], 54 | ["Single-line value", "Multi-line\n\nvalue"] 55 | ] 56 | let table = MarkdownTable(headers: ["Single-line", "Multi-line"], data: data) 57 | 58 | let output = """ 59 | | Single-line | Multi-line | 60 | | ----------------- | ----------------- | 61 | | Single-line value | Multi-line value | 62 | | Single-line value | Multi-line value | 63 | | Single-line value | Multi-line value | 64 | """ 65 | 66 | XCTAssertEqual(table.markdown, output) 67 | } 68 | 69 | func testMixedTable() { 70 | let table = MarkdownTable(headers: ["Foo"], data: [["Bar"], [], ["Baz", "Bax"]]) 71 | 72 | let output = """ 73 | | Foo | | 74 | | --- | --- | 75 | | Bar | | 76 | | | | 77 | | Baz | Bax | 78 | """ 79 | 80 | XCTAssertEqual(table.markdown, output) 81 | } 82 | 83 | func testPipeEscaping() { 84 | let table = MarkdownTable(headers: ["Foo"], data: [["Foo|Bar|Baz"]]) 85 | 86 | let output = """ 87 | | Foo | 88 | | ----------- | 89 | | Foo\\|Bar\\|Baz | 90 | """ 91 | 92 | XCTAssertEqual(table.markdown, output) 93 | } 94 | 95 | static var allTests = [ 96 | ("test1x1Table", test1x1Table), 97 | ("test3x3Table", test3x3Table), 98 | ("testMultilineValues", testMultilineValues), 99 | ("testMixedTable", testMixedTable), 100 | ("testPipeEscaping", testPipeEscaping) 101 | ] 102 | 103 | } 104 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: 2 | layout: "reach, diff, flags, files" 3 | behavior: default 4 | require_changes: false # if true: only post the comment if coverage changes 5 | require_base: no # [yes :: must have a base report to post] 6 | require_head: yes # [yes :: must have a head report to post] 7 | branches: null 8 | 9 | -------------------------------------------------------------------------------- /docs/Package.md: -------------------------------------------------------------------------------- 1 | # Package: **MarkdownGenerator** 2 | 3 | ## Products 4 | 5 | List of products in this package: 6 | 7 | | Product | Type | Targets | 8 | | ------- | ---- | ------- | 9 | | MarkdownGenerator | Library (automatic) | MarkdownGenerator | 10 | 11 | _Libraries denoted 'automatic' can be both static or dynamic._ 12 | 13 | ## Modules 14 | 15 | ### Program Modules 16 | 17 | | Module | Type | Dependencies | 18 | | ------ | ---- | ------------ | 19 | | MarkdownGenerator | Regular | | 20 | 21 | ### Test Modules 22 | 23 | | Module | Type | Dependencies | 24 | | ------ | ---- | ------------ | 25 | | MarkdownGeneratorTests | Test | MarkdownGenerator | 26 | 27 | ### Module Dependency Graph 28 | 29 | [![Module Dependency Graph](PackageModules.png)](PackageModules.png) 30 | 31 | ## External Dependencies 32 | 33 | This package has zero dependencies 🎉 34 | 35 | ## Requirements 36 | 37 | This file was generated by [SourceDocs](https://github.com/eneko/SourceDocs) on 2020-05-13 20:32:11 +0000 -------------------------------------------------------------------------------- /docs/PackageModules.dot: -------------------------------------------------------------------------------- 1 | digraph ModuleDependencyGraph { 2 | rankdir = LR 3 | graph [fontname="Helvetica-light", style = filled, color = "#eaeaea"] 4 | node [shape=box, fontname="Helvetica", style=filled] 5 | edge [color="#545454"] 6 | 7 | subgraph clusterRegular { 8 | label = "Program Modules" 9 | node [color="#caecec"] 10 | "MarkdownGenerator" 11 | } 12 | subgraph clusterTest { 13 | label = "Test Modules" 14 | node [color="#aaccee"] 15 | "MarkdownGeneratorTests" 16 | } 17 | 18 | 19 | "MarkdownGeneratorTests" -> "MarkdownGenerator" 20 | } -------------------------------------------------------------------------------- /docs/PackageModules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eneko/MarkdownGenerator/5575590ed9ea5cb02cd54a890cb43174efde7911/docs/PackageModules.png -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Reference Documentation 2 | 3 | ## Protocols 4 | 5 | - [MarkdownConvertible](protocols/MarkdownConvertible.md) 6 | 7 | ## Structs 8 | 9 | - [MarkdownBlockquotes](structs/MarkdownBlockquotes.md) 10 | - [MarkdownCodeBlock](structs/MarkdownCodeBlock.md) 11 | - [MarkdownCollapsibleSection](structs/MarkdownCollapsibleSection.md) 12 | - [MarkdownFile](structs/MarkdownFile.md) 13 | - [MarkdownHeader](structs/MarkdownHeader.md) 14 | - [MarkdownImage](structs/MarkdownImage.md) 15 | - [MarkdownLink](structs/MarkdownLink.md) 16 | - [MarkdownList](structs/MarkdownList.md) 17 | - [MarkdownTable](structs/MarkdownTable.md) 18 | 19 | ## Enums 20 | 21 | - [CodeBlockStyle](enums/CodeBlockStyle.md) 22 | - [MarkdownHeaderLevel](enums/MarkdownHeaderLevel.md) 23 | - [MarkdownHeaderStyle](enums/MarkdownHeaderStyle.md) 24 | - [MarkdownListStyle](enums/MarkdownListStyle.md) 25 | 26 | ## Extensions 27 | 28 | - [Array](extensions/Array.md) 29 | - [MarkdownConvertible](extensions/MarkdownConvertible.md) 30 | - [String](extensions/String.md) 31 | 32 | This reference documentation was generated with 33 | [SourceDocs](https://github.com/eneko/SourceDocs). 34 | 35 | Generated at 2020-05-13 20:32:10 +0000 -------------------------------------------------------------------------------- /docs/enums/CodeBlockStyle.md: -------------------------------------------------------------------------------- 1 | **ENUM** 2 | 3 | # `CodeBlockStyle` 4 | 5 | > Markdown format for the generated code block 6 | > 7 | > - indented: Code block is indented by 4-spaces 8 | > - backticks: Code block is wrapped with ``` 9 | 10 | ## Cases 11 | ### `indented` 12 | 13 | ### `backticks(language:)` 14 | -------------------------------------------------------------------------------- /docs/enums/MarkdownHeaderLevel.md: -------------------------------------------------------------------------------- 1 | **ENUM** 2 | 3 | # `MarkdownHeaderLevel` 4 | 5 | > Markdown Header level 6 | > 7 | > - h1: first-level headers 8 | > 9 | > # H1 Header 10 | > 11 | > - h2: second-level headers 12 | > 13 | > ## H2 Header 14 | > 15 | > - h3: third-level headers 16 | > 17 | > ### H3 Header 18 | > 19 | > - h4: fourth-level headers 20 | > 21 | > #### H4 Header 22 | > 23 | > - h5: fifth-level headers 24 | > 25 | > ##### H5 Header 26 | > 27 | > - h6: sixth-level headers 28 | > 29 | > ###### H6 Header 30 | 31 | ## Cases 32 | ### `h1` 33 | 34 | ### `h2` 35 | 36 | ### `h3` 37 | 38 | ### `h4` 39 | 40 | ### `h5` 41 | 42 | ### `h6` 43 | -------------------------------------------------------------------------------- /docs/enums/MarkdownHeaderStyle.md: -------------------------------------------------------------------------------- 1 | **ENUM** 2 | 3 | # `MarkdownHeaderStyle` 4 | 5 | > Markdown Header render style 6 | > 7 | > - `setex`: Setext-style headers are “underlined” using equal signs (for first-level headers) 8 | > and dashes (for second-level headers). For example: 9 | > 10 | > This is a Setex H1 Header 11 | > ========================= 12 | > 13 | > This is a Setex H2 Header 14 | > ------------------------- 15 | > 16 | > - `atx`: Atx-style headers use 1-6 hash characters at the start of the line, corresponding 17 | > to header levels 1-6. For example: 18 | > 19 | > # This is an Atx H1 Header 20 | > 21 | > ## This is an Atx H2 Header 22 | > 23 | > ###### This is a closed Atx H6 Header ###### 24 | 25 | ## Cases 26 | ### `setex` 27 | 28 | ### `atx` 29 | -------------------------------------------------------------------------------- /docs/enums/MarkdownListStyle.md: -------------------------------------------------------------------------------- 1 | **ENUM** 2 | 3 | # `MarkdownListStyle` 4 | 5 | > Specifies the type of list to be generated 6 | > 7 | > - ordered: Ordered lists use numbers followed by periods. 8 | > - unordered: Unordered lists use hyphens as list markers. 9 | 10 | ## Cases 11 | ### `ordered` 12 | 13 | ### `unordered` 14 | -------------------------------------------------------------------------------- /docs/extensions/Array.md: -------------------------------------------------------------------------------- 1 | **EXTENSION** 2 | 3 | # `Array` 4 | 5 | ## Properties 6 | ### `markdown` 7 | 8 | > Render a collection of Markdown convertible elements. 9 | > 10 | > Elements are rendered separated by one blank line, to prevent formatting interference. 11 | -------------------------------------------------------------------------------- /docs/extensions/MarkdownConvertible.md: -------------------------------------------------------------------------------- 1 | **EXTENSION** 2 | 3 | # `MarkdownConvertible` 4 | 5 | ## Properties 6 | ### `blockquoted` 7 | 8 | > Quoted version of the generated Markdown output of the current entity. 9 | > 10 | > "## H2 Header".blockquoted // > ## H2 Header 11 | -------------------------------------------------------------------------------- /docs/extensions/String.md: -------------------------------------------------------------------------------- 1 | **EXTENSION** 2 | 3 | # `String` 4 | 5 | ## Properties 6 | ### `markdown` 7 | 8 | > Render a string of text as Markdown. No transformations applied. 9 | 10 | ### `removingConsecutiveBlankLines` 11 | 12 | > Remove consecutive blank lines from a string output 13 | -------------------------------------------------------------------------------- /docs/protocols/MarkdownConvertible.md: -------------------------------------------------------------------------------- 1 | **PROTOCOL** 2 | 3 | # `MarkdownConvertible` 4 | 5 | > Defines an entity that can be represented as Markdown. 6 | 7 | ## Properties 8 | ### `markdown` 9 | 10 | > Generated Markdown output representing the current entity. 11 | -------------------------------------------------------------------------------- /docs/structs/MarkdownBlockquotes.md: -------------------------------------------------------------------------------- 1 | **STRUCT** 2 | 3 | # `MarkdownBlockquotes` 4 | 5 | > Render Markdown Blockquotes 6 | > 7 | > Markdown uses email-style > characters for blockquoting. 8 | > 9 | > > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, 10 | > > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. 11 | > > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. 12 | > > 13 | > > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse 14 | > > id sem consectetuer libero luctus adipiscing. 15 | 16 | ## Properties 17 | ### `markdown` 18 | 19 | > Generated Markdown output 20 | 21 | ## Methods 22 | ### `init(content:)` 23 | 24 | > MarkdownBlockquotes initializer 25 | > 26 | > - Parameter content: Content to be block-quoted with '> ' 27 | -------------------------------------------------------------------------------- /docs/structs/MarkdownCodeBlock.md: -------------------------------------------------------------------------------- 1 | **STRUCT** 2 | 3 | # `MarkdownCodeBlock` 4 | 5 | ## Properties 6 | ### `markdown` 7 | 8 | > Generated Markdown output 9 | 10 | ## Methods 11 | ### `init(code:style:)` 12 | -------------------------------------------------------------------------------- /docs/structs/MarkdownCollapsibleSection.md: -------------------------------------------------------------------------------- 1 | **STRUCT** 2 | 3 | # `MarkdownCollapsibleSection` 4 | 5 | > Collapsible blocks are a great way to hide large portions of content 6 | > that, while valuable to the reader, would result on a lot of noise. 7 | > 8 | > Collapsible blocks work well in most Markdown readers, including 9 | > GitHub.com and rendered GitHub Pages. However, because they rely on 10 | > HTML tags, they will make the _raw_ markdown output harder to read. 11 | > 12 | > ```html 13 | >
Block Title 14 | > 15 | > Block details. 16 | > 17 | >
18 | > ``` 19 | 20 | ## Properties 21 | ### `markdown` 22 | 23 | > Generated Markdown output 24 | 25 | ## Methods 26 | ### `init(summary:details:)` 27 | 28 | > MarkdownCollapsibleSection initializer 29 | > 30 | > - Parameters: 31 | > - summary: Plain text or HTML string containing the block title. 32 | > - details: Markdown convertible elements to include in the collapsible block. 33 | -------------------------------------------------------------------------------- /docs/structs/MarkdownFile.md: -------------------------------------------------------------------------------- 1 | **STRUCT** 2 | 3 | # `MarkdownFile` 4 | 5 | > Helper structure to write Markdown files to disk. 6 | 7 | ## Properties 8 | ### `filename` 9 | 10 | > Name of the Markdown file, without extension. 11 | 12 | ### `basePath` 13 | 14 | > Path where the Markdown file will be written to. 15 | > 16 | > Path can be absolute or relative to the working directory. It should 17 | > not contain a trailing slash, nor the name of the file to write. 18 | > 19 | > Path will be created if it doesn't already exist in the system. 20 | 21 | ### `content` 22 | 23 | > MarkdownConvertible entity that will be rendered 24 | > as the Markdown content of the file. Can be an `Array`. 25 | 26 | ### `filePath` 27 | 28 | > Computed property containing the file path (`/.md`) 29 | 30 | ## Methods 31 | ### `init(filename:basePath:content:)` 32 | 33 | > MarkdownFile initializer 34 | > 35 | > - Parameters: 36 | > - filename: Name of the Markdown file, without extension. 37 | > - basePath: Path where the Markdown file will be written to. 38 | > 39 | > Path can be absolute or relative to the working directory. It should 40 | > not contain a trailing slash, nor the name of the file to write. 41 | > 42 | > Path will be created if it doesn't already exist in the system. 43 | > 44 | > - content: MarkdownConvertible entity that will be rendered 45 | > as the Markdown content of the file. Can be an `Array`. 46 | 47 | ### `write()` 48 | 49 | > Generate and write the Markdown file to disk. 50 | > 51 | > - Will override the file if already existing, or create a new one. 52 | > - Will create the path directory structure if it does not exists. 53 | > 54 | > - Throws: Throws an exception if the file could not be written to disk, or 55 | > if the path could not be created. 56 | -------------------------------------------------------------------------------- /docs/structs/MarkdownHeader.md: -------------------------------------------------------------------------------- 1 | **STRUCT** 2 | 3 | # `MarkdownHeader` 4 | 5 | > Renders a Markdown Header 6 | > 7 | > Markdown supports two styles of headers, Setext and atx. 8 | > 9 | > Setext-style headers are “underlined” using equal signs (for first-level headers) 10 | > and dashes (for second-level headers). For example: 11 | > 12 | > This is an H1 13 | > ============= 14 | > 15 | > This is an H2 16 | > ------------- 17 | > 18 | > Atx-style headers use 1-6 hash characters at the start of the line, corresponding 19 | > to HTML header levels 1-6. For example: 20 | > 21 | > # This is an H1 22 | > 23 | > ## This is an H2 24 | > 25 | > ###### This is an H6 26 | > 27 | > Atx-style headers can be closed (this is purely cosmetic): 28 | > 29 | > # This is an H1 # 30 | > 31 | > ## This is an H2 ## 32 | > 33 | > ### This is an H3 ### 34 | 35 | ## Properties 36 | ### `markdown` 37 | 38 | > Generated Markdown output 39 | 40 | ## Methods 41 | ### `init(title:level:style:close:)` 42 | 43 | > MarkdownHeader initializer. 44 | > 45 | > - Parameters: 46 | > - title: Title of the header element 47 | > - level: Header level (`h1`, `h2`... `h6`) 48 | > - style: Header style: `setex` (underlined) or `atx` ('#') (defaults to `atx`). 49 | > Setex format is only available for first-level (using equal signs) and 50 | > second-level headers (using dashes). 51 | > - close: Close `atx` style headers (defaults to `false`). When false, headers 52 | > only include the '#' prefix. When `true`, headers also include the 53 | > trailing '#' suffix: 54 | > 55 | > ### Third-level Header ### 56 | > 57 | > - SeeAlso: MarkdownHeaderLevel, MarkdownHeaderStyle 58 | -------------------------------------------------------------------------------- /docs/structs/MarkdownImage.md: -------------------------------------------------------------------------------- 1 | **STRUCT** 2 | 3 | # `MarkdownImage` 4 | 5 | > Render an HTML image in Markdown format 6 | > 7 | > MarkdownImage(url: "http://example.com/image.jpg", altText: "SourceDocs Header").markdown 8 | > 9 | > Would render as: 10 | > 11 | > ![SourceDocs Header](http://example.com/image.jpg) 12 | 13 | ## Properties 14 | ### `url` 15 | 16 | > URL where the image is located. Can be absolute or relative. 17 | 18 | ### `altText` 19 | 20 | > Alternate text to display on non-graphic browsers or to be used by screen readers. 21 | 22 | ### `markdown` 23 | 24 | > Generated Markdown output 25 | 26 | ## Methods 27 | ### `init(url:altText:)` 28 | 29 | > MarkdownImage initializer 30 | > 31 | > - Parameters: 32 | > - url: URL where the image is located. Can be absolute or relative. 33 | > - altText: Alternate text to display on non-graphic browsers or to be used by screen readers. 34 | -------------------------------------------------------------------------------- /docs/structs/MarkdownLink.md: -------------------------------------------------------------------------------- 1 | **STRUCT** 2 | 3 | # `MarkdownLink` 4 | 5 | > Render an HTML link in Markdown format 6 | > 7 | > MarkdownLink(text: "Google", url: "https://example.com").markdown 8 | > 9 | > Would render as: 10 | > 11 | > [Google](https://example.com) 12 | 13 | ## Properties 14 | ### `text` 15 | 16 | > Text to display as hyper-linked. 17 | 18 | ### `url` 19 | 20 | > Link URL, can be absolute, relative, or #local. 21 | 22 | ### `markdown` 23 | 24 | > Generated Markdown output 25 | 26 | ## Methods 27 | ### `init(text:url:)` 28 | 29 | > MarkdownLink initializer 30 | > 31 | > - Parameters: 32 | > - text: Text to display as hyper-linked. 33 | > - url: Link URL, can be absolute, relative, or #local. 34 | -------------------------------------------------------------------------------- /docs/structs/MarkdownList.md: -------------------------------------------------------------------------------- 1 | **STRUCT** 2 | 3 | # `MarkdownList` 4 | 5 | > Render a list of elements in Markdown format 6 | > 7 | > Unordered lists: 8 | > 9 | > - One item 10 | > - Another item that expands to multiple 11 | > lines. 12 | > - A nested item. 13 | > - Third-level. 14 | > - Back to first-level. 15 | > 16 | > Ordered lists: 17 | > 18 | > 1. First item 19 | > 1. Second item 20 | > 1. Nested item (second-level) 21 | > 1. Back to first-level 22 | 23 | ## Properties 24 | ### `items` 25 | 26 | > List of items to be converted to a list. 27 | 28 | ### `markdown` 29 | 30 | > Generated Markdown output 31 | 32 | ## Methods 33 | ### `init(items:style:)` 34 | 35 | > MarkdownList initializer 36 | > 37 | > - Parameter items: List of items to be converted to a list. 38 | -------------------------------------------------------------------------------- /docs/structs/MarkdownTable.md: -------------------------------------------------------------------------------- 1 | **STRUCT** 2 | 3 | # `MarkdownTable` 4 | 5 | > Render a two dimensional Markdown table. 6 | > 7 | > | | Name | Department | 8 | > | -- | ------ | ---------- | 9 | > | 🍏 | Apple | Fruits | 10 | > | 🍊 | Orange | Fruits | 11 | > | 🥖 | Bread | Bakery | 12 | > 13 | > *Notes*: 14 | > - Markdown tables are not supported by all Markdown readers. 15 | > - Table headers are required. 16 | > - Table cells cannot contain multiple lines. New line characters are replaced by a space. 17 | 18 | ## Properties 19 | ### `markdown` 20 | 21 | > Generated Markdown output 22 | 23 | ## Methods 24 | ### `init(headers:data:)` 25 | 26 | > MarkdownTable initializer 27 | > 28 | > - Parameters: 29 | > - headers: List of table header titles. 30 | > - data: Two-dimensional `String` array with the table content. Rows are defined by 31 | > the outer array, columns are defined by the inner arrays. 32 | > 33 | > An array of rows, each row containing an array of columns. All rows should contain the same 34 | > number of columns as the headers array, to avoid formatting issues. 35 | --------------------------------------------------------------------------------