leandrocp
MDEx - Fast and Extensible Markdown
MDEx is a fast and extensible Markdown parser and formatter.
Fast
Leverage Rust to parse, manipulate and render documents using:
- comrak - a Rust port of the official GitHub markdown library compliant with the CommonMark spec.
- ammonia - HTML sanitization.
- autumnus - syntax highlighter powered by Tree-sitter and Neovim themes.
Extensible
A Req-like API to manipulate documents in a pipeline with support for plugins, for eg mdex_mermaid
Features
- Fast
- Compliant with the CommonMark spec
- Plugins
- Formats:
- Markdown (CommonMark)
- HTML
- JSON
- XML
- Quill Delta
- Floki-like Document AST
- Req-like Document pipeline API
- GitHub Flavored Markdown
- Discord and GitLab Flavored-ish Markdown
- Wiki-style links
- Streaming incomplete fragments
- Emoji shortcodes
- Built-in Syntax Highlighting for code blocks
- Code Block Decorators
- HTML sanitization
- ~MD Sigil for Markdown, HTML, JSON, XML, and Quill Delta
Most Liked
leandrocp
MDEx v0.9 is now available with some new cool features!
Delta format
Thanks to @Jskalc we can now convert Markdown to Delta:
Streaming
Initial (experimental) support to put incomplete fragments of Markdown into the document. Useful for AI/LLM tools:
You can see a demo (video) at Leandro Pereira on X: "Here's a short demo of Markdown streaming in MDEx 👀 Note it's still experimental and disabled by default. https://t.co/uEdEEalbb8" / X
Inspect Document as a tree
To help visualize the nodes in a document:
It can be disabled if you prefer the regular struct inspect.
Unified Document API
Removed the MDEx.Pipe module in favor of unifying all operations in the MDEx.Document. Note this is a breaking change:
I’ll be working on Support Phoenix tags? · Issue #571 · kivikakk/comrak · GitHub so we can (hopefully) get Elixir and Phoenix components rendering inside Markdown. Enjoy!
leandrocp
MDEx v0.7.0 is out with a new ~MD sigils supporting assigns and Elixir expressions:
import MDEx.Sigil
assigns = %{lang: "elixir", sample: "spawn(fn -> send(current, {self(), 1 + 2}) end)"}
~MD"""
## Lang: <%= String.capitalize(@lang) %>
```elixir
<%= @sample %>
```
"""
Outputs:
%MDEx.Document{
nodes: [
%MDEx.Heading{nodes: [%MDEx.Text{literal: "Lang: Elixir"}], level: 2, setext: false},
%MDEx.CodeBlock{
nodes: [],
fenced: true,
fence_char: "`",
fence_length: 3,
fence_offset: 0,
info: "elixir",
literal: "spawn(fn -> send(current, {self(), 1 + 2}) end)\n"
}
]
}
Or using the HTML modifier:
"<h2>Lang: Elixir</h2>\n<pre class=\"athl\" style=\"color: #abb2bf; background-color: #282c34;\"><code class=\"language-elixir\" translate=\"no\" tabindex=\"0\"><span class=\"line\" data-line=\"1\"><span style=\"color: #61afef;\">spawn</span><span style=\"color: #848b98;\">(</span><span style=\"color: #c678dd;\">fn</span> <span style=\"color: #abb2bf;\">-></span> <span style=\"color: #61afef;\">send</span><span style=\"color: #848b98;\">(</span><span style=\"color: #abb2bf;\">current</span><span style=\"color: #848b98;\">,</span> <span style=\"color: #848b98;\">{</span><span style=\"color: #61afef;\">self</span><span style=\"color: #848b98;\">(</span><span style=\"color: #848b98;\">)</span><span style=\"color: #848b98;\">,</span> <span style=\"color: #d19a66;\">1</span> <span style=\"color: #abb2bf;\">+</span> <span style=\"color: #d19a66;\">2</span><span style=\"color: #848b98;\">}</span><span style=\"color: #848b98;\">)</span> <span style=\"color: #c678dd;\">end</span><span style=\"color: #848b98;\">)</span>\n</span></code></pre>"
That’s one step into the direction of supporting Markdown in LiveViews with components.
leandrocp
MDEx v0.11 is out with 2 new cool features:
- Initial support for Phoenix Components
Now you can render Phoenix Components inside Markdow, either inside a LiveView or just use the ~MD[...]HEEX sigil. Example:
def render(assigns) do
~MD"""
Hello from MDEx :wave:
Today is _{Calendar.strftime(DateTime.utc_now(), "%B %d, %Y")}_
<ReqEmbed.embed url={@video_url} class="aspect-video rounded-xl my-6" />
Built with:
- <.link href="https://crates.io/crates/comrak">comrak</.link>
- <.link href="https://hex.pm/packages/mdex">MDEx</.link>
"""HEEX
end
More info at Phoenix LiveView HEEx — MDEx v0.13.2
- Syntax Highlighter with Light/Dark themes
The syntax highlighting engine now supports dual/multi themes so you can have automatic light/dark themes:
options = [
syntax_highlight: [
formatter: {
:html_multi_themes,
themes: [light: "github_light", dark: "github_dark"],
default_theme: "light-dark()"
}
]
]
Full example at Lumis light/dark theme — MDEx v0.13.2
I’m also opening a sponsorship program if you want to support MDEx in that way please see GitHub - leandrocp/mdex: Markdown for Elixir. Fast, Extensible, Phoenix-native. AI-ready. Built on top of comrak, ammonia, and lumis. · GitHub
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance












