1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use std::io::{BufWriter, Error, ErrorKind};
use rst_parser::parse;
use rst_renderer::render_html;
pub fn render(s: &str) -> Result<String, Error> {
match parse(s) {
Err(e) => {
eprintln!("err: {}", e);
Err(Error::new(ErrorKind::InvalidInput, e))
},
Ok(doc) => {
let buf = Vec::new();
let mut stream = BufWriter::new(buf);
let standalone = false;
render_html(&doc, &mut stream, standalone)
.map_err(|e| Error::new(ErrorKind::InvalidData, e))?;
let r = stream.into_inner().unwrap();
Ok(String::from_utf8_lossy(&r).into_owned())
},
}
}