Showing preview only (441K chars total). Download the full file or copy to clipboard to get everything.
Repository: SwiftDocOrg/CommonMark
Branch: main
Commit: 6fc9d04ff536
Files: 79
Total size: 414.3 KB
Directory structure:
gitextract_min7gahu/
├── .github/
│ └── workflows/
│ ├── ci.yml
│ └── documentation.yml
├── .gitignore
├── Changelog.md
├── LICENSE.md
├── Makefile
├── Package.resolved
├── Package.swift
├── README.md
├── Resources/
│ ├── CommonMarkSpecTests.swift.gyb
│ └── camelcase.awk
├── Sources/
│ └── CommonMark/
│ ├── Nodes/
│ │ ├── Block/
│ │ │ ├── BlockQuote.swift
│ │ │ ├── CodeBlock.swift
│ │ │ ├── HTMLBlock.swift
│ │ │ ├── Heading.swift
│ │ │ ├── List.swift
│ │ │ ├── Paragraph.swift
│ │ │ └── ThematicBreak.swift
│ │ ├── Document.swift
│ │ ├── Inline/
│ │ │ ├── Code.swift
│ │ │ ├── Emphasis.swift
│ │ │ ├── HardLineBreak.swift
│ │ │ ├── Image.swift
│ │ │ ├── Link.swift
│ │ │ ├── RawHTML.swift
│ │ │ ├── SoftLineBreak.swift
│ │ │ ├── Strong.swift
│ │ │ └── Text.swift
│ │ └── Node.swift
│ ├── Result Builders/
│ │ ├── ContainerOfBlocksBuilder.swift
│ │ ├── ContainerOfInlineElementsBuilder.swift
│ │ └── ListBuilder.swift
│ ├── Supporting Types/
│ │ ├── Block.swift
│ │ ├── Children.swift
│ │ ├── Fragment.swift
│ │ ├── Inline.swift
│ │ ├── LineBreak.swift
│ │ ├── Linked.swift
│ │ ├── Literal.swift
│ │ ├── Section.swift
│ │ ├── Visitable.swift
│ │ └── Visitor.swift
│ └── Version.swift
└── Tests/
├── CommonMarkSpecTests/
│ ├── AtxHeadingsTests.swift
│ ├── AutolinksTests.swift
│ ├── BackslashEscapesTests.swift
│ ├── BlankLinesTests.swift
│ ├── BlockQuotesTests.swift
│ ├── CodeSpansTests.swift
│ ├── EmphasisAndStrongEmphasisTests.swift
│ ├── EntityAndNumericCharacterReferencesTests.swift
│ ├── FencedCodeBlocksTests.swift
│ ├── HardLineBreaksTests.swift
│ ├── HtmlBlocksTests.swift
│ ├── ImagesTests.swift
│ ├── IndentedCodeBlocksTests.swift
│ ├── InlinesTests.swift
│ ├── LinkReferenceDefinitionsTests.swift
│ ├── LinksTests.swift
│ ├── ListItemsTests.swift
│ ├── ListsTests.swift
│ ├── ParagraphsTests.swift
│ ├── PrecedenceTests.swift
│ ├── RawHtmlTests.swift
│ ├── SetextHeadingsTests.swift
│ ├── SoftLineBreaksTests.swift
│ ├── TabsTests.swift
│ ├── TextualContentTests.swift
│ └── ThematicBreaksTests.swift
├── CommonMarkTests/
│ ├── CommonMarkBuilderTests.swift
│ ├── CommonMarkTests.swift
│ ├── ContainerManipulationTests.swift
│ ├── DocumentTests.swift
│ ├── Fixtures.swift
│ ├── NodeTests.swift
│ ├── ProtocolTests.swift
│ ├── StatisticsVisitor.swift
│ └── VisitorTests.swift
└── LinuxMain.swift
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/workflows/ci.yml
================================================
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
macos:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Build and Test
run: swift test
linux:
runs-on: ubuntu-latest
strategy:
matrix:
swift:
- "5.3"
- "5.4"
container:
image: swift:${{ matrix.swift }}
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Build and Test
run: swift test --enable-test-discovery
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: seanmiddleditch/gha-setup-vsdevenv@master
- name: Install swift-5.4
run: |
Install-Binary -Url "https://swift.org/builds/swift-5.4-release/windows10/swift-5.4-RELEASE/swift-5.4-RELEASE-windows10.exe" -Name "installer.exe" -ArgumentList ("-q")
- name: Set Environment Variables
run: |
echo "SDKROOT=C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "DEVELOPER_DIR=C:\Library\Developer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Adjust Paths
run: |
echo "C:\Library\Swift-development\bin;C:\Library\icu-67\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Install Supporting Files
run: |
Copy-Item "$env:SDKROOT\usr\share\ucrt.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\ucrt\module.modulemap"
Copy-Item "$env:SDKROOT\usr\share\visualc.modulemap" -destination "$env:VCToolsInstallDir\include\module.modulemap"
Copy-Item "$env:SDKROOT\usr\share\visualc.apinotes" -destination "$env:VCToolsInstallDir\include\visualc.apinotes"
Copy-Item "$env:SDKROOT\usr\share\winsdk.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\um\module.modulemap"
- name: Build and Test
run: swift test --enable-test-discovery
================================================
FILE: .github/workflows/documentation.yml
================================================
name: Documentation
on:
push:
branches:
- main
paths:
- .github/workflows/documentation.yml
- Sources/**.swift
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Generate Documentation
uses: SwiftDocOrg/swift-doc@master
with:
inputs: "Sources"
output: "Documentation"
- name: Upload Documentation to Wiki
uses: SwiftDocOrg/github-wiki-publish-action@master
with:
path: "Documentation"
env:
GITHUB_PERSONAL_ACCESS_TOKEN: ${{ secrets.GITHUB_PERSONAL_ACCESS_TOKEN }}
================================================
FILE: .gitignore
================================================
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
.swiftpm
Resources/spec*
================================================
FILE: Changelog.md
================================================
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.5.1] - 2021-05-04
### Added
- Added `replace(child:with:)` methods for container nodes.
#26 by @mattt.
### Fixed
- Fixed documentation for `List`.
#29 by @mattt.
### Changed
- Changed implementation of `Hashable` conformance for `Node`.
Previously the hash value of a node was computed from its content.
Now it's computed from the opaque cmark pointer.
#30 by @Lukas-Stuehrk.
## [0.5.0] - 2021-01-14
### Added
- Added support for the visitor pattern,
by adding `protocol Visitor`/`protocol Visitable` & `enum VisitorContinueKind`.
#13 by @regexident.
### Fixed
- Fixed document parsing options.
#21 by @regexident.
- Fixed memory leaks.
#22 by @regexident.
## [0.4.0] - 2020-05-01
### Added
- Added a changelog.
#17 by @mattt.
### Changed
- Changed `render` method,
as well as nested `RenderingFormat` and `RenderingOptions` types,
from `Document` to `Node`.
#18 by @mattt.
### Fixed
- Fixed abbreviation for "Universal Declaration of Human Rights" (UDHR)
throughout project.
#12 by @regexident.
## [0.3.2] - 2020-04-24
### Fixed
- Fixed implementations of `insert` methods.
#10 by @Lukas-Stuehrk
## [0.3.1] - 2020-04-23
### Fixed
- Fixed error caused by missing a case for `CMARK_NODE_DOCUMENT` in `Node.create`.
#8 by @mattt.
### Removed
- Removed `assertionFailure` in `Node` `cmark_node_type` class property.
1903d99 by @mattt.
## [0.3.0] - 2020-04-10
### Added
- Added implementations of `buildIf` and `buildEither` to `StringBuilder`.
#5 by @mattt.
### Changed
- **Breaking Change**.
Changed `HTML`, renaming it to `RawHTML`.
#4 by @mattt.
- Changed `Node` to conform to `Codable`.
#6 by @mattt.
- Changed access level of `Node` from `open` to `public`.
#6 by @mattt.
- Change access level for APIs referencing `cmark_node` to `internal`
#6 by @mattt.
- Changed swift-cmark dependency to more recent version.
2239c9c by @mattt.
### Fixed
- Fixed error 'Top-level Document encoded as string JSON fragment.'
727e38f by @mattt.
## [0.2.2] - 2020-02-06
### Fixed
- Fixed bug in how closed ranges are constructed from reported source positions.
#2 by @mattt.
## [0.2.1] - 2020-01-25
### Added
- Added `ForEach` type to `CommonMarkBuilder` module.
3cee5da by @mattt.
- Added implementations of `buildIf` and `buildEither` to `CommonMarkBuilder`.
a125d23 by @mattt.
- Added convenience initializers to `List` for mapping sequence of values.
ec61c45 by @mattt.
### Changed
- Changed `List.Item` to allow initialization with `Inline` or `Block` children.
c21468c0 by @mattt.
- Changed inline types conform to `ListItemConvertible`.
ffe900bf by @mattt.
- Changed access of children to `public` and conformed them to `Block & Node`.
5e88c519 by @mattt
### Removed
- Removed conformance of `Document` to `CustomReflectable`.
6b92588e by @mattt.
- Removed `Child` typealias in favor of explicit compound types.
c9a5b199 by @mattt.
## [0.2.0] - 2020-01-24
### Added
- Added CommonMarkBuilder interface.
79a98dd by @mattt.
### Changed
- Changed access level for `Node` to open.
79a98dd by @mattt.
- Changed initialization pattern of `Node`.
79a98dd by @mattt.
- Changed `ListItem`, renaming it to `List.Item`.
79a98dd by @mattt.
- Changed initializers for `Node` subclasses
79a98dd by @mattt.
### Removed
- Removed `BulletList` and `OrderedList`,
consolidating them into into a new `List` type.
79a98dd by @mattt.
## [0.1.2] - 2020-01-22
### Changed
- Changed cmark dependency to pin to a tag in a fork.
2f5a2a4 by @mattt.
## [0.1.1] - 2020-01-22
### Changed
- Changed cmark dependency to pin to a specific revision.
90704ff by @mattt.
## [0.1.0] - 2020-01-22
### Added
- Added node creation and mutation functionality.
a41ba246 by @mattt.
## [0.0.1] - 2020-01-27
Initial release.
[unreleased]: https://github.com/SwiftDocOrg/CommonMark/compare/0.5.1...main
[0.5.1]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.5.1
[0.5.0]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.5.0
[0.4.0]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.4.0
[0.3.2]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.3.2
[0.3.1]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.3.1
[0.3.0]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.3.0
[0.2.2]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.2.2
[0.2.1]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.2.1
[0.2.0]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.2.0
[0.1.2]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.1.2
[0.1.1]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.1.1
[0.1.0]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.1.0
[0.0.1]: https://github.com/SwiftDocOrg/CommonMark/releases/tag/0.0.1
================================================
FILE: LICENSE.md
================================================
Copyright 2019 Read Evaluate Press, LLC
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
================================================
FILE: Makefile
================================================
COMMONMARK_SPEC_VERSION=0.29
Tests/CommonMarkSpecTests: Resources/spec.json | Resources/spec
@mkdir -p $@
@for section in $(shell jq -c '.[].section' $< | uniq); do \
filename=`echo "$${section}" | awk -f Resources/camelcase.awk`; \
jq "map(select(.section == \"$${section}\"))" $< > "$|/$${filename}.json" ; \
gyb --line-directive '' -o $@/$${filename}Tests.swift -D filename="$${filename}" Resources/CommonMarkSpecTests.swift.gyb; \
done
Resources/spec:
@mkdir -p Resources/spec
Resources/spec.json:
@curl "https://spec.commonmark.org/${COMMONMARK_SPEC_VERSION}/spec.json" > $@
%.swift: %.swift.gyb
@gyb --line-directive '' -o $@ $<
.PHONY:
clean:
@rm -f Resources/spec.json
@rm -rf Resources/spec
@rm -rf Tests/CommonMarkSpecTests
================================================
FILE: Package.resolved
================================================
{
"object": {
"pins": [
{
"package": "cmark",
"repositoryURL": "https://github.com/SwiftDocOrg/swift-cmark.git",
"state": {
"branch": null,
"revision": "9c8096a23f44794bde297452d87c455fc4f76d42",
"version": "0.29.0+20210102.9c8096a"
}
}
]
},
"version": 1
}
================================================
FILE: Package.swift
================================================
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "CommonMark",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "CommonMark",
targets: ["CommonMark"]
)
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/SwiftDocOrg/swift-cmark.git",
from: Version(0, 29, 0, buildMetadataIdentifiers: ["20210102", "9c8096a"])),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "CommonMark",
dependencies: ["cmark"]
),
.testTarget(
name: "CommonMarkTests",
dependencies: ["CommonMark"]
),
.testTarget(
name: "CommonMarkSpecTests",
dependencies: ["CommonMark"]
)
]
)
================================================
FILE: README.md
================================================
# CommonMark
![CI][ci badge]
[![Documentation][documentation badge]][documentation]
A Swift package for working with [CommonMark][commonmark] text.
It's built on top of [libcmark][cmark]
and fully compliant with the [CommonMark Spec][commonmark].
## Usage
```swift
import CommonMark
let markdown = #"""
# [Universal Declaration of Human Rights][udhr]
## Article 1.
All human beings are born free and equal in dignity and rights.
They are endowed with reason and conscience
and should act towards one another in a spirit of brotherhood.
[udhr]: https://www.un.org/en/universal-declaration-human-rights/ "View full version"
"""#
let document = try Document(markdown)
```
### Inspecting Document Nodes
```swift
document.children.count // 3
let heading = document.children[0] as! Heading
heading.headerLevel // 1
heading.children.count // 1
let link = heading.children[0] as! Link
link.urlString // "https://www.un.org/en/universal-declaration-human-rights/")
link.title // "View full version"
let subheading = document.children[1] as! Heading
subheading.headerLevel // 2
subheading.children.count // 1
let subheadingText = subheading.children[0] as! Text
subheadingText.literal // "Article 1."
let paragraph = document.children[2] as! Paragraph
paragraph.description // "All human beings [ ... ]"
paragraph.range.lowerBound // (line: 5, column: 1)
paragraph.range.upperBound // (line: 7, column: 62)
```
### Rendering to HTML, XML, LaTeX, and Manpage
```swift
let html = document.render(format: .html) // <h1> [ ... ]
let xml = document.render(format: .xml) // <?xml [ ... ]
let latex = document.render(format: .latex) // \section{ [ ... ]
let manpage = document.render(format: .manpage) // .SH [ ... ]
// To get back CommonMark text,
// you can either render with the `.commonmark` format...
document.render(format: .commonmark) // # [Universal [ ... ]
// ...or call `description`
// (individual nodes also return their CommonMark representation as their description)
document.description // # [Universal [ ... ]
```
### Creating Documents From Scratch
#### Using Result Builders
In Swift 5.4 and later,
you can create CommonMark documents using `@resultBuilder` initializers.
```swift
import CommonMark
let document = Document {
Heading {
Link(urlString: "https://www.un.org/en/universal-declaration-human-rights/",
title: "View full version")
{
"Universal Declaration of Human Rights"
}
}
Section { // sections increase the level of contained headings
Heading { "Article 1." } // this is a second-level heading
}
// block-level strings are parsed as CommonMark literals
"""
**All** human beings are born free and equal in dignity and rights.
They are endowed with reason and conscience
and should act towards one another in a spirit of brotherhood.
"""
}
```
#### Using the Conventional Approach
The following code produces the same result as the preceding example,
using conventional Swift initializers.
```swift
let link = Link(urlString: "https://www.un.org/en/universal-declaration-human-rights/",
title: "View full version",
text: "Universal Declaration of Human Rights")
let heading = Heading(level: 1, children: [link])
let subheading = Heading(level: 2, text: "Article 1.")
let paragraph = Paragraph(children: #"""
All human beings are born free and equal in dignity and rights.
They are endowed with reason and conscience
and should act towards one another in a spirit of brotherhood.
"""#.split(separator: "\n")
.flatMap { [Text(String($0)), SoftLineBreak()] })
Document(children: [heading, subheading, paragraph]).description == document.description // true
```
## CommonMark Spec Compliance
This package passes all of the 649 test cases
in the latest version (0.29) of the [CommonMark Spec][commonmark spec]:
```console
$ swift test
Executed 649 tests, with 0 failures (0 unexpected) in 0.178 (0.201) seconds
```
## Requirements
- Swift 5.1+
## Installation
### Swift Package Manager
Add the CommonMark package to your target dependencies in `Package.swift`:
```swift
import PackageDescription
let package = Package(
name: "YourProject",
dependencies: [
.package(
url: "https://github.com/SwiftDocOrg/CommonMark",
from: "0.5.1"
),
]
)
```
Then run the `swift build` command to build your project.
## License
MIT
## Contact
Mattt ([@mattt](https://twitter.com/mattt))
[cmark]: https://github.com/commonmark/cmark
[commonmark]: https://commonmark.org
[commonmark spec]: https://spec.commonmark.org
[ci badge]: https://github.com/SwiftDocOrg/CommonMark/workflows/CI/badge.svg
[documentation badge]: https://github.com/SwiftDocOrg/CommonMark/workflows/Documentation/badge.svg
[documentation]: https://github.com/SwiftDocOrg/CommonMark/wiki
================================================
FILE: Resources/CommonMarkSpecTests.swift.gyb
================================================
% warning = "This file was automatically generated and should not be edited."
// ${warning}
%{
# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import json
def indent(text, amount, ch=' '):
padding = amount * ch
return ''.join(padding+line for line in text.splitlines(True))
}%
import XCTest
import CommonMark
final class CommonMarkSpec${filename}Tests: XCTestCase {
% with open('../Resources/spec/%s.json' % filename) as file:
%{ spec = json.load(file) }%
% for example in spec:
%{
number = example['example']
markdown = example['markdown']
html = example['html'] }%
func testExample${number}() throws {
let markdown = #######"""
${indent(markdown, 8)}
"""#######
let html = #######"""
${indent(html, 8)}
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
% end
% end
}
================================================
FILE: Resources/camelcase.awk
================================================
#!/usr/bin/awk -f
{
text = $0;
split(text, words, /[^a-zA-Z]+/);
for (i=1; i<=length(words); i++) {
res = res toupper(substr(words[i],1,1)) tolower(substr(words[i],2));
}
print res
}
================================================
FILE: Sources/CommonMark/Nodes/Block/BlockQuote.swift
================================================
import cmark
/**
A block quote.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [5.1 Block quotes](https://spec.commonmark.org/0.29/#block-quotes)
>
> A block quote marker consists of 0-3 spaces of initial indent,
> plus (a) the character > together with a following space,
> or (b) a single character > not followed by a space.
*/
public final class BlockQuote: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_BLOCK_QUOTE }
public convenience init(children: [Block & Node] = []) {
self.init()
guard !children.isEmpty else { return }
for child in children {
append(child: child)
}
}
#if swift(>=5.4)
public convenience init(@ContainerOfBlocksBuilder _ builder: () -> [Block & Node]) {
self.init(children: builder())
}
#endif
}
================================================
FILE: Sources/CommonMark/Nodes/Block/CodeBlock.swift
================================================
import cmark
/**
A code block.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [4.4 Indented code blocks](https://spec.commonmark.org/0.29/#indented-code-blocks)
>
> An indented code block is composed of
> one or more indented chunks separated by blank lines.
> An indented chunk is a sequence of non-blank lines,
> each indented four or more spaces.
> The contents of the code block are the literal contents of the lines,
> including trailing line endings,
> minus four spaces of indentation.
> An indented code block has no info string.
> ## [4.5 Fenced code blocks](https://spec.commonmark.org/0.29/#fenced-code-blocks)
>
> A code fence is a sequence of
> at least three consecutive backtick characters (`) or tildes (~).
> (Tildes and backticks cannot be mixed.)
> A fenced code block begins with a code fence,
> indented no more than three spaces.
*/
public final class CodeBlock: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_CODE_BLOCK }
public var fenceInfo: String? {
get {
return String(cString: cmark_node_get_fence_info(cmark_node))
}
set {
cmark_node_set_fence_info(cmark_node, newValue)
}
}
public convenience init(literal: String? = nil) {
self.init()
self.literal = literal
}
public convenience init(literal: String, fenceInfo: String? = nil) {
self.init()
self.literal = literal
if let fenceInfo = fenceInfo {
self.fenceInfo = fenceInfo
}
}
public convenience init(fenceInfo: String? = nil, _ block: () -> String?) {
self.init(literal: block())
if let fenceInfo = fenceInfo {
self.fenceInfo = fenceInfo
}
}
}
================================================
FILE: Sources/CommonMark/Nodes/Block/HTMLBlock.swift
================================================
import cmark
/**
An HTML block.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [4.6 HTML blocks](https://spec.commonmark.org/0.29/#html-blocks)
>
> An HTML block is a group of lines that is treated as raw HTML
> (and will not be escaped in HTML output).
*/
public final class HTMLBlock: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_HTML_BLOCK }
public convenience init(literal: String? = nil) {
self.init()
self.literal = literal
}
#if swift(>=5.4)
public static func wrap(
@ContainerOfBlocksBuilder _ body: () -> [Block & Node],
before: () -> String?,
after: () -> String?
) -> [Block & Node] {
var blocks: [Block & Node] = []
blocks.append(HTMLBlock(literal: before()))
blocks.append(contentsOf: body())
blocks.append(HTMLBlock(literal: after()))
return blocks
}
#endif
}
================================================
FILE: Sources/CommonMark/Nodes/Block/Heading.swift
================================================
import cmark
/**
A heading.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [4.2 ATX headings](https://spec.commonmark.org/0.29/#atx-headings)
>
> An ATX heading consists of a string of characters,
> parsed as inline content,
> between an opening sequence of 1–6 unescaped # characters
> and an optional closing sequence of any number of unescaped # characters.
> The opening sequence of # characters must be followed by a space
> or by the end of line.
> The optional closing sequence of #s must be preceded by a space
> and may be followed by spaces only.
> The opening # character may be indented 0-3 spaces.
> The raw contents of the heading are stripped of leading and trailing spaces
> before being parsed as inline content.
> The heading level is equal to the number of # characters
> in the opening sequence.
> ## [4.3 Setext headings](https://spec.commonmark.org/0.29/#setext-headings)
> A setext heading consists of one or more lines of text,
> each containing at least one non-whitespace character,
> with no more than 3 spaces indentation,
> followed by a setext heading underline.
> The lines of text must be such that,
> were they not followed by the setext heading underline,
> they would be interpreted as a paragraph:
> they cannot be interpretable as a
> code fence, ATX heading, block quote,
> thematic break, list item, or HTML block.
*/
public final class Heading: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_HEADING }
static let levelRange: ClosedRange<Int> = 1...6
public var level: Int {
get {
return numericCast(cmark_node_get_heading_level(cmark_node))
}
set {
precondition(Heading.levelRange.contains(newValue))
cmark_node_set_heading_level(cmark_node, numericCast(newValue))
}
}
public convenience init(level: Int, text string: String) {
self.init(level: level, children: [Text(literal: string)])
}
public convenience init(level: Int, children: [Inline & Node] = []) {
self.init()
self.level = level
guard !children.isEmpty else { return }
for child in children {
append(child: child)
}
}
#if swift(>=5.4)
public convenience init(level: Int = 1, @ContainerOfInlineElementsBuilder _ builder: () -> [Inline & Node]) {
self.init(level: level, children: builder())
}
#endif
}
================================================
FILE: Sources/CommonMark/Nodes/Block/List.swift
================================================
import cmark
/**
A list.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [5.3 Lists](https://spec.commonmark.org/0.29/#lists)
>
> A list is a sequence of one or more list items of the same type.
> The list items may be separated by any number of blank lines.
> ## [5.2 List items](https://spec.commonmark.org/0.29/#list-items)
>
> A list marker is a bullet list marker or an ordered list marker.
>
> An ordered list marker is a sequence of 1–9 arabic digits (0-9),
> followed by either a . character or a ) character.
> (The reason for the length limit is that
> with 10 digits we start seeing integer overflows in some browsers.)
*/
public final class List: Node {
public enum Kind: Hashable {
case bullet
case ordered
}
public enum Delimiter: Hashable {
case none
case period(Int = 1)
case parenthesis(Int = 1)
init(_ cmark_node: OpaquePointer) {
switch cmark_node_get_list_delim(cmark_node) {
case CMARK_PERIOD_DELIM:
self = .period(numericCast(cmark_node_get_list_start(cmark_node)))
case CMARK_PAREN_DELIM:
self = .parenthesis(numericCast(cmark_node_get_list_start(cmark_node)))
default:
self = .none
}
}
}
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_LIST }
public var kind: Kind {
return delimiter == .none ? .bullet : .ordered
}
public var delimiter: Delimiter {
get {
return Delimiter(cmark_node)
}
set {
switch newValue {
case .period(let listStart):
cmark_node_set_list_type(cmark_node, CMARK_ORDERED_LIST)
cmark_node_set_list_delim(cmark_node, CMARK_PERIOD_DELIM)
cmark_node_set_list_start(cmark_node, numericCast(listStart))
case .parenthesis(let listStart):
cmark_node_set_list_type(cmark_node, CMARK_ORDERED_LIST)
cmark_node_set_list_delim(cmark_node, CMARK_PAREN_DELIM)
cmark_node_set_list_start(cmark_node, numericCast(listStart))
default:
cmark_node_set_list_type(cmark_node, CMARK_BULLET_LIST)
}
}
}
/**
Whether the list is loose.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> A list is loose if any of its constituent list items
> are separated by blank lines,
> or if any of its constituent list items
> directly contain two block-level elements with a blank line between them.
> Otherwise a list is tight.
*/
public var loose: Bool {
get {
return !tight
}
set {
tight = !newValue
}
}
/**
Whether the list is tight.
- SeeAlso: `loose`
*/
public var tight: Bool {
get {
return cmark_node_get_list_tight(cmark_node) == 1 ? true : false
}
set {
cmark_node_set_list_tight(cmark_node, newValue ? 1 : 0)
}
}
public convenience init(delimiter: Delimiter = .none, children: [List.Item] = []) {
self.init()
self.delimiter = delimiter
guard !children.isEmpty else { return }
for child in children {
append(child: child)
}
}
#if swift(>=5.4)
public convenience init(delimiter: Delimiter = .none, tight: Bool = true, @ListBuilder _ builder: () -> [List.Item]) {
self.init(delimiter: delimiter, children: builder())
self.tight = tight
}
public convenience init<Values>(of values: Values, delimiter: Delimiter = .none, tight: Bool = true, @ListBuilder _ builder: (Values.Element) -> [List.Item]) where Values: Sequence {
self.init(delimiter: delimiter, children: values.flatMap { builder($0) })
self.tight = tight
}
#endif
}
extension List {
public final class Item: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_ITEM }
public convenience init(children: [Inline & Node] = []) {
self.init(children: [Paragraph(children: children)])
}
public convenience init(children: [Block & Node] = []) {
self.init()
guard !children.isEmpty else { return }
for child in children {
append(child: child)
}
}
#if swift(>=5.4)
public convenience init(@ContainerOfInlineElementsBuilder _ builder: () -> [Inline & Node]) {
self.init(children: builder())
}
public convenience init(@ContainerOfBlocksBuilder _ builder: () -> [Block & Node]) {
self.init(children: builder())
}
#endif
}
}
================================================
FILE: Sources/CommonMark/Nodes/Block/Paragraph.swift
================================================
import cmark
/**
A paragraph.
From the [CommonMark Spec](https://spec.commonmark.org/0.29/#thematic-breaks):
> ## [4.8 Paragraphs](https://spec.commonmark.org/0.29/#paragraphs)
>
> A sequence of non-blank lines
> that cannot be interpreted as other kinds of blocks
> forms a paragraph.
> The contents of the paragraph are the result of
> parsing the paragraph’s raw content as inlines.
> The paragraph’s raw content is formed by
> concatenating the lines and removing initial and final whitespace.
*/
public final class Paragraph: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_PARAGRAPH }
public convenience init(text string: String, replacingNewLinesWithBreaks: Bool = true) {
let children: [Inline & Node]
if replacingNewLinesWithBreaks {
children = string.split(separator: "\n", omittingEmptySubsequences: false)
.flatMap { ($0.isEmpty ? [HardLineBreak()] : [Text(literal: "\($0)"), SoftLineBreak()]) }
} else {
children = [Text(literal: string)]
}
self.init(children: children)
}
public convenience init(children: [Inline & Node] = []) {
self.init()
guard !children.isEmpty else { return }
for child in children {
append(child: child)
}
}
#if swift(>=5.4)
public convenience init(@ContainerOfInlineElementsBuilder _ builder: () -> [Inline & Node]) {
self.init(children: builder())
}
#endif
}
================================================
FILE: Sources/CommonMark/Nodes/Block/ThematicBreak.swift
================================================
import cmark
/**
A thematic break.
From the [CommonMark Spec](https://spec.commonmark.org/0.29/):
> ## [4.1 Thematic breaks](https://spec.commonmark.org/0.29/#thematic-breaks)
>
> A line consisting of 0-3 spaces of indentation,
> followed by a sequence of three or more matching -, _, or * characters,
> each followed optionally by any number of spaces or tabs,
> forms a thematic break.
*/
public final class ThematicBreak: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_THEMATIC_BREAK }
public convenience init() {
self.init(nonrecursively: ())
}
}
================================================
FILE: Sources/CommonMark/Nodes/Document.swift
================================================
import cmark
/// A CommonMark document.
public final class Document: Node {
/// Options for parsing CommonMark text.
public struct ParsingOptions: OptionSet {
public var rawValue: Int32
public init(rawValue: Int32 = CMARK_OPT_DEFAULT) {
self.rawValue = rawValue
}
/**
Convert ASCII punctuation characters
to "smart" typographic punctuation characters.
- Straight quotes (" and ')
become curly quotes (“ ” and ‘ ’)
- Dashes (-- and ---) become
en-dashes (–) and em-dashes (—)
- Three consecutive full stops (...) become an ellipsis (…)
*/
public static let smart = Self(rawValue: CMARK_OPT_SMART)
}
/// A position within a document.
public struct Position: Hashable {
/**
The line number.
Line numbers start at 1 and increase monotonically.
*/
public var line: Int
/**
The line number.
Column numbers start at 1 and increase monotonically.
*/
public var column: Int
}
/// An error when creating a document.
public enum Error: Swift.Error {
/// A document couldn't be constructed with the provided source.
case invalid
}
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_DOCUMENT }
/**
Creates a document from a CommonMark string.
- Parameter commonmark: A CommonMark string.
- Throws:
- `Document.Error.invalid`
if a document couldn't be constructed with the provided source.
*/
public convenience init(_ commonmark: String, options: ParsingOptions = []) throws {
guard let cmark_node = cmark_parse_document(commonmark, commonmark.utf8.count, options.rawValue)
else {
throw Error.invalid
}
self.init(cmark_node)
self.managed = true
}
public convenience init(children: [Block & Node] = []) {
self.init()
guard !children.isEmpty else { return }
for child in children {
append(child: child)
}
}
#if swift(>=5.4)
public convenience init(options: ParsingOptions = [], @ContainerOfBlocksBuilder _ builder: () -> [Block & Node]) {
self.init(children: builder())
}
#endif
}
// MARK: - Comparable
extension Document.Position: Comparable {
public static func < (lhs: Document.Position, rhs: Document.Position) -> Bool {
return lhs.line < rhs.line || (lhs.line == rhs.line && lhs.column < rhs.column)
}
}
================================================
FILE: Sources/CommonMark/Nodes/Inline/Code.swift
================================================
import cmark
/**
A code span.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [6.3 Code spans](https://spec.commonmark.org/0.29/#code-spans)
>
> A code span begins with a backtick string
> and ends with a backtick string of equal length.
*/
public final class Code: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_CODE }
public convenience init(literal: String? = nil) {
self.init()
self.literal = literal
}
public convenience init(_ block: () -> String?) {
self.init(literal: block())
}
}
================================================
FILE: Sources/CommonMark/Nodes/Inline/Emphasis.swift
================================================
import cmark
/**
An emphasis span.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [6.4 Emphasis and strong emphasis](https://spec.commonmark.org/0.29/#emphasis-and-strong-emphasis)
*/
public final class Emphasis: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_EMPH }
public convenience init(text string: String) {
self.init(children: [Text(literal: string)])
}
public convenience init(children: [Inline & Node] = []) {
self.init()
guard !children.isEmpty else { return }
for child in children {
append(child: child)
}
}
#if swift(>=5.4)
public convenience init(@ContainerOfInlineElementsBuilder _ builder: () -> [Inline & Node]) {
self.init(children: builder())
}
#endif
}
================================================
FILE: Sources/CommonMark/Nodes/Inline/HardLineBreak.swift
================================================
import cmark
/**
A hard line break.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [6.9 Hard line breaks](https://spec.commonmark.org/0.29/#hard-line-breaks)
>
> A line break (not in a code span or HTML tag)
> that is preceded by two or more spaces
> and does not occur at the end of a block
> is parsed as a hard line break
> (rendered in HTML as a `<br />` tag):
*/
public final class HardLineBreak: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_LINEBREAK }
public convenience init() {
self.init(nonrecursively: ())
}
}
================================================
FILE: Sources/CommonMark/Nodes/Inline/Image.swift
================================================
import cmark
/**
An image.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [6.6 Images](https://spec.commonmark.org/0.29/#images)
*/
public final class Image: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_IMAGE }
public convenience init(urlString: String, title: String? = nil) {
self.init()
self.urlString = urlString
self.title = title
}
}
================================================
FILE: Sources/CommonMark/Nodes/Inline/Link.swift
================================================
import cmark
/**
A link.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [6.5 Links](https://spec.commonmark.org/0.29/#links)
>
> A link contains link text (the visible text),
> a link destination (the URI that is the link destination),
> and optionally a link title.
> ## [4.7 Link reference definitions](https://spec.commonmark.org/0.29/#link-reference-definitions)
> ## [6.7 Autolinks](https://spec.commonmark.org/0.29/#autolinks)
*/
public final class Link: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_LINK }
public convenience init(urlString: String, title: String? = nil, text string: String) {
self.init(urlString: urlString, title: title, children: [Text(literal: string)])
}
public convenience init(urlString: String?, title: String?, children: [Inline & Node] = []) {
self.init()
self.urlString = urlString
self.title = title
guard !children.isEmpty else { return }
for child in children {
append(child: child)
}
}
#if swift(>=5.4)
public convenience init(urlString: String?, title: String?, @ContainerOfInlineElementsBuilder _ builder: () -> [Inline & Node]) {
self.init(urlString: urlString, title: title, children: builder())
}
#endif
}
================================================
FILE: Sources/CommonMark/Nodes/Inline/RawHTML.swift
================================================
import cmark
/**
Raw HTML.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [6.8 Raw HTML](https://spec.commonmark.org/0.29/#raw-html)
>
> Text between `<` and `>` that looks like an HTML tag
> is parsed as a raw HTML tag
> and will be rendered in HTML without escaping.
> Tag and attribute names are not limited to current HTML tags,
> so custom tags (and even, say, DocBook tags) may be used.
*/
public final class RawHTML: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_HTML_INLINE }
public convenience init(literal: String?) {
self.init()
self.literal = literal
}
public convenience init(_ block: () -> String?) {
self.init(literal: block())
}
}
================================================
FILE: Sources/CommonMark/Nodes/Inline/SoftLineBreak.swift
================================================
import cmark
/**
A soft line break.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [6.10 Soft line breaks](https://spec.commonmark.org/0.29/#soft-line-breaks)
>
> A regular line break (not in a code span or HTML tag)
> that is not preceded by two or more spaces or a backslash
> is parsed as a softbreak.
> (A softbreak may be rendered in HTML
> either as a line ending or as a space.
> The result will be the same in browsers.)
*/
public final class SoftLineBreak: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_SOFTBREAK }
public convenience init() {
self.init(nonrecursively: ())
}
}
================================================
FILE: Sources/CommonMark/Nodes/Inline/Strong.swift
================================================
import cmark
/**
A strong emphasis span.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [6.4 Emphasis and strong emphasis](https://spec.commonmark.org/0.29/#emphasis-and-strong-emphasis)
*/
public final class Strong: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_STRONG }
public convenience init(text string: String) {
self.init(children: [Text(literal: string)])
}
public convenience init(children: [Inline & Node] = []) {
self.init()
guard !children.isEmpty else { return }
for child in children {
append(child: child)
}
}
#if swift(>=5.4)
public convenience init(@ContainerOfInlineElementsBuilder _ builder: () -> [Inline & Node]) {
self.init(children: builder())
}
#endif
}
================================================
FILE: Sources/CommonMark/Nodes/Inline/Text.swift
================================================
import cmark
/**
Textual content.
From the [CommonMark Spec](https://spec.commonmark.org/0.29):
> ## [6.11 Textual content](https://spec.commonmark.org/0.29/#textual-content)
>
> Any characters not given an interpretation by the above rules
> will be parsed as plain textual content.
*/
public final class Text: Node {
override class var cmark_node_type: cmark_node_type { return CMARK_NODE_TEXT }
public convenience init(literal: String? = nil) {
self.init()
self.literal = literal
}
public convenience init(_ block: () -> String?) {
self.init(literal: block())
}
}
================================================
FILE: Sources/CommonMark/Nodes/Node.swift
================================================
import cmark
/// A CommonMark node.
public class Node: Codable {
class var cmark_node_type: cmark_node_type { return CMARK_NODE_NONE }
/// A pointer to the underlying `cmark_node` for the node.
final let cmark_node: OpaquePointer
/// Whether the underlying `cmark_node` should be freed upon deallocation.
var managed: Bool = false
/**
Creates a node from a `cmark_node` pointer.
- Parameter cmark_node: A `cmark_node` pointer.
*/
required init(_ cmark_node: OpaquePointer) {
self.cmark_node = cmark_node
assert(type(of: self) != Node.self)
assert(cmark_node_get_type(cmark_node) == type(of: self).cmark_node_type)
}
convenience init(nonrecursively: Void) {
self.init()
}
convenience init() {
self.init(cmark_node_new(type(of: self).cmark_node_type))
self.managed = true
}
deinit {
guard managed else { return }
cmark_node_free(cmark_node)
}
/**
Creates and returns the `Node` subclass corresponding to
the type of a `cmark_node` pointer.
- Parameter cmark_node: A `cmark_node` pointer.
- Returns: An instance of a `Node` subclass.
*/
static func create(for cmark_node: OpaquePointer!) -> Node? {
guard let cmark_node = cmark_node else { return nil }
switch cmark_node_get_type(cmark_node) {
case CMARK_NODE_DOCUMENT:
return Document(cmark_node)
case CMARK_NODE_BLOCK_QUOTE:
return BlockQuote(cmark_node)
case CMARK_NODE_LIST:
switch cmark_node_get_list_type(cmark_node) {
case CMARK_BULLET_LIST:
return List(cmark_node)
case CMARK_ORDERED_LIST:
return List(cmark_node)
default:
return nil
}
case CMARK_NODE_ITEM:
return List.Item(cmark_node)
case CMARK_NODE_CODE_BLOCK:
return CodeBlock(cmark_node)
case CMARK_NODE_HTML_BLOCK:
return HTMLBlock(cmark_node)
case CMARK_NODE_PARAGRAPH:
return Paragraph(cmark_node)
case CMARK_NODE_HEADING:
return Heading(cmark_node)
case CMARK_NODE_THEMATIC_BREAK:
return ThematicBreak(cmark_node)
case CMARK_NODE_TEXT:
return Text(cmark_node)
case CMARK_NODE_SOFTBREAK:
return SoftLineBreak(cmark_node)
case CMARK_NODE_LINEBREAK:
return HardLineBreak(cmark_node)
case CMARK_NODE_CODE:
return Code(cmark_node)
case CMARK_NODE_HTML_INLINE:
return RawHTML(cmark_node)
case CMARK_NODE_EMPH:
return Emphasis(cmark_node)
case CMARK_NODE_STRONG:
return Strong(cmark_node)
case CMARK_NODE_LINK:
return Link(cmark_node)
case CMARK_NODE_IMAGE:
return Image(cmark_node)
default:
return nil
}
}
func unlink() {
cmark_node_unlink(self.cmark_node)
self.managed = true
}
/// The line and column range of the element in the document.
public var range: ClosedRange<Document.Position> {
let start = Document.Position(line: numericCast(cmark_node_get_start_line(cmark_node)), column: numericCast(cmark_node_get_start_column(cmark_node)))
let end = Document.Position(line: max(start.line, numericCast(cmark_node_get_end_line(cmark_node))), column: max(start.column, numericCast(cmark_node_get_end_column(cmark_node))))
return start...end
}
/// The parent of the element, if any.
public var parent: Node? {
return Node.create(for: cmark_node_parent(cmark_node))
}
// MARK: - Rendering
/// Formats for rendering a document.
public enum RenderingFormat {
/// CommonMark
case commonmark
/// HTML
case html
/// XML
case xml
/// LaTeX
case latex
/// Manpage
case manpage
}
/// Options for rendering a CommonMark document.
public struct RenderingOptions: OptionSet {
public var rawValue: Int32
public init(rawValue: Int32 = CMARK_OPT_DEFAULT) {
self.rawValue = rawValue
}
/**
Render raw HTML and "unsafe" links.
A link is considered to be "unsafe"
if its scheme is `javascript:`, `vbscript:`, or `file:`,
or if its scheme is `data:`
and the MIME type of the encoded data isn't one of the following:
- `image/png`
- `image/gif`
- `image/jpeg`
- `image/webp`
By default,
raw HTML is replaced by a placeholder HTML comment.
Unsafe links are replaced by empty strings.
- Important: This option has an effect only when rendering HTML.
*/
public static let unsafe = Self(rawValue: CMARK_OPT_UNSAFE)
/**
Render softbreak elements as spaces.
- Important: This option has no effect when rendering XML.
*/
public static let noBreaks = Self(rawValue: CMARK_OPT_NOBREAKS)
/**
Render softbreak elements as hard line breaks.
- Important: This option has no effect when rendering XML.
*/
public static let hardBreaks = Self(rawValue: CMARK_OPT_HARDBREAKS)
/**
Include a `data-sourcepos` attribute on all block elements
to map the rendered output to the source input.
- Important: This option has an effect only when rendering HTML or XML.
*/
public static let includeSourcePosition = Self(rawValue: CMARK_OPT_SOURCEPOS)
}
/**
Render a document into a given format with the specified options.
- Parameters:
- format: The rendering format
- options: The rendering options
- width: The column width used to wrap lines for rendered output
(`.commonmark`, `.man`, and `.latex` formats only).
Must be a positive number.
Pass `0` to prevent line wrapping.
- Returns: The rendered text.
*/
public func render(format: RenderingFormat, options: RenderingOptions = [], width: Int = 0) -> String {
precondition(width >= 0)
let cString: UnsafeMutablePointer<CChar>
switch format {
case .commonmark:
cString = cmark_render_commonmark(cmark_node, options.rawValue, Int32(clamping: width))
case .html:
cString = cmark_render_html(cmark_node, options.rawValue)
case .xml:
cString = cmark_render_xml(cmark_node, options.rawValue)
case .latex:
cString = cmark_render_latex(cmark_node, options.rawValue, Int32(clamping: width))
case .manpage:
cString = cmark_render_man(cmark_node, options.rawValue, Int32(clamping: width))
}
defer {
free(cString)
}
return String(cString: cString)
}
// MARK: - Codable
public required convenience init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let commonmark = try container.decode(String.self)
let document = try Document(commonmark, options: [])
let node: Node
switch Self.cmark_node_type {
case CMARK_NODE_DOCUMENT:
node = document
case CMARK_NODE_BLOCK_QUOTE,
CMARK_NODE_LIST,
CMARK_NODE_ITEM,
CMARK_NODE_CODE_BLOCK,
CMARK_NODE_HTML_BLOCK,
CMARK_NODE_CUSTOM_BLOCK,
CMARK_NODE_PARAGRAPH,
CMARK_NODE_HEADING,
CMARK_NODE_THEMATIC_BREAK:
node = try Self.extractRootBlock(from: document, in: container)
case CMARK_NODE_TEXT,
CMARK_NODE_SOFTBREAK,
CMARK_NODE_LINEBREAK,
CMARK_NODE_CODE,
CMARK_NODE_HTML_INLINE,
CMARK_NODE_CUSTOM_INLINE,
CMARK_NODE_EMPH,
CMARK_NODE_STRONG,
CMARK_NODE_LINK,
CMARK_NODE_IMAGE:
node = try Self.extractRootInline(from: document, in: container)
default:
throw DecodingError.dataCorruptedError(in: container, debugDescription: "unsupported node type")
}
// If the extracted node is not managed, then we most likely
// introduced a memory bug in our extraction logic:
assert(
node.managed,
"Expected extracted node to be managed"
)
// Un-assign memory management duties from old owning node:
node.managed = false
self.init(node.cmark_node)
// Re-assign memory management duties to new owning node:
self.managed = true
}
public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(description)
}
private static func extractRootBlock(from document: Document, in container: SingleValueDecodingContainer) throws -> Self {
// Unlink the children from the document node to prevent dangling pointers to the parent.
let documentChildren = document.removeChildren()
guard let block = documentChildren.first as? Self,
documentChildren.count == 1
else {
throw DecodingError.dataCorruptedError(in: container, debugDescription: "expected single block node")
}
assert(block.managed)
return block
}
private static func extractRootInline(from document: Document, in container: SingleValueDecodingContainer) throws -> Self {
// Unlink the children from the document node to prevent dangling pointers to the parent.
let documentChildren = document.removeChildren()
guard let paragraph = documentChildren.first as? Paragraph,
documentChildren.count == 1
else {
throw DecodingError.dataCorruptedError(in: container, debugDescription: "expected single paragraph node")
}
// Unlink the children from the root node to prevent dangling pointers to the parent.
let paragraphChildren = paragraph.removeChildren()
guard let inline = paragraphChildren.first as? Self,
paragraphChildren.count == 1
else {
throw DecodingError.dataCorruptedError(in: container, debugDescription: "expected single inline node")
}
assert(inline.managed)
return inline
}
}
// MARK: - Equatable
extension Node: Equatable {
public static func == (lhs: Node, rhs: Node) -> Bool {
return lhs.cmark_node == rhs.cmark_node
}
}
// MARK: - Hashable
extension Node: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(cmark_node)
}
}
// MARK: - CustomStringConvertible
extension Node: CustomStringConvertible {
public var description: String {
self.render(format: .commonmark)
}
}
================================================
FILE: Sources/CommonMark/Result Builders/ContainerOfBlocksBuilder.swift
================================================
#if swift(>=5.4)
@resultBuilder
public struct ContainerOfBlocksBuilder {
/// Required by every result builder to build combined results from
/// statement blocks.
public static func buildBlock(_ components: [Block & Node]...) -> [Block & Node] {
return components.flatMap { $0 }
}
/// If declared, provides contextual type information for statement
/// expressions to translate them into partial results.
public static func buildExpression(_ expression: Block & Node) -> [Block & Node] {
return [expression]
}
/// If declared, provides contextual type information for statement
/// expressions to translate them into partial results.
public static func buildExpression(_ expression: [Block & Node]) -> [Block & Node] {
return expression
}
/// If declared, provides contextual type information for statement
/// expressions to translate them into partial results.
public static func buildExpression(_ expression: Section) -> [Block & Node] {
return expression.children
}
/// If declared, provides contextual type information for statement
/// expressions to translate them into partial results.
public static func buildExpression(_ expression: String?) -> [Block & Node] {
guard let expression = expression, !expression.isEmpty else { return [] }
let document = try? Document(expression)
// Unlink the children from the document node to prevent dangling pointers to the parent.
let children = document?.removeChildren() ?? []
return children
}
/// Enables support for `if` statements that do not have an `else`.
public static func buildOptional(_ component: [Block & Node]?) -> [Block & Node] {
return component ?? []
}
/// With buildEither(second:), enables support for 'if-else' and 'switch'
/// statements by folding conditional results into a single result.
public static func buildEither(first component: [Block & Node]) -> [Block & Node] {
return component
}
/// With buildEither(first:), enables support for 'if-else' and 'switch'
/// statements by folding conditional results into a single result.
public static func buildEither(second component: [Block & Node]) -> [Block & Node] {
return component
}
/// Enables support for 'for..in' loops by combining the
/// results of all iterations into a single result.
public static func buildArray(_ components: [[Block & Node]]) -> [Block & Node] {
return components.flatMap { $0 }
}
/// If declared, this will be called on the partial result of an 'if
/// #available' block to allow the result builder to erase type
/// information.
public static func buildLimitedAvailability(_ component: [Block & Node]) -> [Block & Node] {
return component
}
}
#endif
================================================
FILE: Sources/CommonMark/Result Builders/ContainerOfInlineElementsBuilder.swift
================================================
#if swift(>=5.4)
@resultBuilder
public struct ContainerOfInlineElementsBuilder {
/// Required by every result builder to build combined results from
/// statement blocks.
public static func buildBlock(_ components: [Inline & Node]...) -> [Inline & Node] {
return components.flatMap { $0 }
}
/// If declared, provides contextual type information for statement
/// expressions to translate them into partial results.
public static func buildExpression(_ expression: String?) -> [Inline & Node] {
guard let expression = expression, !expression.isEmpty else { return [] }
return [Text(literal: expression)]
}
/// If declared, provides contextual type information for statement
/// expressions to translate them into partial results.
public static func buildExpression(_ expression: Inline & Node) -> [Inline & Node] {
return [expression]
}
/// If declared, provides contextual type information for statement
/// expressions to translate them into partial results.
public static func buildExpression(_ expression: [Inline & Node]) -> [Inline & Node] {
return expression
}
/// Enables support for `if` statements that do not have an `else`.
public static func buildOptional(_ component: [Inline & Node]?) -> [Inline & Node] {
return component ?? []
}
/// With buildEither(second:), enables support for 'if-else' and 'switch'
/// statements by folding conditional results into a single result.
public static func buildEither(first component: [Inline & Node]) -> [Inline & Node] {
return component
}
/// With buildEither(first:), enables support for 'if-else' and 'switch'
/// statements by folding conditional results into a single result.
public static func buildEither(second component: [Inline & Node]) -> [Inline & Node] {
return component
}
/// Enables support for 'for..in' loops by combining the
/// results of all iterations into a single result.
public static func buildArray(_ components: [[Inline & Node]]) -> [Inline & Node] {
return components.flatMap { $0 }
}
/// If declared, this will be called on the partial result of an 'if
/// #available' block to allow the result builder to erase type
/// information.
public static func buildLimitedAvailability(_ component: [Inline & Node]) -> [Inline & Node] {
return component
}
}
#endif
================================================
FILE: Sources/CommonMark/Result Builders/ListBuilder.swift
================================================
#if swift(>=5.4)
@resultBuilder
public struct ListBuilder {
/// Required by every result builder to build combined results from
/// statement blocks.
public static func buildBlock(_ components: [List.Item]...) -> [List.Item] {
return components.flatMap { $0 }
}
/// If declared, provides contextual type information for statement
/// expressions to translate them into partial results.
public static func buildExpression(_ expression: String?) -> [List.Item] {
guard let expression = expression, !expression.isEmpty else { return [] }
return [List.Item(children: [Paragraph(text: expression)])]
}
/// If declared, provides contextual type information for statement
/// expressions to translate them into partial results.
public static func buildExpression(_ expression: Inline & Node) -> [List.Item] {
return [List.Item(children: [expression])]
}
/// If declared, provides contextual type information for statement
/// expressions to translate them into partial results.
public static func buildExpression(_ expression: Block & Node) -> [List.Item] {
return [List.Item(children: [expression])]
}
/// If declared, provides contextual type information for statement
/// expressions to translate them into partial results.
public static func buildExpression(_ expression: [Inline & Node]) -> [List.Item] {
return [List.Item(children: expression)]
}
/// If declared, provides contextual type information for statement
/// expressions to translate them into partial results.
public static func buildExpression(_ expression: [Block & Node]) -> [List.Item] {
return [List.Item(children: expression)]
}
/// Enables support for `if` statements that do not have an `else`.
public static func buildOptional(_ component: [List.Item]?) -> [List.Item] {
return component ?? []
}
/// With buildEither(second:), enables support for 'if-else' and 'switch'
/// statements by folding conditional results into a single result.
public static func buildEither(first component: [List.Item]) -> [List.Item] {
return component
}
/// With buildEither(first:), enables support for 'if-else' and 'switch'
/// statements by folding conditional results into a single result.
public static func buildEither(second component: [List.Item]) -> [List.Item] {
return component
}
/// Enables support for 'for..in' loops by combining the
/// results of all iterations into a single result.
public static func buildArray(_ components: [[List.Item]]) -> [List.Item] {
return components.flatMap { $0 }
}
/// If declared, this will be called on the partial result of an 'if
/// #available' block to allow the result builder to erase type
/// information.
public static func buildLimitedAvailability(_ component: [List.Item]) -> [List.Item] {
return component
}
}
#endif
================================================
FILE: Sources/CommonMark/Supporting Types/Block.swift
================================================
import cmark
/// A block structure element.
public protocol Block {}
// MARK: -
/// A block that can contain other blocks.
public protocol ContainerBlock: Block {}
extension BlockQuote: ContainerBlock {}
extension List: ContainerBlock {}
extension List.Item: ContainerBlock {}
// MARK: -
/// A block that can only contain inline elements.
public protocol LeafBlock: Block {}
extension Heading: LeafBlock {}
extension Paragraph: LeafBlock {}
extension HTMLBlock: LeafBlock {}
extension CodeBlock: LeafBlock {}
extension ThematicBreak: LeafBlock {}
================================================
FILE: Sources/CommonMark/Supporting Types/Children.swift
================================================
import cmark
struct Children: Sequence {
var cmark_node: OpaquePointer
init(of node: Node) {
cmark_node = node.cmark_node
}
init(of document: Document) {
cmark_node = document.cmark_node
}
func makeIterator() -> AnyIterator<Node> {
var iterator = CMarkNodeChildIterator(cmark_node)
return AnyIterator {
guard let child = iterator.next() else { return nil }
return Node.create(for: child)
}
}
}
struct CMarkNodeChildIterator: IteratorProtocol {
var current: OpaquePointer!
init(_ node: OpaquePointer!) {
current = cmark_node_first_child(node)
}
mutating func next() -> OpaquePointer? {
guard let next = current else { return nil }
defer { current = cmark_node_next(current) }
return next
}
}
// MARK: -
public protocol ContainerOfBlocks: Node {
var children: [Block & Node] { get }
}
extension Document: ContainerOfBlocks {}
extension BlockQuote: ContainerOfBlocks {}
extension ContainerOfBlocks {
/**
The block elements contained by the node.
- Important: The returned child nodes are valid only during the lifetime of their parent.
Use the `removeChildren()` method to detach and access children
beyond the lifetime of their parent.
*/
public var children: [Block & Node] {
get {
return Children(of: self).compactMap { $0 as? Block & Node }
}
set {
for child in children {
remove(child: child)
}
for child in newValue {
append(child: child)
}
}
}
/**
Adds a block to the beginning of the node's children.
- Parameters:
- child: The block to add.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func prepend(child: Block & Node) -> Bool {
guard cmark_node_prepend_child(cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Adds a block to the end of the node's children.
- Parameters:
- child: The block to add.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func append(child: Block & Node) -> Bool {
guard cmark_node_append_child(cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Inserts a block to the node's children before a specified sibling.
- Parameters:
- child: The block to add.
- sibling: The child before which the block is added
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func insert(child: Block & Node, before sibling: Block & Node) -> Bool {
guard cmark_node_insert_before(sibling.cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Inserts a block to the node's children after a specified sibling.
- Parameters:
- child: The block to add.
- sibling: The child after which the block is added
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func insert(child: Block & Node, after sibling: Block & Node) -> Bool {
guard cmark_node_insert_after(sibling.cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Replaces a block with the specified node.
- Parameters:
- child: The block to replace.
- replacement: The block to replace the existing block.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func replace(child: Block & Node, with replacement: Block & Node) -> Bool {
guard cmark_node_replace(child.cmark_node, replacement.cmark_node) == 1 else { return false }
replacement.managed = false
child.managed = true
return true
}
/**
Removes a block from the node's children.
- Parameters:
- child: The block to remove.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func remove(child: Block & Node) -> Bool {
guard child.parent == self else { return false }
child.unlink()
return true
}
/**
Removes and returns the node's children.
- Returns: An array of block structure elements.
*/
@discardableResult
public func removeChildren() -> [Block & Node] {
var children: [Block & Node] = []
for child in self.children {
guard remove(child: child) else { continue }
children.append(child)
}
return children
}
}
// MARK: -
public protocol ContainerOfInlineElements: Node {
var children: [Inline & Node] { get }
}
extension Heading: ContainerOfInlineElements {}
extension Paragraph: ContainerOfInlineElements {}
extension CodeBlock: ContainerOfInlineElements {}
extension ThematicBreak: ContainerOfInlineElements {}
extension Strong: ContainerOfInlineElements {}
extension Emphasis: ContainerOfInlineElements {}
extension Link: ContainerOfInlineElements {}
extension ContainerOfInlineElements {
/**
The inline elements contained by the node.
- Important: The returned child nodes are valid only during the lifetime of their parent.
Use the `removeChildren()` method to detach and access children
beyond the lifetime of their parent.
*/
public var children: [Inline & Node] {
get {
return Children(of: self).compactMap { $0 as? Inline & Node }
}
set {
for child in children {
remove(child: child)
}
for child in newValue {
append(child: child)
}
}
}
/**
Adds an inline element to the beginning of the node's children.
- Parameters:
- child: The inline element to add.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func prepend(child: Inline & Node) -> Bool {
guard cmark_node_prepend_child(cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Adds an inline element to the end of the node's children.
- Parameters:
- child: The inline element to add.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func append(child: Inline & Node) -> Bool {
guard cmark_node_append_child(cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Inserts an inline element to the node's children before a specified sibling.
- Parameters:
- child: The inline element to add.
- sibling: The child before which the inline element is added
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func insert(child: Inline & Node, before sibling: Inline & Node) -> Bool {
guard cmark_node_insert_before(sibling.cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Inserts an inline element to the node's children after a specified sibling.
- Parameters:
- child: The inline element to add.
- sibling: The child after which the inline element is added
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func insert(child: Inline & Node, after sibling: Inline & Node) -> Bool {
guard cmark_node_insert_after(sibling.cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Replaces an inline element with the specified node.
- Parameters:
- child: The inline element to replace.
- replacement: The inline element to replace the existing inline element.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func replace(child: Inline & Node, with replacement: Inline & Node) -> Bool {
guard cmark_node_replace(child.cmark_node, replacement.cmark_node) == 1 else { return false }
replacement.managed = false
child.managed = true
return true
}
/**
Removes an inline element from the node's children.
- Parameters:
- child: The inline element to remove.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func remove(child: Inline & Node) -> Bool {
guard child.parent == self else { return false }
child.unlink()
return true
}
/**
Removes and returns the node's children.
- Returns: An array of inline content elements.
*/
@discardableResult
public func removeChildren() -> [Inline & Node] {
var children: [Inline & Node] = []
for child in self.children {
guard remove(child: child) else { continue }
children.append(child)
}
return children
}
}
// MARK: -
extension List {
/**
The list's items.
- Important: The returned child nodes are valid only during the lifetime of their parent.
Use the `removeChildren()` method to detach and access children
beyond the lifetime of their parent.
*/
public var children: [Item] {
get {
return Children(of: self).compactMap { $0 as? Item }
}
set {
for child in children {
remove(child: child)
}
for child in newValue {
append(child: child)
}
}
}
/**
Adds an item to the beginning of the list.
- Parameters:
- child: The item to add.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func prepend(child: Item) -> Bool {
guard cmark_node_prepend_child(cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Adds an to the end of the list.
- Parameters:
- child: The item to add.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func append(child: Item) -> Bool {
guard cmark_node_append_child(cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Inserts an item to the list before a specified sibling.
- Parameters:
- child: The item to add.
- sibling: The item before which the new item is added
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func insert(child: Item, before sibling: Item) -> Bool {
guard cmark_node_insert_before(sibling.cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Inserts an item to the list after a specified sibling.
- Parameters:
- child: The item to add.
- sibling: The item after which the new item is added
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func insert(child: Item, after sibling: Item) -> Bool {
guard cmark_node_insert_after(sibling.cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Replaces an item with the specified node.
- Parameters:
- child: The item to replace.
- replacement: The item to replace the existing item.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func replace(child: Item, with replacement: Item) -> Bool {
guard cmark_node_replace(child.cmark_node, replacement.cmark_node) == 1 else { return false }
replacement.managed = false
child.managed = true
return true
}
/**
Removes an item from the list.
- Parameters:
- child: The item to remove.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func remove(child: Item) -> Bool {
guard child.parent == self else { return false }
child.unlink()
return true
}
/**
Removes and returns the list's items.
- Returns: An array of list items.
*/
@discardableResult
public func removeChildren() -> [Item] {
var children: [Item] = []
for child in self.children {
guard remove(child: child) else { continue }
children.append(child)
}
return children
}
}
// MARK: -
extension List.Item {
/**
The elements contained by the list item.
- Important: The returned child nodes are valid only during the lifetime of their parent.
Use the `removeChildren()` method to detach and access children
beyond the lifetime of their parent.
*/
public var children: [Node] {
get {
return Children(of: self).map { $0 }
}
set {
for child in children {
remove(child: child)
}
for child in newValue {
append(child: child)
}
}
}
/**
Adds a node to the beginning of the list item's children.
- Parameters:
- child: The node to add.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func prepend(child: Node) -> Bool {
guard cmark_node_prepend_child(cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Adds a node to the end of the list item's children.
- Parameters:
- child: The node to add.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func append(child: Node) -> Bool {
guard cmark_node_append_child(cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Inserts a node to the list item's children before a specified sibling.
- Parameters:
- child: The node to add.
- sibling: The child before which the node is added
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func insert(child: Node, before sibling: Node) -> Bool {
guard cmark_node_insert_before(sibling.cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Inserts a node to the list item's children after a specified sibling.
- Parameters:
- child: The node to add.
- sibling: The child after which the node is added
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func insert(child: Node, after sibling: Node) -> Bool {
guard cmark_node_insert_after(sibling.cmark_node, child.cmark_node) == 1 else { return false }
child.managed = false
return true
}
/**
Replaces a node with a specified node.
- Parameters:
- child: The node to replace.
- replacement: The node to replace the existing node.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func replace(child: Node, with replacement: Node) -> Bool {
guard cmark_node_replace(child.cmark_node, replacement.cmark_node) == 1 else { return false }
replacement.managed = false
return true
}
/**
Removes a node from the list item's children.
- Parameters:
- child: The node to remove.
- Returns: `true` if successful, otherwise `false`.
*/
@discardableResult
public func remove(child: Node) -> Bool {
guard child.parent == self else { return false }
child.unlink()
return true
}
/**
Removes and returns the list item's children.
- Returns: An array of nodes.
*/
public func removeChildren() -> [Node] {
var children: [Node] = []
for child in self.children {
guard remove(child: child) else { continue }
children.append(child)
}
return children
}
}
================================================
FILE: Sources/CommonMark/Supporting Types/Fragment.swift
================================================
public struct Fragment {
public var children: [Block & Node] = []
init(children: [Block & Node]) {
self.children = children
}
public init(_ string: String) {
let document = try? Document(string)
// Unlink the children from the document node to prevent dangling pointers to the parent.
let children = document?.removeChildren() ?? []
self.init(children: children)
}
//
// public init(@CommonMarkBuilder _ builder: () -> BlockConvertible) {
// self.init(children: builder().blockValue)
// }
// public init(@CommonMarkBuilder _ builder: () -> BlockConvertible) {
// self.init(children: builder().blockValue)
// }
}
// MARK: - BlockConvertible
//
//extension Fragment: BlockConvertible {
// public var blockValue: [Block & Node] {
// return children
// }
//}
//
//// MARK: - ListItemConvertible
//
//extension Fragment: ListItemConvertible {
// public var listItemValue: [List.Item] {
// return children as? [List.Item] ?? [List.Item(children: children)]
// }
//}
================================================
FILE: Sources/CommonMark/Supporting Types/Inline.swift
================================================
/// An inline content element.
public protocol Inline {}
// MARK: -
extension Text: Inline {}
extension Strong: Inline {}
extension Emphasis: Inline {}
extension Link: Inline {}
extension Image: Inline {}
extension Code: Inline {}
extension RawHTML: Inline {}
extension SoftLineBreak: Inline {}
extension HardLineBreak: Inline {}
================================================
FILE: Sources/CommonMark/Supporting Types/LineBreak.swift
================================================
/// A line break element.
public protocol LineBreak {}
// MARK: -
extension HardLineBreak: LineBreak {}
extension SoftLineBreak: LineBreak {}
================================================
FILE: Sources/CommonMark/Supporting Types/Linked.swift
================================================
import cmark
public protocol Linked: Node {}
extension Link: Linked {}
extension Image: Linked {}
extension Linked {
public var urlString: String? {
get {
return String(cString: cmark_node_get_url(cmark_node))
}
set {
cmark_node_set_url(cmark_node, newValue)
}
}
public var title: String? {
get {
return String(cString: cmark_node_get_title(cmark_node))
}
set {
cmark_node_set_title(cmark_node, newValue)
}
}
}
================================================
FILE: Sources/CommonMark/Supporting Types/Literal.swift
================================================
import cmark
/// An element with literal contents.
public protocol Literal: Node {
init(literal: String?)
}
// MARK: -
extension Literal {
/// The literal contents of the element.
public var literal: String? {
get {
return String(cString: cmark_node_get_literal(cmark_node))
}
set {
cmark_node_set_literal(cmark_node, newValue)
}
}
}
// MARK: -
extension Code: Literal {}
extension CodeBlock: Literal {}
extension RawHTML: Literal {}
extension HTMLBlock: Literal {}
extension Text: Literal {}
================================================
FILE: Sources/CommonMark/Supporting Types/Section.swift
================================================
public struct Section {
private var levelAdjustment: Int
public var children: [Block & Node] = []
init(levelAdjustment: Int = +1, children: [Block & Node]) {
self.levelAdjustment = levelAdjustment
self.children = children
}
#if swift(>=5.4)
public init(levelAdjustment: Int = +1, @ContainerOfBlocksBuilder _ builder: () -> [Block & Node]) {
self.init(levelAdjustment: levelAdjustment, children: builder().map { child in
guard let heading = child as? Heading else { return child }
heading.level += levelAdjustment
return heading
})
}
#endif
}
================================================
FILE: Sources/CommonMark/Supporting Types/Visitable.swift
================================================
public protocol Visitable {
func accept<T: Visitor>(visitor: T)
}
// MARK: - Document
extension Document: Visitable {
public func accept<T: Visitor>(visitor: T) {
let continueKind = visitor.visit(self, by: visitor.visit(document: self))
if continueKind == .visitChildren {
self.walkVisitableChildren(with: visitor)
}
visitor.visitPost(document: self)
}
}
// MARK: - Container Blocks
extension BlockQuote: Visitable {
public func accept<T: Visitor>(visitor: T) {
let continueKind = visitor.visit(self, by: visitor.visit(blockQuote: self))
if continueKind == .visitChildren {
self.walkVisitableChildren(with: visitor)
}
visitor.visitPost(blockQuote: self)
}
}
extension List: Visitable {
public func accept<T: Visitor>(visitor: T) {
let continueKind = visitor.visit(self, by: visitor.visit(list: self))
if continueKind == .visitChildren {
self.walkVisitableChildren(with: visitor)
}
visitor.visitPost(list: self)
}
}
extension List.Item: Visitable {
public func accept<T: Visitor>(visitor: T) {
let continueKind = visitor.visit(self, by: visitor.visit(listItem: self))
if continueKind == .visitChildren {
self.walkVisitableChildren(with: visitor)
}
visitor.visitPost(listItem: self)
}
}
// MARK: - Leaf Blocks
extension Heading: Visitable {
public func accept<T: Visitor>(visitor: T) {
let continueKind = visitor.visit(self, by: visitor.visit(heading: self))
if continueKind == .visitChildren {
self.walkVisitableChildren(with: visitor)
}
visitor.visitPost(heading: self)
}
}
extension Paragraph: Visitable {
public func accept<T: Visitor>(visitor: T) {
let continueKind = visitor.visit(self, by: visitor.visit(paragraph: self))
if continueKind == .visitChildren {
self.walkVisitableChildren(with: visitor)
}
visitor.visitPost(paragraph: self)
}
}
extension HTMLBlock: Visitable {
public func accept<T: Visitor>(visitor: T) {
_ = visitor.visit(self, by: visitor.visit(htmlBlock: self))
visitor.visitPost(htmlBlock: self)
}
}
extension CodeBlock: Visitable {
public func accept<T: Visitor>(visitor: T) {
let continueKind = visitor.visit(self, by: visitor.visit(codeBlock: self))
if continueKind == .visitChildren {
self.walkVisitableChildren(with: visitor)
}
visitor.visitPost(codeBlock: self)
}
}
extension ThematicBreak: Visitable {
public func accept<T: Visitor>(visitor: T) {
let continueKind = visitor.visit(self, by: visitor.visit(thematicBreak: self))
if continueKind == .visitChildren {
self.walkVisitableChildren(with: visitor)
}
visitor.visitPost(thematicBreak: self)
}
}
// MARK: - Inline
extension Text: Visitable {
public func accept<T: Visitor>(visitor: T) {
_ = visitor.visit(self, by: visitor.visit(text: self))
visitor.visitPost(text: self)
}
}
extension Strong: Visitable {
public func accept<T: Visitor>(visitor: T) {
let continueKind = visitor.visit(self, by: visitor.visit(strong: self))
if continueKind == .visitChildren {
self.walkVisitableChildren(with: visitor)
}
visitor.visitPost(strong: self)
}
}
extension Emphasis: Visitable {
public func accept<T: Visitor>(visitor: T) {
let continueKind = visitor.visit(self, by: visitor.visit(emphasis: self))
if continueKind == .visitChildren {
self.walkVisitableChildren(with: visitor)
}
visitor.visitPost(emphasis: self)
}
}
extension Link: Visitable {
public func accept<T: Visitor>(visitor: T) {
let continueKind = visitor.visit(self, by: visitor.visit(link: self))
if continueKind == .visitChildren {
self.walkVisitableChildren(with: visitor)
}
visitor.visitPost(link: self)
}
}
extension Image: Visitable {
public func accept<T: Visitor>(visitor: T) {
_ = visitor.visit(self, by: visitor.visit(image: self))
visitor.visitPost(image: self)
}
}
extension Code: Visitable {
public func accept<T: Visitor>(visitor: T) {
_ = visitor.visit(self, by: visitor.visit(code: self))
visitor.visitPost(code: self)
}
}
extension RawHTML: Visitable {
public func accept<T: Visitor>(visitor: T) {
_ = visitor.visit(self, by: visitor.visit(rawHTML: self))
visitor.visitPost(rawHTML: self)
}
}
extension SoftLineBreak: Visitable {
public func accept<T: Visitor>(visitor: T) {
_ = visitor.visit(self, by: visitor.visit(softLineBreak: self))
visitor.visitPost(softLineBreak: self)
}
}
extension HardLineBreak: Visitable {
public func accept<T: Visitor>(visitor: T) {
_ = visitor.visit(self, by: visitor.visit(hardLineBreak: self))
visitor.visitPost(hardLineBreak: self)
}
}
// MARK: - Convenience Helpers
extension ContainerOfBlocks {
internal var visitableChildren: AnyCollection<Visitable & Block & Node> {
return AnyCollection(self.children.lazy.compactMap {
$0 as? Visitable & Block & Node
})
}
internal func walkVisitableChildren<T: Visitor>(with visitor: T) {
for child in self.visitableChildren {
child.accept(visitor: visitor)
}
}
}
extension ContainerOfInlineElements {
internal var visitableChildren: AnyCollection<Visitable & Inline & Node> {
return AnyCollection(self.children.lazy.compactMap {
$0 as? Visitable & Inline & Node
})
}
internal func walkVisitableChildren<T: Visitor>(with visitor: T) {
for child in self.visitableChildren {
child.accept(visitor: visitor)
}
}
}
extension List {
internal var visitableChildren: AnyCollection<Visitable & List.Item> {
return AnyCollection(self.children)
}
internal func walkVisitableChildren<T: Visitor>(with visitor: T) {
for child in self.visitableChildren {
child.accept(visitor: visitor)
}
}
}
extension List.Item {
internal var visitableChildren: AnyCollection<Visitable & Node> {
return AnyCollection(self.children.lazy.compactMap {
$0 as? Visitable & Node
})
}
internal func walkVisitableChildren<T: Visitor>(with visitor: T) {
for child in self.visitableChildren {
child.accept(visitor: visitor)
}
}
}
================================================
FILE: Sources/CommonMark/Supporting Types/Visitor.swift
================================================
public enum VisitorContinueKind {
/// The visitor should visit the descendents of the current node.
case visitChildren
/// The visitor should avoid visiting the descendents of the current node.
case skipChildren
/// The visitor should inherit the behavior from the current context.
case inherit
/// The default is `.visitChildren`
static let `default`: Self = .visitChildren
mutating func override(with other: Self) {
switch other {
case .visitChildren, .skipChildren:
self = other
case .inherit:
break
}
}
}
/// Visitor for walking a visitable structure.
///
/// Override the appropriate `func visit(…:)`'s return value
/// to customize the behavior (e.g. skip a given element's children),
/// with sub-types overriding their super-type's behavior.
///
/// The default implementation of `func visit(…:)`returns `.inherit`,
/// resulting in a deep walk over the entire document.
///
/// ## Sub-type inheritance
///
/// ```plain
/// Node
/// ├── Block
/// │ ├── ContainerBlock
/// │ │ ├── BlockQuote
/// │ │ ├── List
/// │ │ └── List.Item
/// │ │
/// │ └── LeafBlock
/// │ ├── CodeBlock
/// │ ├── HTMLBlock
/// │ ├── Heading
/// │ ├── Paragraph
/// │ └── ThematicBreak
/// │
/// └── Inline
/// ├── Code
/// ├── Emphasis
/// ├── HardLineBreak
/// ├── Image
/// ├── Link
/// ├── RawHTML
/// ├── SoftLineBreak
/// ├── Strong
/// └── Text
/// ```
///
/// ## Order of Visitation
///
/// The order of object-wise visitations is: super-type before sub-type.
///
/// ## Order of Post-Visitation
///
/// The order of object-wise visitations is: sub-type before super-type.
public protocol Visitor {
/// Walks a visitable structure.
/// - Parameter visitable: The structure to walk.
func walk<T: Visitable>(_ visitable: T)
// MARK: - Document
func visit(document: Document) -> VisitorContinueKind
func visitPost(document: Document)
// MARK: - Node
func visit(node: Node) -> VisitorContinueKind
func visitPost(node: Node)
// MARK: - Blocks
func visit(block: Block) -> VisitorContinueKind
func visitPost(block: Block)
// MARK: - Container Blocks
func visit(containerBlock: ContainerBlock) -> VisitorContinueKind
func visitPost(containerBlock: ContainerBlock)
func visit(blockQuote: BlockQuote) -> VisitorContinueKind
func visitPost(blockQuote: BlockQuote)
func visit(list: List) -> VisitorContinueKind
func visitPost(list: List)
func visit(listItem: List.Item) -> VisitorContinueKind
func visitPost(listItem: List.Item)
// MARK: - Leaf Blocks
/// A block that can only contain inline elements.
func visit(leafBlock: LeafBlock) -> VisitorContinueKind
func visitPost(leafBlock: LeafBlock)
func visit(heading: Heading) -> VisitorContinueKind
func visitPost(heading: Heading)
func visit(paragraph: Paragraph) -> VisitorContinueKind
func visitPost(paragraph: Paragraph)
func visit(htmlBlock: HTMLBlock) -> VisitorContinueKind
func visitPost(htmlBlock: HTMLBlock)
func visit(codeBlock: CodeBlock) -> VisitorContinueKind
func visitPost(codeBlock: CodeBlock)
func visit(thematicBreak: ThematicBreak) -> VisitorContinueKind
func visitPost(thematicBreak: ThematicBreak)
// MARK: - Inline
func visit(inline: Inline) -> VisitorContinueKind
func visitPost(inline: Inline)
func visit(text: Text) -> VisitorContinueKind
func visitPost(text: Text)
func visit(strong: Strong) -> VisitorContinueKind
func visitPost(strong: Strong)
func visit(emphasis: Emphasis) -> VisitorContinueKind
func visitPost(emphasis: Emphasis)
func visit(link: Link) -> VisitorContinueKind
func visitPost(link: Link)
func visit(image: Image) -> VisitorContinueKind
func visitPost(image: Image)
func visit(code: Code) -> VisitorContinueKind
func visitPost(code: Code)
func visit(rawHTML: RawHTML) -> VisitorContinueKind
func visitPost(rawHTML: RawHTML)
func visit(softLineBreak: SoftLineBreak) -> VisitorContinueKind
func visitPost(softLineBreak: SoftLineBreak)
func visit(hardLineBreak: HardLineBreak) -> VisitorContinueKind
func visitPost(hardLineBreak: HardLineBreak)
}
extension Visitor {
public func walk<T: Visitable>(_ visitable: T) {
visitable.accept(visitor: self)
}
// MARK: - Document
public func visit(document: Document) -> VisitorContinueKind {
return .inherit
}
public func visitPost(document: Document) {
// nothing by default
}
// MARK: - Node
public func visit(node: Node) -> VisitorContinueKind {
return .inherit
}
public func visitPost(node: Node) {
// nothing by default
}
// MARK: - Blocks
public func visit(block: Block) -> VisitorContinueKind {
return .inherit
}
public func visitPost(block: Block) {
// nothing by default
}
// MARK: - Container Blocks
public func visit(containerBlock: ContainerBlock) -> VisitorContinueKind {
return .inherit
}
public func visitPost(containerBlock: ContainerBlock) {
// nothing by default
}
public func visit(blockQuote: BlockQuote) -> VisitorContinueKind {
return .inherit
}
public func visitPost(blockQuote: BlockQuote) {
// nothing by default
}
public func visit(list: List) -> VisitorContinueKind {
return .inherit
}
public func visitPost(list: List) {
// nothing by default
}
public func visit(listItem: List.Item) -> VisitorContinueKind {
return .inherit
}
public func visitPost(listItem: List.Item) {
// nothing by default
}
// MARK: - Leaf Blocks
/// A block that can only contain inline elements.
public func visit(leafBlock: LeafBlock) -> VisitorContinueKind {
return .inherit
}
public func visitPost(leafBlock: LeafBlock) {
// nothing by default
}
public func visit(heading: Heading) -> VisitorContinueKind {
return .inherit
}
public func visitPost(heading: Heading) {
// nothing by default
}
public func visit(paragraph: Paragraph) -> VisitorContinueKind {
return .inherit
}
public func visitPost(paragraph: Paragraph) {
// nothing by default
}
public func visit(htmlBlock: HTMLBlock) -> VisitorContinueKind {
return .inherit
}
public func visitPost(htmlBlock: HTMLBlock) {
// nothing by default
}
public func visit(codeBlock: CodeBlock) -> VisitorContinueKind {
return .inherit
}
public func visitPost(codeBlock: CodeBlock) {
// nothing by default
}
public func visit(thematicBreak: ThematicBreak) -> VisitorContinueKind {
return .inherit
}
public func visitPost(thematicBreak: ThematicBreak) {
// nothing by default
}
// MARK: - Inline
public func visit(inline: Inline) -> VisitorContinueKind {
return .inherit
}
public func visitPost(inline: Inline) {
// nothing by default
}
public func visit(text: Text) -> VisitorContinueKind {
return .inherit
}
public func visitPost(text: Text) {
// nothing by default
}
public func visit(strong: Strong) -> VisitorContinueKind {
return .inherit
}
public func visitPost(strong: Strong) {
// nothing by default
}
public func visit(emphasis: Emphasis) -> VisitorContinueKind {
return .inherit
}
public func visitPost(emphasis: Emphasis) {
// nothing by default
}
public func visit(link: Link) -> VisitorContinueKind {
return .inherit
}
public func visitPost(link: Link) {
// nothing by default
}
public func visit(image: Image) -> VisitorContinueKind {
return .inherit
}
public func visitPost(image: Image) {
// nothing by default
}
public func visit(code: Code) -> VisitorContinueKind {
return .inherit
}
public func visitPost(code: Code) {
// nothing by default
}
public func visit(rawHTML: RawHTML) -> VisitorContinueKind {
return .inherit
}
public func visitPost(rawHTML: RawHTML) {
// nothing by default
}
public func visit(softLineBreak: SoftLineBreak) -> VisitorContinueKind {
return .inherit
}
public func visitPost(softLineBreak: SoftLineBreak) {
// nothing by default
}
public func visit(hardLineBreak: HardLineBreak) -> VisitorContinueKind {
return .inherit
}
public func visitPost(hardLineBreak: HardLineBreak) {
// nothing by default
}
}
extension Visitor {
internal func visit<T: Visitable>(
_ visitable: T,
by visitLeafTypeOf: @autoclosure () -> VisitorContinueKind
) -> VisitorContinueKind {
var continueKind = VisitorContinueKind.visitChildren
let inheritedContinueKind = self.visitSuperTypesOf(visitable: visitable)
let leafTypeContinueKind = visitLeafTypeOf()
continueKind.override(with: inheritedContinueKind)
continueKind.override(with: leafTypeContinueKind)
return continueKind
}
internal func visitSuperTypesOf<T: Visitable>(visitable: T) -> VisitorContinueKind {
var continueKind: VisitorContinueKind = .inherit
if let node = visitable as? Node {
continueKind.override(with: self.visit(node: node))
}
if let block = visitable as? Block {
continueKind.override(with: self.visit(block: block))
}
if let containerBlock = visitable as? ContainerBlock {
continueKind.override(with: self.visit(containerBlock: containerBlock))
}
if let leafBlock = visitable as? LeafBlock {
continueKind.override(with: self.visit(leafBlock: leafBlock))
}
if let inline = visitable as? Inline {
continueKind.override(with: self.visit(inline: inline))
}
return continueKind
}
}
================================================
FILE: Sources/CommonMark/Version.swift
================================================
import cmark
/// A version number.
public typealias Version = (major: Int, minor: Int, patch: Int)
/// The version of CommonMark used by this package.
public let version: Version = (
major: Int((cmark_version() & 0xFF0000) >> 16),
minor: Int((cmark_version() & 0xFF00) >> 8),
patch: Int((cmark_version() & 0xFF))
)
================================================
FILE: Tests/CommonMarkSpecTests/AtxHeadingsTests.swift
================================================
// This file was automatically generated and should not be edited.
import XCTest
import CommonMark
final class CommonMarkSpecAtxHeadingsTests: XCTestCase {
func testExample32() throws {
let markdown = #######"""
# foo
## foo
### foo
#### foo
##### foo
###### foo
"""#######
let html = #######"""
<h1>foo</h1>
<h2>foo</h2>
<h3>foo</h3>
<h4>foo</h4>
<h5>foo</h5>
<h6>foo</h6>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample33() throws {
let markdown = #######"""
####### foo
"""#######
let html = #######"""
<p>####### foo</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample34() throws {
let markdown = #######"""
#5 bolt
#hashtag
"""#######
let html = #######"""
<p>#5 bolt</p>
<p>#hashtag</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample35() throws {
let markdown = #######"""
\## foo
"""#######
let html = #######"""
<p>## foo</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample36() throws {
let markdown = #######"""
# foo *bar* \*baz\*
"""#######
let html = #######"""
<h1>foo <em>bar</em> *baz*</h1>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample37() throws {
let markdown = #######"""
# foo
"""#######
let html = #######"""
<h1>foo</h1>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample38() throws {
let markdown = #######"""
### foo
## foo
# foo
"""#######
let html = #######"""
<h3>foo</h3>
<h2>foo</h2>
<h1>foo</h1>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample39() throws {
let markdown = #######"""
# foo
"""#######
let html = #######"""
<pre><code># foo
</code></pre>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample40() throws {
let markdown = #######"""
foo
# bar
"""#######
let html = #######"""
<p>foo
# bar</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample41() throws {
let markdown = #######"""
## foo ##
### bar ###
"""#######
let html = #######"""
<h2>foo</h2>
<h3>bar</h3>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample42() throws {
let markdown = #######"""
# foo ##################################
##### foo ##
"""#######
let html = #######"""
<h1>foo</h1>
<h5>foo</h5>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample43() throws {
let markdown = #######"""
### foo ###
"""#######
let html = #######"""
<h3>foo</h3>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample44() throws {
let markdown = #######"""
### foo ### b
"""#######
let html = #######"""
<h3>foo ### b</h3>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample45() throws {
let markdown = #######"""
# foo#
"""#######
let html = #######"""
<h1>foo#</h1>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample46() throws {
let markdown = #######"""
### foo \###
## foo #\##
# foo \#
"""#######
let html = #######"""
<h3>foo ###</h3>
<h2>foo ###</h2>
<h1>foo #</h1>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample47() throws {
let markdown = #######"""
****
## foo
****
"""#######
let html = #######"""
<hr />
<h2>foo</h2>
<hr />
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample48() throws {
let markdown = #######"""
Foo bar
# baz
Bar foo
"""#######
let html = #######"""
<p>Foo bar</p>
<h1>baz</h1>
<p>Bar foo</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample49() throws {
let markdown = #######"""
##
#
### ###
"""#######
let html = #######"""
<h2></h2>
<h1></h1>
<h3></h3>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
}
================================================
FILE: Tests/CommonMarkSpecTests/AutolinksTests.swift
================================================
// This file was automatically generated and should not be edited.
import XCTest
import CommonMark
final class CommonMarkSpecAutolinksTests: XCTestCase {
func testExample590() throws {
let markdown = #######"""
<http://foo.bar.baz>
"""#######
let html = #######"""
<p><a href="http://foo.bar.baz">http://foo.bar.baz</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample591() throws {
let markdown = #######"""
<http://foo.bar.baz/test?q=hello&id=22&boolean>
"""#######
let html = #######"""
<p><a href="http://foo.bar.baz/test?q=hello&id=22&boolean">http://foo.bar.baz/test?q=hello&id=22&boolean</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample592() throws {
let markdown = #######"""
<irc://foo.bar:2233/baz>
"""#######
let html = #######"""
<p><a href="irc://foo.bar:2233/baz">irc://foo.bar:2233/baz</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample593() throws {
let markdown = #######"""
<MAILTO:FOO@BAR.BAZ>
"""#######
let html = #######"""
<p><a href="MAILTO:FOO@BAR.BAZ">MAILTO:FOO@BAR.BAZ</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample594() throws {
let markdown = #######"""
<a+b+c:d>
"""#######
let html = #######"""
<p><a href="a+b+c:d">a+b+c:d</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample595() throws {
let markdown = #######"""
<made-up-scheme://foo,bar>
"""#######
let html = #######"""
<p><a href="made-up-scheme://foo,bar">made-up-scheme://foo,bar</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample596() throws {
let markdown = #######"""
<http://../>
"""#######
let html = #######"""
<p><a href="http://../">http://../</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample597() throws {
let markdown = #######"""
<localhost:5001/foo>
"""#######
let html = #######"""
<p><a href="localhost:5001/foo">localhost:5001/foo</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample598() throws {
let markdown = #######"""
<http://foo.bar/baz bim>
"""#######
let html = #######"""
<p><http://foo.bar/baz bim></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample599() throws {
let markdown = #######"""
<http://example.com/\[\>
"""#######
let html = #######"""
<p><a href="http://example.com/%5C%5B%5C">http://example.com/\[\</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample600() throws {
let markdown = #######"""
<foo@bar.example.com>
"""#######
let html = #######"""
<p><a href="mailto:foo@bar.example.com">foo@bar.example.com</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample601() throws {
let markdown = #######"""
<foo+special@Bar.baz-bar0.com>
"""#######
let html = #######"""
<p><a href="mailto:foo+special@Bar.baz-bar0.com">foo+special@Bar.baz-bar0.com</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample602() throws {
let markdown = #######"""
<foo\+@bar.example.com>
"""#######
let html = #######"""
<p><foo+@bar.example.com></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample603() throws {
let markdown = #######"""
<>
"""#######
let html = #######"""
<p><></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample604() throws {
let markdown = #######"""
< http://foo.bar >
"""#######
let html = #######"""
<p>< http://foo.bar ></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample605() throws {
let markdown = #######"""
<m:abc>
"""#######
let html = #######"""
<p><m:abc></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample606() throws {
let markdown = #######"""
<foo.bar.baz>
"""#######
let html = #######"""
<p><foo.bar.baz></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample607() throws {
let markdown = #######"""
http://example.com
"""#######
let html = #######"""
<p>http://example.com</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample608() throws {
let markdown = #######"""
foo@bar.example.com
"""#######
let html = #######"""
<p>foo@bar.example.com</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
}
================================================
FILE: Tests/CommonMarkSpecTests/BackslashEscapesTests.swift
================================================
// This file was automatically generated and should not be edited.
import XCTest
import CommonMark
final class CommonMarkSpecBackslashEscapesTests: XCTestCase {
func testExample298() throws {
let markdown = #######"""
\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~
"""#######
let html = #######"""
<p>!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample299() throws {
let markdown = #######"""
\ \A\a\ \3\φ\«
"""#######
let html = #######"""
<p>\ \A\a\ \3\φ\«</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample300() throws {
let markdown = #######"""
\*not emphasized*
\<br/> not a tag
\[not a link](/foo)
\`not code`
1\. not a list
\* not a list
\# not a heading
\[foo]: /url "not a reference"
\ö not a character entity
"""#######
let html = #######"""
<p>*not emphasized*
<br/> not a tag
[not a link](/foo)
`not code`
1. not a list
* not a list
# not a heading
[foo]: /url "not a reference"
&ouml; not a character entity</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample301() throws {
let markdown = #######"""
\\*emphasis*
"""#######
let html = #######"""
<p>\<em>emphasis</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample302() throws {
let markdown = #######"""
foo\
bar
"""#######
let html = #######"""
<p>foo<br />
bar</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample303() throws {
let markdown = #######"""
`` \[\` ``
"""#######
let html = #######"""
<p><code>\[\`</code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample304() throws {
let markdown = #######"""
\[\]
"""#######
let html = #######"""
<pre><code>\[\]
</code></pre>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample305() throws {
let markdown = #######"""
~~~
\[\]
~~~
"""#######
let html = #######"""
<pre><code>\[\]
</code></pre>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample306() throws {
let markdown = #######"""
<http://example.com?find=\*>
"""#######
let html = #######"""
<p><a href="http://example.com?find=%5C*">http://example.com?find=\*</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample307() throws {
let markdown = #######"""
<a href="/bar\/)">
"""#######
let html = #######"""
<a href="/bar\/)">
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample308() throws {
let markdown = #######"""
[foo](/bar\* "ti\*tle")
"""#######
let html = #######"""
<p><a href="/bar*" title="ti*tle">foo</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample309() throws {
let markdown = #######"""
[foo]
[foo]: /bar\* "ti\*tle"
"""#######
let html = #######"""
<p><a href="/bar*" title="ti*tle">foo</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample310() throws {
let markdown = #######"""
``` foo\+bar
foo
```
"""#######
let html = #######"""
<pre><code class="language-foo+bar">foo
</code></pre>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
}
================================================
FILE: Tests/CommonMarkSpecTests/BlankLinesTests.swift
================================================
// This file was automatically generated and should not be edited.
import XCTest
import CommonMark
final class CommonMarkSpecBlankLinesTests: XCTestCase {
func testExample197() throws {
let markdown = #######"""
aaa
# aaa
"""#######
let html = #######"""
<p>aaa</p>
<h1>aaa</h1>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
}
================================================
FILE: Tests/CommonMarkSpecTests/BlockQuotesTests.swift
================================================
// This file was automatically generated and should not be edited.
import XCTest
import CommonMark
final class CommonMarkSpecBlockQuotesTests: XCTestCase {
func testExample198() throws {
let markdown = #######"""
> # Foo
> bar
> baz
"""#######
let html = #######"""
<blockquote>
<h1>Foo</h1>
<p>bar
baz</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample199() throws {
let markdown = #######"""
># Foo
>bar
> baz
"""#######
let html = #######"""
<blockquote>
<h1>Foo</h1>
<p>bar
baz</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample200() throws {
let markdown = #######"""
> # Foo
> bar
> baz
"""#######
let html = #######"""
<blockquote>
<h1>Foo</h1>
<p>bar
baz</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample201() throws {
let markdown = #######"""
> # Foo
> bar
> baz
"""#######
let html = #######"""
<pre><code>> # Foo
> bar
> baz
</code></pre>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample202() throws {
let markdown = #######"""
> # Foo
> bar
baz
"""#######
let html = #######"""
<blockquote>
<h1>Foo</h1>
<p>bar
baz</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample203() throws {
let markdown = #######"""
> bar
baz
> foo
"""#######
let html = #######"""
<blockquote>
<p>bar
baz
foo</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample204() throws {
let markdown = #######"""
> foo
---
"""#######
let html = #######"""
<blockquote>
<p>foo</p>
</blockquote>
<hr />
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample205() throws {
let markdown = #######"""
> - foo
- bar
"""#######
let html = #######"""
<blockquote>
<ul>
<li>foo</li>
</ul>
</blockquote>
<ul>
<li>bar</li>
</ul>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample206() throws {
let markdown = #######"""
> foo
bar
"""#######
let html = #######"""
<blockquote>
<pre><code>foo
</code></pre>
</blockquote>
<pre><code>bar
</code></pre>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample207() throws {
let markdown = #######"""
> ```
foo
```
"""#######
let html = #######"""
<blockquote>
<pre><code></code></pre>
</blockquote>
<p>foo</p>
<pre><code></code></pre>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample208() throws {
let markdown = #######"""
> foo
- bar
"""#######
let html = #######"""
<blockquote>
<p>foo
- bar</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample209() throws {
let markdown = #######"""
>
"""#######
let html = #######"""
<blockquote>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample210() throws {
let markdown = #######"""
>
>
>
"""#######
let html = #######"""
<blockquote>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample211() throws {
let markdown = #######"""
>
> foo
>
"""#######
let html = #######"""
<blockquote>
<p>foo</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample212() throws {
let markdown = #######"""
> foo
> bar
"""#######
let html = #######"""
<blockquote>
<p>foo</p>
</blockquote>
<blockquote>
<p>bar</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample213() throws {
let markdown = #######"""
> foo
> bar
"""#######
let html = #######"""
<blockquote>
<p>foo
bar</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample214() throws {
let markdown = #######"""
> foo
>
> bar
"""#######
let html = #######"""
<blockquote>
<p>foo</p>
<p>bar</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample215() throws {
let markdown = #######"""
foo
> bar
"""#######
let html = #######"""
<p>foo</p>
<blockquote>
<p>bar</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample216() throws {
let markdown = #######"""
> aaa
***
> bbb
"""#######
let html = #######"""
<blockquote>
<p>aaa</p>
</blockquote>
<hr />
<blockquote>
<p>bbb</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample217() throws {
let markdown = #######"""
> bar
baz
"""#######
let html = #######"""
<blockquote>
<p>bar
baz</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample218() throws {
let markdown = #######"""
> bar
baz
"""#######
let html = #######"""
<blockquote>
<p>bar</p>
</blockquote>
<p>baz</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample219() throws {
let markdown = #######"""
> bar
>
baz
"""#######
let html = #######"""
<blockquote>
<p>bar</p>
</blockquote>
<p>baz</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample220() throws {
let markdown = #######"""
> > > foo
bar
"""#######
let html = #######"""
<blockquote>
<blockquote>
<blockquote>
<p>foo
bar</p>
</blockquote>
</blockquote>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample221() throws {
let markdown = #######"""
>>> foo
> bar
>>baz
"""#######
let html = #######"""
<blockquote>
<blockquote>
<blockquote>
<p>foo
bar
baz</p>
</blockquote>
</blockquote>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample222() throws {
let markdown = #######"""
> code
> not code
"""#######
let html = #######"""
<blockquote>
<pre><code>code
</code></pre>
</blockquote>
<blockquote>
<p>not code</p>
</blockquote>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
}
================================================
FILE: Tests/CommonMarkSpecTests/CodeSpansTests.swift
================================================
// This file was automatically generated and should not be edited.
import XCTest
import CommonMark
final class CommonMarkSpecCodeSpansTests: XCTestCase {
func testExample328() throws {
let markdown = #######"""
`foo`
"""#######
let html = #######"""
<p><code>foo</code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample329() throws {
let markdown = #######"""
`` foo ` bar ``
"""#######
let html = #######"""
<p><code>foo ` bar</code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample330() throws {
let markdown = #######"""
` `` `
"""#######
let html = #######"""
<p><code>``</code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample331() throws {
let markdown = #######"""
` `` `
"""#######
let html = #######"""
<p><code> `` </code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample332() throws {
let markdown = #######"""
` a`
"""#######
let html = #######"""
<p><code> a</code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample333() throws {
let markdown = #######"""
` b `
"""#######
let html = #######"""
<p><code> b </code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample334() throws {
let markdown = #######"""
` `
` `
"""#######
let html = #######"""
<p><code> </code>
<code> </code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample335() throws {
let markdown = #######"""
``
foo
bar
baz
``
"""#######
let html = #######"""
<p><code>foo bar baz</code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample336() throws {
let markdown = #######"""
``
foo
``
"""#######
let html = #######"""
<p><code>foo </code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample337() throws {
let markdown = #######"""
`foo bar
baz`
"""#######
let html = #######"""
<p><code>foo bar baz</code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample338() throws {
let markdown = #######"""
`foo\`bar`
"""#######
let html = #######"""
<p><code>foo\</code>bar`</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample339() throws {
let markdown = #######"""
``foo`bar``
"""#######
let html = #######"""
<p><code>foo`bar</code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample340() throws {
let markdown = #######"""
` foo `` bar `
"""#######
let html = #######"""
<p><code>foo `` bar</code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample341() throws {
let markdown = #######"""
*foo`*`
"""#######
let html = #######"""
<p>*foo<code>*</code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample342() throws {
let markdown = #######"""
[not a `link](/foo`)
"""#######
let html = #######"""
<p>[not a <code>link](/foo</code>)</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample343() throws {
let markdown = #######"""
`<a href="`">`
"""#######
let html = #######"""
<p><code><a href="</code>">`</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample344() throws {
let markdown = #######"""
<a href="`">`
"""#######
let html = #######"""
<p><a href="`">`</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample345() throws {
let markdown = #######"""
`<http://foo.bar.`baz>`
"""#######
let html = #######"""
<p><code><http://foo.bar.</code>baz>`</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample346() throws {
let markdown = #######"""
<http://foo.bar.`baz>`
"""#######
let html = #######"""
<p><a href="http://foo.bar.%60baz">http://foo.bar.`baz</a>`</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample347() throws {
let markdown = #######"""
```foo``
"""#######
let html = #######"""
<p>```foo``</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample348() throws {
let markdown = #######"""
`foo
"""#######
let html = #######"""
<p>`foo</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample349() throws {
let markdown = #######"""
`foo``bar``
"""#######
let html = #######"""
<p>`foo<code>bar</code></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
}
================================================
FILE: Tests/CommonMarkSpecTests/EmphasisAndStrongEmphasisTests.swift
================================================
// This file was automatically generated and should not be edited.
import XCTest
import CommonMark
final class CommonMarkSpecEmphasisAndStrongEmphasisTests: XCTestCase {
func testExample350() throws {
let markdown = #######"""
*foo bar*
"""#######
let html = #######"""
<p><em>foo bar</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample351() throws {
let markdown = #######"""
a * foo bar*
"""#######
let html = #######"""
<p>a * foo bar*</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample352() throws {
let markdown = #######"""
a*"foo"*
"""#######
let html = #######"""
<p>a*"foo"*</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample353() throws {
let markdown = #######"""
* a *
"""#######
let html = #######"""
<p>* a *</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample354() throws {
let markdown = #######"""
foo*bar*
"""#######
let html = #######"""
<p>foo<em>bar</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample355() throws {
let markdown = #######"""
5*6*78
"""#######
let html = #######"""
<p>5<em>6</em>78</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample356() throws {
let markdown = #######"""
_foo bar_
"""#######
let html = #######"""
<p><em>foo bar</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample357() throws {
let markdown = #######"""
_ foo bar_
"""#######
let html = #######"""
<p>_ foo bar_</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample358() throws {
let markdown = #######"""
a_"foo"_
"""#######
let html = #######"""
<p>a_"foo"_</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample359() throws {
let markdown = #######"""
foo_bar_
"""#######
let html = #######"""
<p>foo_bar_</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample360() throws {
let markdown = #######"""
5_6_78
"""#######
let html = #######"""
<p>5_6_78</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample361() throws {
let markdown = #######"""
пристаням_стремятся_
"""#######
let html = #######"""
<p>пристаням_стремятся_</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample362() throws {
let markdown = #######"""
aa_"bb"_cc
"""#######
let html = #######"""
<p>aa_"bb"_cc</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample363() throws {
let markdown = #######"""
foo-_(bar)_
"""#######
let html = #######"""
<p>foo-<em>(bar)</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample364() throws {
let markdown = #######"""
_foo*
"""#######
let html = #######"""
<p>_foo*</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample365() throws {
let markdown = #######"""
*foo bar *
"""#######
let html = #######"""
<p>*foo bar *</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample366() throws {
let markdown = #######"""
*foo bar
*
"""#######
let html = #######"""
<p>*foo bar
*</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample367() throws {
let markdown = #######"""
*(*foo)
"""#######
let html = #######"""
<p>*(*foo)</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample368() throws {
let markdown = #######"""
*(*foo*)*
"""#######
let html = #######"""
<p><em>(<em>foo</em>)</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample369() throws {
let markdown = #######"""
*foo*bar
"""#######
let html = #######"""
<p><em>foo</em>bar</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample370() throws {
let markdown = #######"""
_foo bar _
"""#######
let html = #######"""
<p>_foo bar _</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample371() throws {
let markdown = #######"""
_(_foo)
"""#######
let html = #######"""
<p>_(_foo)</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample372() throws {
let markdown = #######"""
_(_foo_)_
"""#######
let html = #######"""
<p><em>(<em>foo</em>)</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample373() throws {
let markdown = #######"""
_foo_bar
"""#######
let html = #######"""
<p>_foo_bar</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample374() throws {
let markdown = #######"""
_пристаням_стремятся
"""#######
let html = #######"""
<p>_пристаням_стремятся</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample375() throws {
let markdown = #######"""
_foo_bar_baz_
"""#######
let html = #######"""
<p><em>foo_bar_baz</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample376() throws {
let markdown = #######"""
_(bar)_.
"""#######
let html = #######"""
<p><em>(bar)</em>.</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample377() throws {
let markdown = #######"""
**foo bar**
"""#######
let html = #######"""
<p><strong>foo bar</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample378() throws {
let markdown = #######"""
** foo bar**
"""#######
let html = #######"""
<p>** foo bar**</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample379() throws {
let markdown = #######"""
a**"foo"**
"""#######
let html = #######"""
<p>a**"foo"**</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample380() throws {
let markdown = #######"""
foo**bar**
"""#######
let html = #######"""
<p>foo<strong>bar</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample381() throws {
let markdown = #######"""
__foo bar__
"""#######
let html = #######"""
<p><strong>foo bar</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample382() throws {
let markdown = #######"""
__ foo bar__
"""#######
let html = #######"""
<p>__ foo bar__</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample383() throws {
let markdown = #######"""
__
foo bar__
"""#######
let html = #######"""
<p>__
foo bar__</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample384() throws {
let markdown = #######"""
a__"foo"__
"""#######
let html = #######"""
<p>a__"foo"__</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample385() throws {
let markdown = #######"""
foo__bar__
"""#######
let html = #######"""
<p>foo__bar__</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample386() throws {
let markdown = #######"""
5__6__78
"""#######
let html = #######"""
<p>5__6__78</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample387() throws {
let markdown = #######"""
пристаням__стремятся__
"""#######
let html = #######"""
<p>пристаням__стремятся__</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample388() throws {
let markdown = #######"""
__foo, __bar__, baz__
"""#######
let html = #######"""
<p><strong>foo, <strong>bar</strong>, baz</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample389() throws {
let markdown = #######"""
foo-__(bar)__
"""#######
let html = #######"""
<p>foo-<strong>(bar)</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample390() throws {
let markdown = #######"""
**foo bar **
"""#######
let html = #######"""
<p>**foo bar **</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample391() throws {
let markdown = #######"""
**(**foo)
"""#######
let html = #######"""
<p>**(**foo)</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample392() throws {
let markdown = #######"""
*(**foo**)*
"""#######
let html = #######"""
<p><em>(<strong>foo</strong>)</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample393() throws {
let markdown = #######"""
**Gomphocarpus (*Gomphocarpus physocarpus*, syn.
*Asclepias physocarpa*)**
"""#######
let html = #######"""
<p><strong>Gomphocarpus (<em>Gomphocarpus physocarpus</em>, syn.
<em>Asclepias physocarpa</em>)</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample394() throws {
let markdown = #######"""
**foo "*bar*" foo**
"""#######
let html = #######"""
<p><strong>foo "<em>bar</em>" foo</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample395() throws {
let markdown = #######"""
**foo**bar
"""#######
let html = #######"""
<p><strong>foo</strong>bar</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample396() throws {
let markdown = #######"""
__foo bar __
"""#######
let html = #######"""
<p>__foo bar __</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample397() throws {
let markdown = #######"""
__(__foo)
"""#######
let html = #######"""
<p>__(__foo)</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample398() throws {
let markdown = #######"""
_(__foo__)_
"""#######
let html = #######"""
<p><em>(<strong>foo</strong>)</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample399() throws {
let markdown = #######"""
__foo__bar
"""#######
let html = #######"""
<p>__foo__bar</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample400() throws {
let markdown = #######"""
__пристаням__стремятся
"""#######
let html = #######"""
<p>__пристаням__стремятся</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample401() throws {
let markdown = #######"""
__foo__bar__baz__
"""#######
let html = #######"""
<p><strong>foo__bar__baz</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample402() throws {
let markdown = #######"""
__(bar)__.
"""#######
let html = #######"""
<p><strong>(bar)</strong>.</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample403() throws {
let markdown = #######"""
*foo [bar](/url)*
"""#######
let html = #######"""
<p><em>foo <a href="/url">bar</a></em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample404() throws {
let markdown = #######"""
*foo
bar*
"""#######
let html = #######"""
<p><em>foo
bar</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample405() throws {
let markdown = #######"""
_foo __bar__ baz_
"""#######
let html = #######"""
<p><em>foo <strong>bar</strong> baz</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample406() throws {
let markdown = #######"""
_foo _bar_ baz_
"""#######
let html = #######"""
<p><em>foo <em>bar</em> baz</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample407() throws {
let markdown = #######"""
__foo_ bar_
"""#######
let html = #######"""
<p><em><em>foo</em> bar</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample408() throws {
let markdown = #######"""
*foo *bar**
"""#######
let html = #######"""
<p><em>foo <em>bar</em></em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample409() throws {
let markdown = #######"""
*foo **bar** baz*
"""#######
let html = #######"""
<p><em>foo <strong>bar</strong> baz</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample410() throws {
let markdown = #######"""
*foo**bar**baz*
"""#######
let html = #######"""
<p><em>foo<strong>bar</strong>baz</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample411() throws {
let markdown = #######"""
*foo**bar*
"""#######
let html = #######"""
<p><em>foo**bar</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample412() throws {
let markdown = #######"""
***foo** bar*
"""#######
let html = #######"""
<p><em><strong>foo</strong> bar</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample413() throws {
let markdown = #######"""
*foo **bar***
"""#######
let html = #######"""
<p><em>foo <strong>bar</strong></em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample414() throws {
let markdown = #######"""
*foo**bar***
"""#######
let html = #######"""
<p><em>foo<strong>bar</strong></em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample415() throws {
let markdown = #######"""
foo***bar***baz
"""#######
let html = #######"""
<p>foo<em><strong>bar</strong></em>baz</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample416() throws {
let markdown = #######"""
foo******bar*********baz
"""#######
let html = #######"""
<p>foo<strong><strong><strong>bar</strong></strong></strong>***baz</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample417() throws {
let markdown = #######"""
*foo **bar *baz* bim** bop*
"""#######
let html = #######"""
<p><em>foo <strong>bar <em>baz</em> bim</strong> bop</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample418() throws {
let markdown = #######"""
*foo [*bar*](/url)*
"""#######
let html = #######"""
<p><em>foo <a href="/url"><em>bar</em></a></em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample419() throws {
let markdown = #######"""
** is not an empty emphasis
"""#######
let html = #######"""
<p>** is not an empty emphasis</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample420() throws {
let markdown = #######"""
**** is not an empty strong emphasis
"""#######
let html = #######"""
<p>**** is not an empty strong emphasis</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample421() throws {
let markdown = #######"""
**foo [bar](/url)**
"""#######
let html = #######"""
<p><strong>foo <a href="/url">bar</a></strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample422() throws {
let markdown = #######"""
**foo
bar**
"""#######
let html = #######"""
<p><strong>foo
bar</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample423() throws {
let markdown = #######"""
__foo _bar_ baz__
"""#######
let html = #######"""
<p><strong>foo <em>bar</em> baz</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample424() throws {
let markdown = #######"""
__foo __bar__ baz__
"""#######
let html = #######"""
<p><strong>foo <strong>bar</strong> baz</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample425() throws {
let markdown = #######"""
____foo__ bar__
"""#######
let html = #######"""
<p><strong><strong>foo</strong> bar</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample426() throws {
let markdown = #######"""
**foo **bar****
"""#######
let html = #######"""
<p><strong>foo <strong>bar</strong></strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample427() throws {
let markdown = #######"""
**foo *bar* baz**
"""#######
let html = #######"""
<p><strong>foo <em>bar</em> baz</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample428() throws {
let markdown = #######"""
**foo*bar*baz**
"""#######
let html = #######"""
<p><strong>foo<em>bar</em>baz</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample429() throws {
let markdown = #######"""
***foo* bar**
"""#######
let html = #######"""
<p><strong><em>foo</em> bar</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample430() throws {
let markdown = #######"""
**foo *bar***
"""#######
let html = #######"""
<p><strong>foo <em>bar</em></strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample431() throws {
let markdown = #######"""
**foo *bar **baz**
bim* bop**
"""#######
let html = #######"""
<p><strong>foo <em>bar <strong>baz</strong>
bim</em> bop</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample432() throws {
let markdown = #######"""
**foo [*bar*](/url)**
"""#######
let html = #######"""
<p><strong>foo <a href="/url"><em>bar</em></a></strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample433() throws {
let markdown = #######"""
__ is not an empty emphasis
"""#######
let html = #######"""
<p>__ is not an empty emphasis</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample434() throws {
let markdown = #######"""
____ is not an empty strong emphasis
"""#######
let html = #######"""
<p>____ is not an empty strong emphasis</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample435() throws {
let markdown = #######"""
foo ***
"""#######
let html = #######"""
<p>foo ***</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample436() throws {
let markdown = #######"""
foo *\**
"""#######
let html = #######"""
<p>foo <em>*</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample437() throws {
let markdown = #######"""
foo *_*
"""#######
let html = #######"""
<p>foo <em>_</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample438() throws {
let markdown = #######"""
foo *****
"""#######
let html = #######"""
<p>foo *****</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample439() throws {
let markdown = #######"""
foo **\***
"""#######
let html = #######"""
<p>foo <strong>*</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample440() throws {
let markdown = #######"""
foo **_**
"""#######
let html = #######"""
<p>foo <strong>_</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample441() throws {
let markdown = #######"""
**foo*
"""#######
let html = #######"""
<p>*<em>foo</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample442() throws {
let markdown = #######"""
*foo**
"""#######
let html = #######"""
<p><em>foo</em>*</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample443() throws {
let markdown = #######"""
***foo**
"""#######
let html = #######"""
<p>*<strong>foo</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample444() throws {
let markdown = #######"""
****foo*
"""#######
let html = #######"""
<p>***<em>foo</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample445() throws {
let markdown = #######"""
**foo***
"""#######
let html = #######"""
<p><strong>foo</strong>*</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample446() throws {
let markdown = #######"""
*foo****
"""#######
let html = #######"""
<p><em>foo</em>***</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample447() throws {
let markdown = #######"""
foo ___
"""#######
let html = #######"""
<p>foo ___</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample448() throws {
let markdown = #######"""
foo _\__
"""#######
let html = #######"""
<p>foo <em>_</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample449() throws {
let markdown = #######"""
foo _*_
"""#######
let html = #######"""
<p>foo <em>*</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample450() throws {
let markdown = #######"""
foo _____
"""#######
let html = #######"""
<p>foo _____</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample451() throws {
let markdown = #######"""
foo __\___
"""#######
let html = #######"""
<p>foo <strong>_</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample452() throws {
let markdown = #######"""
foo __*__
"""#######
let html = #######"""
<p>foo <strong>*</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample453() throws {
let markdown = #######"""
__foo_
"""#######
let html = #######"""
<p>_<em>foo</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample454() throws {
let markdown = #######"""
_foo__
"""#######
let html = #######"""
<p><em>foo</em>_</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample455() throws {
let markdown = #######"""
___foo__
"""#######
let html = #######"""
<p>_<strong>foo</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample456() throws {
let markdown = #######"""
____foo_
"""#######
let html = #######"""
<p>___<em>foo</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample457() throws {
let markdown = #######"""
__foo___
"""#######
let html = #######"""
<p><strong>foo</strong>_</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample458() throws {
let markdown = #######"""
_foo____
"""#######
let html = #######"""
<p><em>foo</em>___</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample459() throws {
let markdown = #######"""
**foo**
"""#######
let html = #######"""
<p><strong>foo</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample460() throws {
let markdown = #######"""
*_foo_*
"""#######
let html = #######"""
<p><em><em>foo</em></em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample461() throws {
let markdown = #######"""
__foo__
"""#######
let html = #######"""
<p><strong>foo</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample462() throws {
let markdown = #######"""
_*foo*_
"""#######
let html = #######"""
<p><em><em>foo</em></em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample463() throws {
let markdown = #######"""
****foo****
"""#######
let html = #######"""
<p><strong><strong>foo</strong></strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample464() throws {
let markdown = #######"""
____foo____
"""#######
let html = #######"""
<p><strong><strong>foo</strong></strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample465() throws {
let markdown = #######"""
******foo******
"""#######
let html = #######"""
<p><strong><strong><strong>foo</strong></strong></strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample466() throws {
let markdown = #######"""
***foo***
"""#######
let html = #######"""
<p><em><strong>foo</strong></em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample467() throws {
let markdown = #######"""
_____foo_____
"""#######
let html = #######"""
<p><em><strong><strong>foo</strong></strong></em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample468() throws {
let markdown = #######"""
*foo _bar* baz_
"""#######
let html = #######"""
<p><em>foo _bar</em> baz_</p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample469() throws {
let markdown = #######"""
*foo __bar *baz bim__ bam*
"""#######
let html = #######"""
<p><em>foo <strong>bar *baz bim</strong> bam</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample470() throws {
let markdown = #######"""
**foo **bar baz**
"""#######
let html = #######"""
<p>**foo <strong>bar baz</strong></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample471() throws {
let markdown = #######"""
*foo *bar baz*
"""#######
let html = #######"""
<p>*foo <em>bar baz</em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample472() throws {
let markdown = #######"""
*[bar*](/url)
"""#######
let html = #######"""
<p>*<a href="/url">bar*</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample473() throws {
let markdown = #######"""
_foo [bar_](/url)
"""#######
let html = #######"""
<p>_foo <a href="/url">bar_</a></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample474() throws {
let markdown = #######"""
*<img src="foo" title="*"/>
"""#######
let html = #######"""
<p>*<img src="foo" title="*"/></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample475() throws {
let markdown = #######"""
**<a href="**">
"""#######
let html = #######"""
<p>**<a href="**"></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample476() throws {
let markdown = #######"""
__<a href="__">
"""#######
let html = #######"""
<p>__<a href="__"></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample477() throws {
let markdown = #######"""
*a `*`*
"""#######
let html = #######"""
<p><em>a <code>*</code></em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected = html
XCTAssertEqual(actual, expected)
}
func testExample478() throws {
let markdown = #######"""
_a `_`_
"""#######
let html = #######"""
<p><em>a <code>_</code></em></p>
"""#######
let document = try Document(markdown)
let actual = document.render(format: .html, options: [.unsafe])
let expected =
gitextract_min7gahu/
├── .github/
│ └── workflows/
│ ├── ci.yml
│ └── documentation.yml
├── .gitignore
├── Changelog.md
├── LICENSE.md
├── Makefile
├── Package.resolved
├── Package.swift
├── README.md
├── Resources/
│ ├── CommonMarkSpecTests.swift.gyb
│ └── camelcase.awk
├── Sources/
│ └── CommonMark/
│ ├── Nodes/
│ │ ├── Block/
│ │ │ ├── BlockQuote.swift
│ │ │ ├── CodeBlock.swift
│ │ │ ├── HTMLBlock.swift
│ │ │ ├── Heading.swift
│ │ │ ├── List.swift
│ │ │ ├── Paragraph.swift
│ │ │ └── ThematicBreak.swift
│ │ ├── Document.swift
│ │ ├── Inline/
│ │ │ ├── Code.swift
│ │ │ ├── Emphasis.swift
│ │ │ ├── HardLineBreak.swift
│ │ │ ├── Image.swift
│ │ │ ├── Link.swift
│ │ │ ├── RawHTML.swift
│ │ │ ├── SoftLineBreak.swift
│ │ │ ├── Strong.swift
│ │ │ └── Text.swift
│ │ └── Node.swift
│ ├── Result Builders/
│ │ ├── ContainerOfBlocksBuilder.swift
│ │ ├── ContainerOfInlineElementsBuilder.swift
│ │ └── ListBuilder.swift
│ ├── Supporting Types/
│ │ ├── Block.swift
│ │ ├── Children.swift
│ │ ├── Fragment.swift
│ │ ├── Inline.swift
│ │ ├── LineBreak.swift
│ │ ├── Linked.swift
│ │ ├── Literal.swift
│ │ ├── Section.swift
│ │ ├── Visitable.swift
│ │ └── Visitor.swift
│ └── Version.swift
└── Tests/
├── CommonMarkSpecTests/
│ ├── AtxHeadingsTests.swift
│ ├── AutolinksTests.swift
│ ├── BackslashEscapesTests.swift
│ ├── BlankLinesTests.swift
│ ├── BlockQuotesTests.swift
│ ├── CodeSpansTests.swift
│ ├── EmphasisAndStrongEmphasisTests.swift
│ ├── EntityAndNumericCharacterReferencesTests.swift
│ ├── FencedCodeBlocksTests.swift
│ ├── HardLineBreaksTests.swift
│ ├── HtmlBlocksTests.swift
│ ├── ImagesTests.swift
│ ├── IndentedCodeBlocksTests.swift
│ ├── InlinesTests.swift
│ ├── LinkReferenceDefinitionsTests.swift
│ ├── LinksTests.swift
│ ├── ListItemsTests.swift
│ ├── ListsTests.swift
│ ├── ParagraphsTests.swift
│ ├── PrecedenceTests.swift
│ ├── RawHtmlTests.swift
│ ├── SetextHeadingsTests.swift
│ ├── SoftLineBreaksTests.swift
│ ├── TabsTests.swift
│ ├── TextualContentTests.swift
│ └── ThematicBreaksTests.swift
├── CommonMarkTests/
│ ├── CommonMarkBuilderTests.swift
│ ├── CommonMarkTests.swift
│ ├── ContainerManipulationTests.swift
│ ├── DocumentTests.swift
│ ├── Fixtures.swift
│ ├── NodeTests.swift
│ ├── ProtocolTests.swift
│ ├── StatisticsVisitor.swift
│ └── VisitorTests.swift
└── LinuxMain.swift
Condensed preview — 79 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (459K chars).
[
{
"path": ".github/workflows/ci.yml",
"chars": 2268,
"preview": "name: CI\n\non:\n push:\n branches: [main]\n pull_request:\n branches: [main]\n\njobs:\n macos:\n runs-on: macos-lates"
},
{
"path": ".github/workflows/documentation.yml",
"chars": 654,
"preview": "name: Documentation\n\non:\n push:\n branches:\n - main\n paths:\n - .github/workflows/documentation.yml\n "
},
{
"path": ".gitignore",
"chars": 78,
"preview": ".DS_Store\n/.build\n/Packages\n/*.xcodeproj\nxcuserdata/\n.swiftpm\nResources/spec*\n"
},
{
"path": "Changelog.md",
"chars": 5087,
"preview": "# Changelog\n\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Change"
},
{
"path": "LICENSE.md",
"chars": 1064,
"preview": "Copyright 2019 Read Evaluate Press, LLC\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of"
},
{
"path": "Makefile",
"chars": 754,
"preview": "COMMONMARK_SPEC_VERSION=0.29\n\nTests/CommonMarkSpecTests: Resources/spec.json | Resources/spec\n\t@mkdir -p $@\n\t@for sectio"
},
{
"path": "Package.resolved",
"chars": 345,
"preview": "{\n \"object\": {\n \"pins\": [\n {\n \"package\": \"cmark\",\n \"repositoryURL\": \"https://github.com/SwiftDocO"
},
{
"path": "Package.swift",
"chars": 1283,
"preview": "// swift-tools-version:5.1\n// The swift-tools-version declares the minimum version of Swift required to build this packa"
},
{
"path": "README.md",
"chars": 4872,
"preview": "# CommonMark\n\n![CI][ci badge]\n[![Documentation][documentation badge]][documentation]\n\nA Swift package for working with ["
},
{
"path": "Resources/CommonMarkSpecTests.swift.gyb",
"chars": 1051,
"preview": "% warning = \"This file was automatically generated and should not be edited.\"\n// ${warning}\n%{\n# encoding=utf8\nimport sy"
},
{
"path": "Resources/camelcase.awk",
"chars": 212,
"preview": "#!/usr/bin/awk -f\n\n{\n text = $0;\n split(text, words, /[^a-zA-Z]+/);\n for (i=1; i<=length(words); i++) {\n "
},
{
"path": "Sources/CommonMark/Nodes/Block/BlockQuote.swift",
"chars": 870,
"preview": "import cmark\n\n/**\n A block quote.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [5.1 Block quot"
},
{
"path": "Sources/CommonMark/Nodes/Block/CodeBlock.swift",
"chars": 1795,
"preview": "import cmark\n\n/**\n A code block.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [4.4 Indented co"
},
{
"path": "Sources/CommonMark/Nodes/Block/HTMLBlock.swift",
"chars": 954,
"preview": "import cmark\n\n/**\n An HTML block.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [4.6 HTML block"
},
{
"path": "Sources/CommonMark/Nodes/Block/Heading.swift",
"chars": 2477,
"preview": "import cmark\n\n/**\n A heading.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [4.2 ATX headings]("
},
{
"path": "Sources/CommonMark/Nodes/Block/List.swift",
"chars": 4836,
"preview": "import cmark\n\n/**\n A list.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [5.3 Lists](https://sp"
},
{
"path": "Sources/CommonMark/Nodes/Block/Paragraph.swift",
"chars": 1529,
"preview": "import cmark\n\n/**\n A paragraph.\n \n From the [CommonMark Spec](https://spec.commonmark.org/0.29/#thematic-breaks):\n\n > ##"
},
{
"path": "Sources/CommonMark/Nodes/Block/ThematicBreak.swift",
"chars": 616,
"preview": "import cmark\n\n/**\n A thematic break.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29/):\n\n > ## [4.1 Themat"
},
{
"path": "Sources/CommonMark/Nodes/Document.swift",
"chars": 2595,
"preview": "import cmark\n\n/// A CommonMark document.\npublic final class Document: Node {\n /// Options for parsing CommonMark text"
},
{
"path": "Sources/CommonMark/Nodes/Inline/Code.swift",
"chars": 595,
"preview": "import cmark\n\n/**\n A code span.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [6.3 Code spans]("
},
{
"path": "Sources/CommonMark/Nodes/Inline/Emphasis.swift",
"chars": 830,
"preview": "import cmark\n\n/**\n An emphasis span.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [6.4 Emphasi"
},
{
"path": "Sources/CommonMark/Nodes/Inline/HardLineBreak.swift",
"chars": 609,
"preview": "import cmark\n\n/**\n A hard line break.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [6.9 Hard l"
},
{
"path": "Sources/CommonMark/Nodes/Inline/Image.swift",
"chars": 437,
"preview": "import cmark\n\n/**\n An image.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [6.6 Images](https:/"
},
{
"path": "Sources/CommonMark/Nodes/Inline/Link.swift",
"chars": 1338,
"preview": "import cmark\n\n/**\n A link.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [6.5 Links](https://sp"
},
{
"path": "Sources/CommonMark/Nodes/Inline/RawHTML.swift",
"chars": 758,
"preview": "import cmark\n\n/**\n Raw HTML.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [6.8 Raw HTML](https"
},
{
"path": "Sources/CommonMark/Nodes/Inline/SoftLineBreak.swift",
"chars": 673,
"preview": "import cmark\n\n/**\n A soft line break.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [6.10 Soft "
},
{
"path": "Sources/CommonMark/Nodes/Inline/Strong.swift",
"chars": 836,
"preview": "import cmark\n\n/**\n A strong emphasis span.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [6.4 E"
},
{
"path": "Sources/CommonMark/Nodes/Inline/Text.swift",
"chars": 622,
"preview": "import cmark\n\n/**\n Textual content.\n\n From the [CommonMark Spec](https://spec.commonmark.org/0.29):\n\n > ## [6.11 Textual"
},
{
"path": "Sources/CommonMark/Nodes/Node.swift",
"chars": 11047,
"preview": "import cmark\n\n/// A CommonMark node.\npublic class Node: Codable {\n class var cmark_node_type: cmark_node_type { retur"
},
{
"path": "Sources/CommonMark/Result Builders/ContainerOfBlocksBuilder.swift",
"chars": 2898,
"preview": "#if swift(>=5.4)\n@resultBuilder\npublic struct ContainerOfBlocksBuilder {\n /// Required by every result builder to bui"
},
{
"path": "Sources/CommonMark/Result Builders/ContainerOfInlineElementsBuilder.swift",
"chars": 2473,
"preview": "#if swift(>=5.4)\n@resultBuilder\npublic struct ContainerOfInlineElementsBuilder {\n /// Required by every result builde"
},
{
"path": "Sources/CommonMark/Result Builders/ListBuilder.swift",
"chars": 3011,
"preview": "#if swift(>=5.4)\n@resultBuilder\npublic struct ListBuilder {\n /// Required by every result builder to build combined r"
},
{
"path": "Sources/CommonMark/Supporting Types/Block.swift",
"chars": 555,
"preview": "import cmark\n\n/// A block structure element.\npublic protocol Block {}\n\n// MARK: -\n\n/// A block that can contain other bl"
},
{
"path": "Sources/CommonMark/Supporting Types/Children.swift",
"chars": 16787,
"preview": "import cmark\n\nstruct Children: Sequence {\n var cmark_node: OpaquePointer\n\n init(of node: Node) {\n cmark_nod"
},
{
"path": "Sources/CommonMark/Supporting Types/Fragment.swift",
"chars": 1075,
"preview": "public struct Fragment {\n public var children: [Block & Node] = []\n\n init(children: [Block & Node]) {\n self"
},
{
"path": "Sources/CommonMark/Supporting Types/Inline.swift",
"chars": 332,
"preview": "/// An inline content element.\npublic protocol Inline {}\n\n// MARK: -\n\nextension Text: Inline {}\nextension Strong: Inline"
},
{
"path": "Sources/CommonMark/Supporting Types/LineBreak.swift",
"chars": 144,
"preview": "/// A line break element.\npublic protocol LineBreak {}\n\n// MARK: -\n\nextension HardLineBreak: LineBreak {}\nextension Soft"
},
{
"path": "Sources/CommonMark/Supporting Types/Linked.swift",
"chars": 544,
"preview": "import cmark\n\npublic protocol Linked: Node {}\nextension Link: Linked {}\nextension Image: Linked {}\n\nextension Linked {\n "
},
{
"path": "Sources/CommonMark/Supporting Types/Literal.swift",
"chars": 580,
"preview": "import cmark\n\n/// An element with literal contents.\npublic protocol Literal: Node {\n init(literal: String?)\n}\n\n// MAR"
},
{
"path": "Sources/CommonMark/Supporting Types/Section.swift",
"chars": 645,
"preview": "public struct Section {\n private var levelAdjustment: Int\n\n public var children: [Block & Node] = []\n\n init(lev"
},
{
"path": "Sources/CommonMark/Supporting Types/Visitable.swift",
"chars": 6660,
"preview": "public protocol Visitable {\n func accept<T: Visitor>(visitor: T)\n}\n\n// MARK: - Document\n\nextension Document: Visitabl"
},
{
"path": "Sources/CommonMark/Supporting Types/Visitor.swift",
"chars": 10249,
"preview": "public enum VisitorContinueKind {\n /// The visitor should visit the descendents of the current node.\n case visitCh"
},
{
"path": "Sources/CommonMark/Version.swift",
"chars": 329,
"preview": "import cmark\n\n/// A version number.\npublic typealias Version = (major: Int, minor: Int, patch: Int)\n\n/// The version of "
},
{
"path": "Tests/CommonMarkSpecTests/AtxHeadingsTests.swift",
"chars": 7749,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/AutolinksTests.swift",
"chars": 8235,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/BackslashEscapesTests.swift",
"chars": 6048,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/BlankLinesTests.swift",
"chars": 622,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/BlockQuotesTests.swift",
"chars": 11965,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/CodeSpansTests.swift",
"chars": 8943,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/EmphasisAndStrongEmphasisTests.swift",
"chars": 52607,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/EntityAndNumericCharacterReferencesTests.swift",
"chars": 7504,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/FencedCodeBlocksTests.swift",
"chars": 13094,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/HardLineBreaksTests.swift",
"chars": 6133,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/HtmlBlocksTests.swift",
"chars": 20935,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/ImagesTests.swift",
"chars": 9961,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/IndentedCodeBlocksTests.swift",
"chars": 5798,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/InlinesTests.swift",
"chars": 543,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/LinkReferenceDefinitionsTests.swift",
"chars": 12815,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/LinksTests.swift",
"chars": 38118,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/ListItemsTests.swift",
"chars": 25105,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/ListsTests.swift",
"chars": 14370,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/ParagraphsTests.swift",
"chars": 3535,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/PrecedenceTests.swift",
"chars": 596,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/RawHtmlTests.swift",
"chars": 9058,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/SetextHeadingsTests.swift",
"chars": 11998,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/SoftLineBreaksTests.swift",
"chars": 949,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/TabsTests.swift",
"chars": 4952,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/TextualContentTests.swift",
"chars": 1333,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkSpecTests/ThematicBreaksTests.swift",
"chars": 7951,
"preview": "// This file was automatically generated and should not be edited.\n\nimport XCTest\nimport CommonMark\n\nfinal class CommonM"
},
{
"path": "Tests/CommonMarkTests/CommonMarkBuilderTests.swift",
"chars": 2620,
"preview": "import XCTest\nimport CommonMark\n\n#if swift(>=5.4)\nfinal class CommonMarkBuilderTests: XCTestCase {\n func testCommonMa"
},
{
"path": "Tests/CommonMarkTests/CommonMarkTests.swift",
"chars": 275,
"preview": "import XCTest\nimport CommonMark\n\nfinal class CommonMarkTests: XCTestCase {\n func testCommonMarkVersion() {\n XC"
},
{
"path": "Tests/CommonMarkTests/ContainerManipulationTests.swift",
"chars": 4378,
"preview": "import XCTest\nimport CommonMark\n\nfinal class ContainerManipulationTests: XCTestCase {\n func testContainerOfBlocksMani"
},
{
"path": "Tests/CommonMarkTests/DocumentTests.swift",
"chars": 14688,
"preview": "import XCTest\nimport CommonMark\n\nfinal class DocumentTests: XCTestCase {\n\n // MARK: - Creation\n\n func testDocument"
},
{
"path": "Tests/CommonMarkTests/Fixtures.swift",
"chars": 422,
"preview": "public enum Fixtures {\n public static let udhr: String = #\"\"\"\n # [Universal Declaration of Human Rights][udhr]\n\n "
},
{
"path": "Tests/CommonMarkTests/NodeTests.swift",
"chars": 2144,
"preview": "import XCTest\nimport CommonMark\n\nfinal class NodeTests: XCTestCase {\n\n // MARK: - Equality\n\n func testNodesEqualit"
},
{
"path": "Tests/CommonMarkTests/ProtocolTests.swift",
"chars": 2859,
"preview": "import XCTest\nimport CommonMark\n\n/// Make sure element types do not conform to more protocols than they should.\n///\n/// "
},
{
"path": "Tests/CommonMarkTests/StatisticsVisitor.swift",
"chars": 4119,
"preview": "import CommonMark\n\nstruct DocumentStatistics: Equatable {\n var documents: Int = 0\n \n // Node:\n \n var node"
},
{
"path": "Tests/CommonMarkTests/VisitorTests.swift",
"chars": 4360,
"preview": "import XCTest\nimport CommonMark\n\nfinal class VisitorTests: XCTestCase {\n func testVisitorVisitingChildren() throws {\n"
},
{
"path": "Tests/LinuxMain.swift",
"chars": 60,
"preview": "fatalError(\"Run with `swift test --enable-test-discovery`\")\n"
}
]
About this extraction
This page contains the full source code of the SwiftDocOrg/CommonMark GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 79 files (414.3 KB), approximately 100.6k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.