Cmark (cmark v0.10.0) View Source

Converts Markdown to supported target formats.

All functions below support the following options:

  • :sourcepos - Include a data-sourcepos attribute on all block elements.
  • :hardbreaks Render softbreak elements as hard line breaks.
  • :nobreaks Render softbreak elements as spaces.
  • :normalize Normalize tree by consolidating adjacent text nodes.
  • :smart Convert straight quotes to curly, --- to em dashes, -- to en dashes.
  • :validate_utf8 Validate UTF-8 in the input before parsing, replacing illegal sequences with the replacement character U+FFFD.
  • :unsafe Allow raw HTML and unsafe links (javascript:, vbscript:, file:, and data:, except for image/png, image/gif, image/jpeg, or image/webp mime types). The default is to treat everything as unsafe, which replaces invalid nodes by a placeholder HTML comment and unsafe links by empty strings.

Link to this section Summary

Types

A list of atoms describing the options to use (see module docs)

Functions

Converts the Markdown document to Commonmark.

Converts the Markdown document to HTML.

Converts the Markdown document to LaTeX.

Converts the Markdown document to Manpage.

Converts the Markdown document to XML.

Link to this section Types

Specs

options_list() :: [
  :sourcepos
  | :hardbreaks
  | :nobreaks
  | :normalize
  | :validate_utf8
  | :smart
  | :unsafe
]

A list of atoms describing the options to use (see module docs)

Link to this section Functions

Link to this function

to_commonmark(document, options_list \\ [])

View Source

Specs

to_commonmark(String.t(), options_list()) :: String.t()

Converts the Markdown document to Commonmark.

See Cmark module docs for all options.

Examples

iex> Cmark.to_commonmark("test")
"test\n"
Link to this function

to_html(document, options_list \\ [])

View Source

Specs

to_html(String.t(), options_list()) :: String.t()

Converts the Markdown document to HTML.

See Cmark module docs for all options.

Examples

iex> Cmark.to_html("test")
"<p>test</p>\n"
Link to this function

to_latex(document, options_list \\ [])

View Source

Specs

to_latex(String.t(), options_list()) :: String.t()

Converts the Markdown document to LaTeX.

See Cmark module docs for all options.

Examples

iex> Cmark.to_latex("test")
"test\n"
Link to this function

to_man(document, options_list \\ [])

View Source

Specs

to_man(String.t(), options_list()) :: String.t()

Converts the Markdown document to Manpage.

See Cmark module docs for all options.

Examples

iex> Cmark.to_man("test")
".PP\ntest\n"
Link to this function

to_xml(document, options_list \\ [])

View Source

Specs

to_xml(String.t(), options_list()) :: String.t()

Converts the Markdown document to XML.

See Cmark module docs for all options.

Examples

iex> Cmark.to_xml("test")
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n<document xmlns=\"http://commonmark.org/xml/1.0\">\n  <paragraph>\n    <text xml:space=\"preserve\">test</text>\n  </paragraph>\n</document>\n"