Earmark—A Pure Elixir Markdown Processor

Dependency

{ :earmark, "> x.y.z" }

Usage

API

html_doc = Earmark.to_html(markdown)

html_doc = Earmark.to_html(markdown, options)

(See the documentation for to_html for options)

Command line

$ mix escript.build
$ ./earmark file.ms

Supports

Standard Gruber markdown.

Extensions

Tables

Github Flavored Markdown tables are supported

    State | Abbrev | Capital
    ----: | :----: | -------
    Texas | TX     | Austin
    Maine | MN     | Augusta

Tables may have leading and trailing vertical bars on each line

    | State | Abbrev | Capital |
    | ----: | :----: | ------- |
    | Texas | TX     | Austin  |
    | Maine | MN     | Augusta |

Tables need not have headers, in which case all column alignments default to left.

    | Texas | TX     | Austin  |
    | Maine | MN     | Augusta |

Currently we assume there are always spaces around interior vertical bars. It isn't clear what the expectation is.

Adding HTML attributes

HTML attributes can be added to any block-level element. We use the Kramdown syntax: add the line {:attrs} following the block.

attrs can be one or more of:

For example:

    # Warning
    {: .red}

    Do not turn off the engine
    if you are at altitude.
    {: .boxed #warning spellcheck="true"}

Limitations

Author

Copyright © 2014 Dave Thomas, The Pragmatic Programmers
@/+pragdave, dave@pragprog.com

Licensed under the same terms as Elixir.

Details

Given a markdown document (as either a list of lines or a string containing newlines), return an HTML representation.

The options are a %Earmark.Options{} structure:

So, to format the document in original and disable smartypants, you'd call

alias Earmark.Options
result = Earmark.to_html(original, %Options{smartypants: false})