Markdown

markdown renderer for comrak markdown parser

Installation

If available in Hex, the package can be installed by adding markdown to your list of dependencies in mix.exs:

def deps do
  [
    {:markdown, "~> 0.1.0"}
  ]
end

Usage

# (markdown[, Renderer \\ Markdown.HtmlRenderer][, data \\ %{}])
Markdown.render("# Hello, world")

Custom Renderers

defmodule MyModule.CustomRenderer do
  use Markdown.Renderer

  def block_code(_data, code, lang) do
    "<pre><code class=\"language-#{lang} #{lang}\">#{HtmlEntities.encode(code)}</code></pre>"
  end
end

Overrides

Block

block_code(data, code, lang)
block_quote(data, quote)
block_html(data, raw_html)
footnotes(data, content)
footnote_def(data, content, number)
footnote_ref(data, number)
header(data, text, header_level)
hrule(data)
list(data, contents, list_type, start)
list_item(data, text, list_type)
paragraph(data, text)
table(data, header, body)
table_row(data, content)
table_cell(data, content, alignment, header)

Inline

autolink(data, url, link_type)
codespan(data, code)
double_emphasis(data, text)
emphasis(data, text)
image(data, url, title, alt_text)
linebreak(data)
softbreak(data)
link(data, url, title, content)
raw_html(data, raw_html)
triple_emphasis(data, text)
strikethrough(data, text)
superscript(data, text)
underline(data, text)
highlight(data, text)
quote(data, text)

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/markdown.