View Source MDEx.Sigil (MDEx v0.2.0)
Sigils for parsing and formatting Markdown.
Modifiers
AST
- converts Markdown to AST, equivalent to callingMDEx.parse_document!/2
MD
- converts AST to Markdown, equivalent to callingMDEx.to_commonmark!/2
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
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>
"
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>
"