You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 23, 2019. It is now read-only.
To run the example project, clone the repo, and run pod install from the Example directory first.
Requirements
Version
Needs
0.x
XCode 8.0+ Swift 3.0+ iOS 8.0+
4.x
XCode 9.0+ Swift 4.0+ iOS 8.0+
5.x
XCode 10.2+ Swift 5.0+ iOS 8.0+
Installation
EFMarkdown is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod"EFMarkdown"
Usage
1. Markdown to HTML
You can use EFMarkdown to make Markdown string to HTML string easily:
letmarkdown="# Hello"varhtml=""do{
html =tryEFMarkdown().markdownToHTML(markdown, options:EFMarkdownOptions.safe)print(html) // This will return "<h1>Hello</h1>\n"
}catchlet error as NSError{print("Error: \(error.domain)")}
2. View Markdown
You can use EFMarkdownView to make a preview of Markdown:
letscreenSize=UIScreen.main.bounds
letmarkView=EFMarkdownView()
markView.frame =CGRect(x:0, y:20, width: screenSize.width, height: screenSize.height -20)
markView.onRendered ={[weak self](height)iniflet _ =self{
// Optional: you can know the change of height in this block
print("onRendered height: \(height ??0)")}}self.view.addSubview(markView)
markView.load(markdown:testMarkdownFileContent(), options:[.default]){[weak self](_, _)iniflet _ =self{
// Optional: you can change font-size with a value of percent here
markView.setFontSize(percent:128)printLog("load finish!")}}
3. Options
You can pass different options to the underlying cmark library. By default safe is passed.
The available options are:
default
sourcePos
hardBreaks
safe
noBreaks
validateUTF8
smart
githubPreLang
liberalHtmlTag
For more information on the available options, see cmark.