All Projects → SwiftDocOrg → Commonmark

SwiftDocOrg / Commonmark

Licence: mit
Create, parse, and render Markdown text according to the CommonMark specification

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Commonmark

Down
Blazing fast Markdown / CommonMark rendering in Swift, built upon cmark.
Stars: ✭ 1,895 (+1189.12%)
Mutual labels:  markdown, commonmark
Marko
A markdown parser with high extensibility.
Stars: ✭ 77 (-47.62%)
Mutual labels:  markdown, commonmark
Qlcommonmark
QuickLook generator for beautifully rendering CommonMark documents on macOS
Stars: ✭ 36 (-75.51%)
Mutual labels:  markdown, commonmark
Mdme
Self-rendering Markdown content
Stars: ✭ 140 (-4.76%)
Mutual labels:  markdown, commonmark
Flexmark Java
CommonMark/Markdown Java parser with source level AST. CommonMark 0.28, emulation of: pegdown, kramdown, markdown.pl, MultiMarkdown. With HTML to MD, MD to PDF, MD to DOCX conversion modules.
Stars: ✭ 1,673 (+1038.1%)
Mutual labels:  markdown, commonmark
Micromark
the smallest commonmark compliant markdown parser that exists; new basis for @unifiedjs (hundreds of projects w/ billions of downloads for dealing w/ content)
Stars: ✭ 793 (+439.46%)
Mutual labels:  markdown, commonmark
Markd
Yet another markdown parser, Compliant to CommonMark specification, written in Crystal.
Stars: ✭ 73 (-50.34%)
Mutual labels:  markdown, commonmark
Turndown
🛏 An HTML to Markdown converter written in JavaScript
Stars: ✭ 5,991 (+3975.51%)
Mutual labels:  markdown, commonmark
Goldmark
🏆 A markdown parser written in Go. Easy to extend, standard(CommonMark) compliant, well structured.
Stars: ✭ 1,813 (+1133.33%)
Mutual labels:  markdown, commonmark
Elm Markdown
Pure Elm markdown parsing and rendering
Stars: ✭ 96 (-34.69%)
Mutual labels:  markdown, commonmark
Texme
Self-rendering Markdown + LaTeX documents
Stars: ✭ 1,970 (+1240.14%)
Mutual labels:  markdown, commonmark
Editor.md
The open source embeddable online markdown editor (component).
Stars: ✭ 11,741 (+7887.07%)
Mutual labels:  markdown, commonmark
Vditor
♏ 一款浏览器端的 Markdown 编辑器。
Stars: ✭ 1,742 (+1085.03%)
Mutual labels:  markdown, commonmark
React Markdown
Markdown component for React
Stars: ✭ 8,047 (+5374.15%)
Mutual labels:  markdown, commonmark
Marked
A markdown parser and compiler. Built for speed.
Stars: ✭ 26,556 (+17965.31%)
Mutual labels:  markdown, commonmark
Markra
A Markdown-to-JIRA syntax editor.
Stars: ✭ 64 (-56.46%)
Mutual labels:  markdown, commonmark
Awesome Markdown
📝 Delightful Markdown stuff.
Stars: ✭ 451 (+206.8%)
Mutual labels:  markdown, commonmark
Remarkable
Markdown parser, done right. Commonmark support, extensions, syntax plugins, high speed - all in one. Gulp and metalsmith plugins available. Used by Facebook, Docusaurus and many others! Use https://github.com/breakdance/breakdance for HTML-to-markdown conversion. Use https://github.com/jonschlinkert/markdown-toc to generate a table of contents.
Stars: ✭ 5,252 (+3472.79%)
Mutual labels:  markdown, commonmark
Html To Markdown
Convert HTML to Markdown with PHP
Stars: ✭ 1,293 (+779.59%)
Mutual labels:  markdown, commonmark
Commonmark Java
Java library for parsing and rendering CommonMark (Markdown)
Stars: ✭ 1,675 (+1039.46%)
Mutual labels:  markdown, commonmark

CommonMark

CI Documentation

A Swift package for working with CommonMark text. It's built on top of libcmark and fully compliant with the CommonMark Spec.

Usage

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

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

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 Function Builders

To use this interface, add "CommonMarkBuilder" to your package's dependencies and replace import CommonMark with import CommonMarkBuilder as needed.

import CommonMarkBuilder

let document = Document {
    Heading {
        Link(urlString: "https://www.un.org/en/universal-declaration-human-rights/" as String?,
                title: "View full version" as String?) // explicit type annotations to work around apparent compiler bug
        {
            "Universal Declaration of Human Rights"
        }
    }

    Section { // sections increase the level of contained headings
        Heading { "Article 1." } // this is a second-level heading
    }

    Fragment { // fragments embed rendered CommonMark text
        """
        **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

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:

$ 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:

import PackageDescription

let package = Package(
  name: "YourProject",
  dependencies: [
    .package(
        url: "https://github.com/SwiftDocOrg/CommonMark",
        from: "0.5.0"
    ),
  ]
)

Then run the swift build command to build your project.

License

MIT

Contact

Mattt (@mattt)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].