]> git.proxmox.com Git - rustc.git/blob - vendor/pulldown-cmark/examples/string-to-string.rs
New upstream version 1.36.0+dfsg1
[rustc.git] / vendor / pulldown-cmark / examples / string-to-string.rs
1 extern crate pulldown_cmark;
2
3 use pulldown_cmark::{Parser, Options, html};
4
5 fn main() {
6 let markdown_input: &str = "Hello world, this is a ~~complicated~~ *very simple* example.";
7 println!("Parsing the following markdown string:\n{}", markdown_input);
8
9 // Set up options and parser. Strikethroughs are not part of the CommonMark standard
10 // and we therefore must enable it explicitly.
11 let mut options = Options::empty();
12 options.insert(Options::ENABLE_STRIKETHROUGH);
13 let parser = Parser::new_ext(markdown_input, options);
14
15 // Write to String buffer.
16 let mut html_output: String = String::with_capacity(markdown_input.len() * 3 / 2);
17 html::push_html(&mut html_output, parser);
18
19 // Check that the output is what we expected.
20 let expected_html: &str = "<p>Hello world, this is a <del>complicated</del> <em>very simple</em> example.</p>\n";
21 assert_eq!(expected_html, &html_output);
22
23 // Write result to stdout.
24 println!("\nHTML output:\n{}", &html_output);
25 }
26