View Source MDEx.Sigil (MDEx v0.2.0)

Sigils for parsing and formatting Markdown.

Modifiers

Without a modifier it converts the input (either Markdown or AST) to HTML, equivalent to calling MDEx.to_html!/2.

Note that you should import MDEx.Sigil to use the ~M or ~m sigils.

Options

In order to support the most common scenarios, the sigils have the following options enabled by default:

[extension: [strikethrough: true, table: true, autolink: true, tasklist: true, superscript: true, footnotes: true, description_lists: true, multiline_block_quotes: true, math_dollars: true, math_code: true, shortcodes: true, underline: true, spoiler: true], parse: [smart: true, relaxed_tasklist_matching: true, relaxed_autolinks: true], render: [_unsafe: true, escape: true]]

If you need a different set of options, you can call the regular functions like MDEx.to_html/2 to pass the options you need.

Summary

Functions

The ~M sigil converts between CommonMark, HTML, and AST without interpolation.

The ~m sigil converts between CommonMark, HTML, and AST with interpolation.

Functions

Link to this macro

sigil_M(arg, modifiers)

View Source (macro)

The ~M sigil converts between CommonMark, HTML, and AST without interpolation.

Examples

# markdown to html
iex> ~M|# Hello|
"<h1>Hello</h1>

"

# markdown to ast
iex> ~M|# Hello|AST
[{"document", [], [{"heading", [{"level", 1}, {"setext", false}], ["Hello"]}]}]

# ast to markdown
iex> ~M|[{"document", [], [{"heading", [{"level", 1}], ["Hello"]}]}]|MD
"# Hello

"

# ast to html
iex> ~M|[{"document", [], [{"heading", [{"level", 1}], ["Hello"]}]}]|
"<h1>Hello</h1>

"

Link to this macro

sigil_m(arg, modifiers)

View Source (macro)

The ~m sigil converts between CommonMark, HTML, and AST with interpolation.

Examples

iex> lang = "elixir"

# markdown to html
iex> ~m|`lang = #{lang}`|
"<p><code>lang = elixir</code></p>

"

# markdown to ast
iex> ~m|`lang = #{lang}`|AST
[{"document", [], [{"paragraph", [], [{"code", [{"num_backticks", 1}, {"literal", "lang = elixir"}], []}]}]}]

# ast to markdown
iex> ~m|[{"document", [], [{"paragraph", [], [{"code", [{"num_backticks", 1}, {"literal", "lang = #{lang}"}], []}]}]}]|MD
"`lang = elixir`

"

# ast to html
iex> ~m|[{"document", [], [{"paragraph", [], [{"code", [{"num_backticks", 1}, {"literal", "lang = #{lang}"}], []}]}]}]|
"<p><code>lang = elixir</code></p>

"