8 releases (5 breaking)

0.6.0 Aug 3, 2023
0.5.1 Jul 5, 2023
0.5.0 May 13, 2023
0.4.0 Oct 3, 2022
0.1.1 Jul 21, 2022

#276 in Parser implementations

Download history 330/week @ 2023-12-22 228/week @ 2023-12-29 447/week @ 2024-01-05 354/week @ 2024-01-12 326/week @ 2024-01-19 284/week @ 2024-01-26 235/week @ 2024-02-02 316/week @ 2024-02-09 311/week @ 2024-02-16 348/week @ 2024-02-23 390/week @ 2024-03-01 378/week @ 2024-03-08 303/week @ 2024-03-15 388/week @ 2024-03-22 414/week @ 2024-03-29 345/week @ 2024-04-05

1,516 downloads per month
Used in 20 crates (11 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

~10MB
~216K SLoC