Skip to content

CMarkGFM is a small Swift wrapper for the cmark-gfm library written in C.

License

Notifications You must be signed in to change notification settings

swiftysites/cmark-gfm

 
 

Repository files navigation

CMarkGFM

Easily render HTML from standard Markdown content.

Overview

Use this library to generate HTML from a string containing GitHub Flavored Markdown (GFM) / CommonMark content.

For example this code:

# Hello
Hello, _World_!

Will be translated into this code:

<h1>Hello</h1>
<p>Hello, <em>World<em>!</p>

Acknowledgements

This implementation is built entirely on top of the amazing cmark-gfm which itself is a fork of the excellent cmark.

Basic usage

Simply wrap your Markdown string with GFMarkdown and call GFMarkdown/toHTML(options:extensions:) with no parameters.

let html = GFMarkdown("# Hello").toHTML()
print(html) // "<h1>Hello</h1>"

Full documentation

Complete documentation ins DocC format can be found attached to each corresponding release. For instance here.

Configuring your project

Look for the corresponding XCFramework attached to each release and add it as a binary target to your Package.swift. The example below contains the correct URL and checksum for the current branch/release.


let package = Package(
    
    targets: [
        .binaryTarget(
            name: "CMarkGFM",
            url: "https://github.com/swiftysites/cmark-gfm/releases/download/1.0.0/CMarkGFM.xcframework.zip",
            checksum: "a2638dfb0d52990788143e7bbe9fdc4de1eb0153a9830a208d951720d3a4b75f"),
        .target(
            name: "MyApp",
            dependencies: ["CMarkGFM"])
    ]
    
)

Building

If you would like to compile CMarkGFM from scratch you will first need to download and build cmark-gfm as a static library. For more information about how to do this take a look inside build-cmark-gfm.

Copy the .a files to the lib folder and archive the project following the steps in generate-xcframework.

The bundle that is ultimatelly generated gets attached to the GitHub release.

About

CMarkGFM is a small Swift wrapper for the cmark-gfm library written in C.

Resources

License

Stars

Watchers

Forks

Languages

  • C 80.6%
  • Swift 11.9%
  • Shell 6.8%
  • Objective-C 0.7%