/markdown-provider

Markdown renderer for Vapor

Primary LanguageSwiftMIT LicenseMIT

Markdown Provider

Language Build Status codecov GitHub license

A Markdown renderer for Vapor and Leaf. This uses the Vapor Markdown package to wrap cmark (though a fork is used to make it work with Swift PM), so it understands Common Mark. A quick reference guide for Common Mark can be found here. It also support Github Flavored Markdown

Use

Once set up, you can use it in your Leaf template files like any other tag:

#markdown(myMarkdown)

Where you have passed myMarkdown into the view as something like:

# Hey #

Check out my *awesome* markdown! It is easy to use in `tags`

Setup

Add as dependency

Add Markdown Provider as a dependency in your Package.swift file:

    dependencies: [
        ...,
        .Package(url: "https://github.com/vapor-community/markdown-provider.git", majorVersion: 1)
    ]

Add the Provider

You can add a provider to you Config, which will do all of the setup for you and register your tag. Just add it as so:

let config = try Config()
try config.addProvider(MarkdownProvider.Provider.self)
let drop = try Droplet(config)

Register with Leaf

Alternatively, you can also directly add the Tag onto your LeafRenderer if desired. During your setup (for example, in main.swift), register your tag as so:

if let leaf = drop.view as? LeafRenderer {
    leaf.stem.register(Markdown())
}

Don't forget to import MarkdownProvider in the file you register the tag or add the provider in with import MarkdownProvider