Markdown pod "EFMarkdown"

https://www.mianshigee.com/project/EyreFree-EFMarkdown/


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:

let markdown = "# Hello"

var html = ""

do {

    html = try EFMarkdown().markdownToHTML(markdown, options: EFMarkdownOptions.safe)

    print(html) // This will return "<h1>Hello</h1>\n"

} catch let error as NSError {

    print ("Error: \(error.domain)")

}


2. View Markdown

You can use EFMarkdownView to make a preview of Markdown:let screenSize = UIScreen.main.bounds

let markView = EFMarkdownView()

markView.frame = CGRect(x: 0, y: 20, width: screenSize.width, height: screenSize.height - 20)

markView.onRendered = {

    [weak self] (height) in

    if let _ = 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] (_, _) in

    if let _ = 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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容