Swiftpack.co - hebertialmeida/MarkdownSyntax as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by hebertialmeida.
hebertialmeida/MarkdownSyntax 1.1.0
☄️ A Type-safe Markdown parser in Swift.
⭐️ 65
🕓 3 days ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/hebertialmeida/MarkdownSyntax.git", from: "1.1.0")

☄️ MarkdownSyntax

codecov

MarkdownSyntax is a wrapper on top of the Github Flavoured Markdown that conforms to mdast. It parses markdown and creates a normalized AST so you can use it not only for rendering markdown and syntax highlighting. In addition, you can render to standard cmark formats HTML, XML, Man, Latex, Plain Text.

Usage

let input = "Hi this is **alpha**"
let tree = try Markdown(text: input).parse()

Outputs a normalized tree:

Root(
    children: [
        Paragraph(
            children: [
                Text(
                    value: "Hi this is ", 
                    position: Position(
                        start: Point(line: 1, column: 1, offset: 0), 
                        end: Point(line: 1, column: 11, offset: 10), 
                        indent: nil
                    )
                ), 
                Strong(
                    children: [
                        Text(
                            value: "alpha", 
                            position: Position(
                                start: Point(line: 1, column: 14, offset: 13), 
                                end: Point(line: 1, column: 18, offset: 17), 
                                indent: nil
                            )
                        )
                    ], 
                    position: Position(
                        start: Point(line: 1, column: 12, offset: 11), 
                        end: Point(line: 1, column: 20, offset: 19), 
                        indent: nil
                    )
                )
            ], 
            position: Position(
                start: Point(line: 1, column: 1, offset: 0), 
                end: Point(line: 1, column: 20, offset: 19), 
                indent: nil
            )
        )
    ], 
    position: Position(
        start: Point(line: 1, column: 1, offset: 0), 
        end: Point(line: 1, column: 20, offset: 19), 
        indent: nil
    )
)

For more examples checkout the tests MarkdownSyntaxTests.

Installation

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding MarkdownSyntax as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/hebertialmeida/MarkdownSyntax", from: "1.1.0")
]

Acknowledgements

GitHub

link
Stars: 65
Last commit: 3 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.1.0
2 years ago
  • Upgraded Swift tools to 5.3
  • Upgraded swift-cmark-gfm dependency

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics