blob: af1664b44e8a49a11c612014c99b59c367b89acc [file] [log] [blame]
extern crate pulldown_cmark;
use pulldown_cmark::{html, Options, Parser};
fn main() {
let markdown_input: &str = "Hello world, this is a ~~complicated~~ *very simple* example.";
println!("Parsing the following markdown string:\n{}", markdown_input);
// Set up options and parser. Strikethroughs are not part of the CommonMark standard
// and we therefore must enable it explicitly.
let mut options = Options::empty();
options.insert(Options::ENABLE_STRIKETHROUGH);
let parser = Parser::new_ext(markdown_input, options);
// Write to String buffer.
let mut html_output: String = String::with_capacity(markdown_input.len() * 3 / 2);
html::push_html(&mut html_output, parser);
// Check that the output is what we expected.
let expected_html: &str =
"<p>Hello world, this is a <del>complicated</del> <em>very simple</em> example.</p>\n";
assert_eq!(expected_html, &html_output);
// Write result to stdout.
println!("\nHTML output:\n{}", &html_output);
}