Packages
mdex
0.1.9
0.13.3
0.13.2
0.13.1
0.13.0
0.12.5
retired
0.12.4
0.12.3
0.12.2
0.12.1
0.12.0
0.11.7
0.11.6
0.11.5
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.0
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.2
0.6.1
0.6.0
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.3
0.3.2
0.3.1
0.3.0
0.2.0
0.1.18
0.1.17
0.1.16
0.1.15
0.1.14
0.1.13
0.1.12
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Fast and extensible Markdown for Elixir
Current section
Files
Jump to
Current section
Files
README.md
# MDEx[](https://hexdocs.pm/mdex)[](https://hex.pm/packages/mdex)<!-- MDOC --><img src="assets/images/mdex_logo.png" width="512" alt="MDEx logo">**A fast 100% CommonMark-compatible GitHub Flavored Markdown parser and formatter for Elixir**.See some samples at https://mdex-c31.pages.devUse Rust's [comrak crate](https://crates.io/crates/comrak) under the hood.## InstallationAdd `:mdex` dependecy:```elixirdef deps do [ {:mdex, "~> 0.1"} ]end```## Usage```elixirMix.install([{:mdex, "~> 0.1"}])``````elixirMDEx.to_html("# Hello")#=> "<h1>Hello</h1>\n"``````elixirMDEx.to_html(~S"""# MDExSome benefits you'll find:- Fast- CommonMark spec- Binary is precompiled, no need to compile anything""") |> IO.puts()#=>#=> <h1>MDEx</h1>#=> <p>Some benefits you'll find:</p>#=> <ul>#=> <li>Fast</li>#=> <li>CommonMark spec</li>#=> <li>Binary is precompiled, no need to compile anything</li>#=> <li>Easier to work with since it's Rust</li>#=> </ul>``````elixirMDEx.to_html(~S"""# And more...* Code syntax highlight is also available:\`\`\`elixirString.upcase("elixir")\`\`\`""") |> IO.puts()#=> <h1>And more...</h1>#=> <ul>#=> <li>Code syntax highlight is also available:</li>#=> </ul>#=> <pre class="autumn highlight" style="background-color: #282C34;">#=> <code class="language-elixir">#=> <span class="namespace" style="color: #61AFEF;">String</span><span class="operator" style="color: #C678DD;">.</span><span class="function" style="color: #61AFEF;">upcase</span><span class="" style="color: #ABB2BF;">(</span><span class="string" style="color: #98C379;">"elixir"</span><span class="" style="color: #ABB2BF;">)</span>#=> </code></pre>```## Demo and SamplesA [livebook](https://github.com/leandrocp/mdex/blob/main/playground.livemd) and a [script](https://github.com/leandrocp/mdex/blob/main/playground.exs) are available to demo and experiment,or you can check out all [available samples](https://github.com/leandrocp/mdex/tree/main/priv/generated/samples) at https://mdex-c31.pages.dev## BenchmarkA [simple script](benchmark.exs) is available to compare existing libs:```Name ips average deviation median 99th %cmark 24.01 K 0.0417 ms ±14.11% 0.0405 ms 0.0631 msmdex 16.37 K 0.0611 ms ±9.65% 0.0601 ms 0.0870 msmd 0.85 K 1.18 ms ±4.72% 1.16 ms 1.36 msearmark 0.47 K 2.14 ms ±2.82% 2.13 ms 2.42 msComparison:cmark 24.01 Kmdex 16.37 K - 1.47x slower +0.0194 msmd 0.85 K - 28.36x slower +1.14 msearmark 0.47 K - 51.47x slower +2.10 ms```## MotivationIf any of the available libraries are working for you, keep using it, if not then keep reading.* `earmark` [can't parse](https://github.com/RobertDober/earmark_parser/issues/126) all kinds of documents and is slow to convert hundreds of markdowns.* `md` is fast and extensible but the doc says "If one needs to perfectly parse the common markdown, Md is probably not the correct choice" so it also fails to parse many documents.* `markdown` is not precompiled and has not received updates in a while.* `cmark` is a fast CommonMark parser but it requires compiling the C library and it's harder to extend (unless you're confortable with C).So given those trade-offs, mdex brings some benefits over the alternatives:- Fast- CommonMark spec- Binary is precompiled, no need to compile anything- Easier to work with since it's Rust## Acknowledgements* [Logo](https://www.flaticon.com/free-icons/rpg) created by by Freepik - Flaticon* [Logo font](https://github.com/quoteunquoteapps/CourierPrime) designed by [Alan Greene](https://github.com/a-dg)