Erlmark (erlmark_ex v0.1.2)

Copy Markdown View Source

Fast Markdown to HTML conversion for Elixir.

A thin wrapper around erlmark, a pure Erlang CommonMark 0.31.2 converter with the GFM tables, strikethrough and task-list extensions. There are no NIFs or system dependencies.

iex> Erlmark.to_html("# Hello *world*")
"<h1>Hello <em>world</em></h1>\n"

Raw HTML in the input is passed through unchanged, as CommonMark requires. Sanitise the output if the input is untrusted.

Summary

Types

An opt-in GFM extension.

A conversion option. See to_html/2.

Functions

Converts Markdown to HTML.

Types

extension()

@type extension() :: :autolink | :tagfilter

An opt-in GFM extension.

option()

@type option() ::
  {:spawn_above, non_neg_integer() | :infinity}
  | {:parallel, false | :auto | pos_integer()}
  | {:extensions, [extension()]}

A conversion option. See to_html/2.

Functions

to_html(markdown, opts \\ [])

@spec to_html(iodata(), [option()]) :: String.t()

Converts Markdown to HTML.

markdown is a string or any iodata. Options:

  • :extensions - a list of opt-in GFM extensions. :autolink turns bare www., http(s):// and ftp:// URLs and e-mail addresses into links. :tagfilter escapes <script>, <style> and similar tags. Conversion with extensions is always sequential. Defaults to [].

  • :parallel - :auto (all online schedulers) or a number of schedulers to convert large documents on. The output is identical to sequential conversion. Documents under 16 KB are never split. Defaults to false.

  • :spawn_above - inputs larger than this many bytes are converted in a short-lived process with a pre-sized heap, which avoids most garbage collection. :infinity always converts in the calling process. Defaults to 256.

Raises ArgumentError for an unknown option or an invalid value.

Examples

iex> Erlmark.to_html("*emphasis* and **strong**")
"<p><em>emphasis</em> and <strong>strong</strong></p>\n"

iex> Erlmark.to_html("visit www.example.com", extensions: [:autolink])
"<p>visit <a href=\"http://www.example.com\">www.example.com</a></p>\n"

iex> Erlmark.to_html("| a |\n|---|\n| 1 |")
"<table>\n<thead>\n<tr>\n<th>a</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>1</td>\n</tr>\n</tbody>\n</table>\n"