MDExNative

Markdown Elixir Native.

Used by:

It uses the following Rust crates:

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.

Installation

Add :mdex_native to your dependencies:

def deps do
[
{:mdex_native, "~> 0.1"}
]
end

Quickstart

See all examples.

Guides:

Development

export MDEX_NATIVE_BUILD=1
mix setup
mix test

Packages

MDExNative.Comrak

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.

MDExNative.Ammonia

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>"