View Source MDEx.Sigil (MDEx v0.3.0)
Sigils for parsing and formatting Markdown between different formats.
Modifiers
HTML
- converts Markdown orMDEx.Document
to HTML, equivalent to callingMDEx.to_html!/2
XML
- converts Markdown orMDEx.Document
to XML, equivalent to callingMDEx.to_xml!/2
MD
- convertsMDEx.Document
to Markdown, equivalent to callingMDEx.to_commonmark!/2
Without a modifier it converts Markdown to MDEx.Document
(the default output of ~m
and ~M
), equivalent to calling MDEx.parse_document!/2
.
Note that you should import MDEx.Sigil
to use the ~m
or ~M
sigil.
Options
In order to support the most common scenarios, all sigils use the following options 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]
]
If you need a different set of options, you can call the regular functions in MDEx
to pass the options you need.
Summary
Functions
The ~M
sigil converts to MDEx.Document
, CommonMark, HTML, or XML without interpolation.
The ~m
sigil converts to MDEx.Document
, CommonMark, HTML, or XML with interpolation.
Functions
The ~M
sigil converts to MDEx.Document
, CommonMark, HTML, or XML without interpolation.
Examples
Markdown to MDEx.Document
iex> ~M[`lang = :elixir`]
%MDEx.Document{nodes: [%MDEx.Paragraph{nodes: [%MDEx.Code{num_backticks: 1, literal: "lang = :elixir"}]}]}
Markdown to HTML
iex> ~M[`lang = :elixir`]HTML
"<p><code>lang = :elixir</code></p>\n"
Markdown to XML
iex> ~M[`lang = :elixir`]XML
"<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE document SYSTEM "CommonMark.dtd">
<document xmlns="http://commonmark.org/xml/1.0">
<paragraph>
<code xml:space="preserve">lang = :elixir</code>
</paragraph>
</document>
"
MDEx.Document
to Markdown
iex> ~M|%MDEx.Document{nodes: [%MDEx.Paragraph{nodes: [%MDEx.Code{num_backticks: 1, literal: "lang = :elixir"}]}]}|MD
"`lang = :elixir`"
Other modifiers also convert from a document to the desired format.
The ~m
sigil converts to MDEx.Document
, CommonMark, HTML, or XML with interpolation.
Examples
Markdown to MDEx.Document
iex> lang = :elixir
iex> ~m[`lang = #{inspect(lang)}`]
%MDEx.Document{nodes: [%MDEx.Paragraph{nodes: [%MDEx.Code{num_backticks: 1, literal: "lang = :elixir"}]}]}
MDEx.Document
to Markdown
iex> lang = :elixir
iex> ~m|%MDEx.Document{nodes: [%MDEx.Paragraph{nodes: [%MDEx.Code{num_backticks: 1, literal: "lang = #{inspect(lang)}"}]}]}|
"`lang = :elixir`"
Other modifiers also accept interpolation.