Function pulldown_cmark::html::write_html
source · [−]pub fn write_html<'a, I, W>(writer: W, iter: I) -> Result<()> where
I: Iterator<Item = Event<'a>>,
W: Write,
Expand description
Iterate over an Iterator
of Event
s, generate HTML for each Event
, and
write it out to a writable stream.
Note: using this function with an unbuffered writer like a file or socket
will result in poor performance. Wrap these in a
BufWriter
to
prevent unnecessary slowdowns.
Examples
use pulldown_cmark::{html, Parser};
use std::io::Cursor;
let markdown_str = r#"
hello
=====
* alpha
* beta
"#;
let mut bytes = Vec::new();
let parser = Parser::new(markdown_str);
html::write_html(Cursor::new(&mut bytes), parser);
assert_eq!(&String::from_utf8_lossy(&bytes)[..], r#"<h1>hello</h1>
<ul>
<li>alpha</li>
<li>beta</li>
</ul>
"#);