Easily render HTML from standard Markdown content.
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>
This implementation is built entirely on top of the amazing cmark-gfm which itself is a fork of the excellent cmark.
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>"
Complete documentation ins DocC format can be found attached to each corresponding release. For instance here.
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"])
]
…
)
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.