Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SwiftDocOrg/CommonMark
Create, parse, and render Markdown text according to the CommonMark specification
https://github.com/SwiftDocOrg/CommonMark
cmark commonmark markdown swift
Last synced: 3 months ago
JSON representation
Create, parse, and render Markdown text according to the CommonMark specification
- Host: GitHub
- URL: https://github.com/SwiftDocOrg/CommonMark
- Owner: SwiftDocOrg
- License: mit
- Archived: true
- Created: 2020-01-21T18:10:39.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-05T13:56:20.000Z (over 3 years ago)
- Last Synced: 2024-07-05T13:46:15.282Z (4 months ago)
- Topics: cmark, commonmark, markdown, swift
- Language: Swift
- Homepage:
- Size: 227 KB
- Stars: 179
- Watchers: 5
- Forks: 12
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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 CommonMarklet 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 // 3let heading = document.children[0] as! Heading
heading.headerLevel // 1
heading.children.count // 1let 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 // 1let 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) //[ ... ]
let xml = document.render(format: .xml) //