Function pulldown_cmark::html::write_html_io

source ·
pub fn write_html_io<'a, I, W>(writer: W, iter: I) -> Result<()>
where I: Iterator<Item = Event<'a>>, W: Write,
Expand description

Iterate over an Iterator of Events, generate HTML for each Event, and write it out to an I/O 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_io(Cursor::new(&mut bytes), parser);

assert_eq!(&String::from_utf8_lossy(&bytes)[..], r#"<h1>hello</h1>
<ul>
<li>alpha</li>
<li>beta</li>
</ul>
"#);