leandrocp

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:

Extensible

A Req-like API to manipulate documents in a pipeline with support for plugins, for eg mdex_mermaid

Features

More at GitHub - leandrocp/mdex: Markdown for Elixir. Fast, Extensible, Phoenix-native. AI-ready. Built on top of comrak, ammonia, and lumis. · GitHub

First Post!

Eiji

Eiji

Very interesting package with lots of features that took my attention! Here are just a few questions/suggestions:

  1. It would be nice to see a comparison table with existing solutions like Earmark - short summary side-by-side sometimes does more than thousands of words

  2. Would it be hard to add support for a custom markdown rules or even custom sets of rules (other markdown syntax - if any)? For example see how many interesting features adds ex_doc to the markdown. It’s import to answer if using your library developer could do the same thing. Would it be harder or simpler?

  3. Would it be hard to add support for Earmark (and other packages)? Imagine a case where there is a critical bug in the Rust parser - for Elixir app it means stopping entire app.

If people would prefer your solution then sooner or later they may ask such a questions … Maybe this is not the same kind of feedback you are interested, but since writing parser is not trivial and especially because Earmark is in the ecosystem for a many, many years people working in production may ask you such type of questions.

Instead of forcing something new (i.e. something unknown) it’s always better to provide something that can fallback in the worst case. This often helps in migrating a big part of a project.

Most Liked

leandrocp

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

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;\">-&gt;</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;\">&lbrace;</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;\">&rbrace;</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.

12
Post #9
leandrocp

leandrocp

MDEx v0.11 is out with 2 new cool features:

  1. 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

  1. 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

Last Post!

leandrocp

leandrocp

Forgot the release link and the Livebook example :slight_smile:

Where Next?

Popular in Announcing Top

zorbash
I created Kitto a framework for dashboards inspired by Dashing. The distributed characteristics of Elixir and the low memory footprint...
New
tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
kelvinst
Hey everyone! Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New
oltarasenko
Dear Elixir community, After a year of development, bug fixes, and improvements, we are proudly ready to share the release of Crawly 0.1...
New
type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
Flo0807
Hello everyone! I am excited to share our heart project Backpex with you. After building several Phoenix applications, we realized that...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement