Giter Club home page Giter Club logo

efmarkdown's Introduction

EFMarkdown is a lightweight Markdown library in Swift, based on EFCMark, inspired by markdown and Markoff.

中文介绍

Overview

sample1 sample2 sample3 sample4

Example

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:

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

For more information on the available options, see cmark.

Author

EyreFree, [email protected]

License

EFMarkdown is available under the WTFPL license. See the LICENSE file for more info.

efmarkdown's People

Contributors

eyrefree avatar abnerchen028 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.