CommonMark and GitHub Flavored Markdown for Markup,
parsed and rendered by comrak through
mdex_native. The document API, plugins, HEEx,
the sigil and streaming come from markup (see its docs).
| markup_markdown | mdex_native | comrak |
|---|---|---|
| 0.1.x | 0.3.6 | 1.3.0 |
comrak comes in through mdex_native ({:mdex_native, "~> 0.3.6"} in mix.exs), so
the comrak version is whatever that mdex_native release bundles.
Installation
def deps do
[
{:markup, "~> 0.1.0"},
{:markup_markdown, "~> 0.1.0"}
]
endThe language id is :markdown. It renders to :html, :xml (CommonMark XML) and
:markdown (CommonMark).
Markup.to_html!("# Hello", language: :markdown)
#=> "<h1>Hello</h1>\n"
doc = Markup.parse_document!("# Hello *world*", language: :markdown, extension: [strikethrough: true])
Markup.convert!(doc, :markdown)
Markup.convert!(doc, :xml)Options
:extension, :parse and :render are comrak's options, with the same names and
defaults as MDEx. :syntax_highlight and :budget go
straight to mdex_native. sanitize: [] uses MDEx's allowlists
(Markup.Markdown.default_sanitize_options/0). See Markup.Markdown for the full
list.
Nodes
There's one Markup.Markdown.* struct for each MDExNative.Comrak.* struct, with the
same fields, so MDEx plugins port over mostly unchanged. Note the comrak names, like
Emph and LineBreak; kind selectors such as :emphasis and :hard_break find them
anyway.
Syntax highlighting
The highlighter is compiled into mdex_native, so you choose it in config:
# config/config.exs
config :mdex_native, syntax_highlighter: :lumis # or :syntectThen turn it on per render:
Markup.to_html!(markdown, language: :markdown, syntax_highlight: [engine: :lumis])
Markup.to_html!(markdown, language: :markdown, syntax_highlight: [engine: :syntect, opts: [theme: "InspiredGitHub"]])Lumis also needs a parser package for each language you highlight, such as
{:lumis_wasm_elixir, "~> 0.26"}. Without the config, highlighting returns
{:error, %MDExNative.SyntaxHighlightError{}}. Code block decorators (theme,
highlight_lines and the like) aren't supported here; that's a djot and carve thing.
HEEx
HEEx rendering turns on comrak's phoenix_heex extension and render: [unsafe: true]
for you.
Credits
Option schemas and the comrak node converter are ported from MDEx by Leandro Pereira (MIT).
License
MIT