Supporting Markdown #1
diegolavalledev
announced in
Posts
Replies: 1 comment 1 reply
-
|
That's fantastic. Apple themselves have praised the GFM library 💪 Have you checked their new Swift Markdown repo?? 😅 Looks about the same although I'm not sure whether it uses GFM under the hood or if it supports Linux 🤷♂️ Cheers! 👋 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Originally published on diegolavalle.com.
One of the first challenges one encounters when building a static site generator is Markdown support.
I knew Apple had just announced during WWDC21 support for Markdown in attributed strings and other APIs but offered no interface for directly converting Markdown to HTML.
A bit of digging in the developer forums led me to this answer by an Apple engineer. Now I knew for a fact that internally they were using the fantastic cmark-gfm library.
cmark-gfmitself is a fork of the cmark C library. GFM stands for GitHub Flavor Markdown and consists of a set of extensions to the CommonMark specification.Having some experience in integrating C code into Swift applications I started adapting
cmark-gfmfor my purposes. The endeavor involved cross-compiling for the relevant architectures and linking to a custom Objective-C framework.Since
cmark-gfmlacked a simplified interface for straightforwardly converting GFM to HTML – which the originalcmarkhad – I decided to write my own Swift protocol around it. I decided to expose all the options and extensions available from the underlying libraries.While the whole effort was open-source I decided to publish the final result as a binary XCFramework. This makes it really easy to include – via Swift Package Manager (SPM) – in SwiftySites or any other project that needs it without the hassle of having to build everything from C sources.
Beta Was this translation helpful? Give feedback.
All reactions