diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-05-24 16:00:03 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-06-09 16:52:34 +0200 |
commit | f6fdfabf81f27b7db2244f1f30958db2f9a0e624 (patch) | |
tree | 45fc9a083f8ae3fb64c602df9ea486cb8d39f6dc /libimagentrymarkdown/src | |
parent | c47923b6691e99cfe75b95f55a7b23d0173d77d7 (diff) |
Add impl for to_html()
Diffstat (limited to 'libimagentrymarkdown/src')
-rw-r--r-- | libimagentrymarkdown/src/error.rs | 2 | ||||
-rw-r--r-- | libimagentrymarkdown/src/html.rs | 13 |
2 files changed, 13 insertions, 2 deletions
diff --git a/libimagentrymarkdown/src/error.rs b/libimagentrymarkdown/src/error.rs index 7f956801..f3d81d1e 100644 --- a/libimagentrymarkdown/src/error.rs +++ b/libimagentrymarkdown/src/error.rs @@ -1,6 +1,6 @@ generate_error_module!( generate_error_types!(MarkdownError, MarkdownErrorKind, - MarkdownParsingError => "Markdown parsing error" + MarkdownRenderError => "Markdown render error" ); ); diff --git a/libimagentrymarkdown/src/html.rs b/libimagentrymarkdown/src/html.rs index 4e278fab..b350f34f 100644 --- a/libimagentrymarkdown/src/html.rs +++ b/libimagentrymarkdown/src/html.rs @@ -1,10 +1,21 @@ +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<HTML> { - unimplemented!() + 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 { |