leandrocp / mdex

A CommonMark-compliant fast and extensible Markdown parser and formatter for Elixir.
https://mdex-c31.pages.dev
MIT License
117 stars 9 forks source link

Encode, decode, and manipulate AST #58

Closed leandrocp closed 3 weeks ago

leandrocp commented 3 weeks ago

With this code is now possible to convert markdown to an AST data structure to inspect and manipulate using regular Elixir APIs based on Floki since we're using the exact same format as {node, attrs, children}.

Two examples are available to show how that works:

Mermaid

https://github.com/leandrocp/mdex/blob/lp-encode-decode-ast/examples/mermaid.exs

mermaid

Alerts

https://github.com/leandrocp/mdex/blob/lp-encode-decode-ast/examples/alerts.exs

alerts

Those functions are pretty low-level at the moment but we'll provide a more high-level API to manipulate the AST and also to attach plugins.