Markdown Elixir Native.
Used by:
It uses the following Rust crates:
comrakfor Markdown parsing and renderingammoniafor HTML sanitizationlumisorsyntect/two-facefor syntax highlighting
Most applications should use MDEx directly to benefit from plugins, Document AST, Phoenix LiveView integration, streaming, additional syntax highlighting features, extra formats, MD sigil, and more.
But this project offers direct access to underlying Rust crates when you don't need all those features, or need a bit more performance, or less dependencies.
Add :mdex_native to your dependencies:
def deps do
[
{:mdex_native, "~> 0.1"}
]
endSee all examples.
Guides:
export MDEX_NATIVE_BUILD=1
mix setup
mix testPrecompiled NIFs are downloaded from GitHub network by default, but you can opt-in to download from CloudFlare:
config :mdex_native, artifact_source: :cloudflareSince version v0.2.3 and valid values are :github and :cloudflare.
Defaults to :github.
Markdown parsing and rendering.
html = MDExNative.Comrak.markdown_to_html("# Hello")Comrak options are accepted as keyword lists. See comrak::Options. MDExNative also accepts :sanitize and :syntax_highlight.
html = MDExNative.Comrak.markdown_to_html("- [x] done", extension: [tasklist: true])It also exposes XML, CommonMark, AST parsing, and heading anchor helpers. See the moduledoc.
HTML sanitization.
html = ~s|<script>alert("xss")</script><p>Hello <strong>MDEx</strong></p>|
MDExNative.Ammonia.safe_html(html)
#=> "<p>Hello <strong>MDEx</strong></p>"