Blazing fast Markdown (GitHub-flavored) rendering in Swift, built upon Apple's Swift Markdown.
Note! This is a fork of the excellent Down library by Rob Phillips and John Nguyen.
The main purpose of this fork is to make the markdown parser and renderer that as needed for the Spud Lemmy client that I am developing (on and off). If you also find this useful, let me know!
Based on Down library (https://github.com/johnxnguyen/Down) maitained by John Nguyen and others:
- John Nguyen
- Rob Phillips
- Keaton Burleson
- phoney
- Tony Arnold
- Ken Harris
- Chris Zielinski
- Other contributors 🙌
Note: Swift support is summarized in the table below.
Swift Version | Tag |
---|---|
Swift 5.1 | >= 0.9.0 |
Install using Swift Package Manager:
To add Down to your project, select File → Add Package Dependency
and enter the GitHub URL for Down.
See Adding Package Dependencies to Your App for detailed instructions.
- Clone this repository
- Drag and drop the Down project into your workspace file, adding the framework in the embedded framework section
- Build and run your app
- ?
- Profit
- NSAttributedString
The Down
struct has everything you need if you just want out-of-the-box setup for parsing and conversion.
import Down
import Markdown
// Parse the markdown string into AST
let document = Document(parsing: markdownString)
// Convert to an attributed string using default presentation ("styler")
let down = Down(document: document).toAttributedString(DownStyler())
// Get NSAttributedString representation of the markdown content.
let attributedString = try? down.toAttributedString()
// Display the rendered markdown content in UITextView
let downView = UITextView()
downView.attributedText = attributedString
Swift; iOS 15+, tvOS 15+, macOS 11.00+
Please feel free to fork and create a pull request for bug fixes or improvements, being sure to maintain the general coding style, adding tests, and adding comments as necessary.
Down is built upon the Apple's Swift Mardown library that is powered by GitHub-flavored Markdown's cmark-gfm implementation.
This library is a fork of the excellent Down library by Rob Phillips and John Nguyen.