9 releases (5 breaking)

0.6.1 Jul 7, 2024
0.6.0 Aug 3, 2023
0.5.1 Jul 5, 2023
0.5.0 May 13, 2023
0.1.1 Jul 21, 2022

#262 in Parser implementations

Download history 169/week @ 2024-08-24 214/week @ 2024-08-31 255/week @ 2024-09-07 300/week @ 2024-09-14 290/week @ 2024-09-21 342/week @ 2024-09-28 206/week @ 2024-10-05 206/week @ 2024-10-12 332/week @ 2024-10-19 489/week @ 2024-10-26 441/week @ 2024-11-02 405/week @ 2024-11-09 298/week @ 2024-11-16 323/week @ 2024-11-23 294/week @ 2024-11-30 413/week @ 2024-12-07

1,432 downloads per month
Used in 26 crates (17 directly)

MIT license

270KB
5.5K SLoC

markdown-it

web demo github docs.rs crates.io coverage

Rust port of popular markdown-it.js library.

TL;DR:

  • if you want to get result fast, use pulldown-cmark
  • if you want to render GFM exactly like github, use comrak
  • if you want to define your own syntax (like @mentions, :emoji:, custom html classes), use this library

You can check a demo in your browser (it's Rust compiled into WASM).

Features

  • 100% CommonMark compatibility
  • AST
  • Source maps (full support, not just on block tags like cmark)
  • Ability to write your own syntax of arbitrary complexity
    • to prove this point, CommonMark syntax itself is written as a plugin

Usage

let parser = &mut markdown_it::MarkdownIt::new();
markdown_it::plugins::cmark::add(parser);
markdown_it::plugins::extra::add(parser);

let ast  = parser.parse("Hello **world**!");
let html = ast.render();

print!("{html}");
// prints "<p>Hello <strong>world</strong>!</p>"

For a guide on how to extend it, see examples folder.

Notes

This is an attempt at making a language-agnostic parser. You can probably parse AsciiDoc, reStructuredText or any other plain text format with this without too much effort. I might eventually write these as proof-of-concept.

Dependencies

~7–16MB
~219K SLoC