MDEx.Sigil (MDEx v0.7.0)
View SourceSigils for parsing and formatting Markdown between different formats.
Modifiers
HTML
- converts Markdown orMDEx.Document
to HTML, equivalent to callingMDEx.to_html!/2
JSON
- converts Markdown orMDEx.Document
to JSON, equivalent to callingMDEx.to_json!/2
XML
- converts Markdown orMDEx.Document
to XML, equivalent to callingMDEx.to_xml!/2
MD
- convertsMDEx.Document
to Markdown, equivalent to callingMDEx.to_markdown!/2
Defaults to generating a MDEx.Document
when no modifier is provided.
Note that you should import MDEx.Sigil
to use the ~MD
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,
alerts: 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 ~MD
sigil converts a Markdown string or a %MDEx.Document{}
struct to either one of these formats: MDEx.Document
, Markdown (CommonMark), HTML, JSON or XML.
Functions
The ~MD
sigil converts a Markdown string or a %MDEx.Document{}
struct to either one of these formats: MDEx.Document
, Markdown (CommonMark), HTML, JSON or XML.
Assigns
You can define a variable assigns
in the context of the sigil to pass values to the Markdown string, for example:
assigns = %{lang: ":elixir"}
iex> ~MD|`lang = <%= @lang %>`|
%MDEx.Document{nodes: [%MDEx.Paragraph{nodes: [%MDEx.Code{num_backticks: 1, literal: "lang = :elixir"}]}]}
Examples
Markdown to MDEx.Document
No modifier defaults to generating a MDEx.Document
:
iex> ~MD[`lang = :elixir`]
%MDEx.Document{nodes: [%MDEx.Paragraph{nodes: [%MDEx.Code{num_backticks: 1, literal: "lang = :elixir"}]}]}
Markdown to HTML
iex> ~MD[`lang = :elixir`]HTML
"<p><code>lang = :elixir</code></p>\n"
Markdown to JSON
iex> ~MD[`lang = :elixir`]JSON
"{"nodes":[{"nodes":[{"literal":"lang = :elixir","num_backticks":1,"node_type":"MDEx.Code"}],"node_type":"MDEx.Paragraph"}],"node_type":"MDEx.Document"}"
Markdown to XML
iex> ~MD[`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> ~MD|%MDEx.Document{nodes: [%MDEx.Paragraph{nodes: [%MDEx.Code{num_backticks: 1, literal: "lang = :elixir"}]}]}|MD
"`lang = :elixir`"