use hoedown::{Markdown, Html as MdHtml}; use hoedown::renderer::html::Flags as HtmlFlags; use hoedown::renderer::Render; use result::Result; use error::MarkdownErrorKind; use libimagerror::into::IntoError; pub type HTML = String; pub fn to_html(buffer: &str) -> Result { let md = Markdown::new(buffer); let mut html = MdHtml::new(HtmlFlags::empty(), 0); html.render(&md) .to_str() .map(String::from) .map_err(Box::new) .map_err(|e| MarkdownErrorKind::MarkdownRenderError.into_error_with_cause(e)) } pub mod iter { use result::Result; use libimagstore::store::Entry; use super::HTML; use super::to_html; pub struct ToHtmlIterator> { i: I } impl> ToHtmlIterator { fn new(i: I) -> ToHtmlIterator { ToHtmlIterator { i: i } } } impl> Iterator for ToHtmlIterator { type Item = Result; fn next(&mut self) -> Option { self.i.next().map(|entry| to_html(&entry.get_content()[..])) } } impl> From for ToHtmlIterator { fn from(obj: I) -> ToHtmlIterator { ToHtmlIterator::new(obj) } } /// Iterate over `(Entry, Result)` tuples pub struct WithHtmlIterator> { i: I } impl> WithHtmlIterator { fn new(i: I) -> WithHtmlIterator { WithHtmlIterator { i: i } } } impl> Iterator for WithHtmlIterator { type Item = (Entry, Result); fn next(&mut self) -> Option { self.i.next().map(|entry| { let html = to_html(&entry.get_content()[..]); (entry, html) }) } } }