Crate comrak

A 100% CommonMark and GFM compatible Markdown parser.

Source repository and detailed README is at github.com/kivikakk/comrak.

You can use comrak::markdown_to_html directly:

use comrak::{markdown_to_html, Options};
assert_eq!(
    markdown_to_html("Olá, **世界**!", &Options::default()),
    "<p>Olá, <strong>世界</strong>!</p>\n"
);

Or you can parse the input into an AST yourself, manipulate it, and then use your desired formatter:

use comrak::{Arena, parse_document, format_html, Options};
use comrak::nodes::NodeValue;

# fn main() {
let arena = Arena::new();

let root = parse_document(
    &arena,
    "Hello, pretty world!\n\n1. Do you like [pretty](#) paintings?\n2. Or *pretty* music?\n",
    &Options::default());

for node in root.descendants() {
    if let NodeValue::Text(ref mut text) = node.data.borrow_mut().value {
        *text = text.to_mut().replace("pretty", "beautiful").into()
    }
}

let mut html = String::new();
format_html(root, &Options::default(), &mut html).unwrap();

assert_eq!(
    &html,
    "<p>Hello, beautiful world!</p>\n\
     <ol>\n\
     <li>Do you like <a href=\"#\">beautiful</a> paintings?</li>\n\
     <li>Or <em>beautiful</em> music?</li>\n\
     </ol>\n");
# }

Modules

Structs

Functions

Type Aliases

Macros