Add impl for to_html()
This commit is contained in:
parent
c47923b669
commit
f6fdfabf81
2 changed files with 13 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
generate_error_module!(
|
generate_error_module!(
|
||||||
generate_error_types!(MarkdownError, MarkdownErrorKind,
|
generate_error_types!(MarkdownError, MarkdownErrorKind,
|
||||||
MarkdownParsingError => "Markdown parsing error"
|
MarkdownRenderError => "Markdown render error"
|
||||||
);
|
);
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -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 result::Result;
|
||||||
use error::MarkdownErrorKind;
|
use error::MarkdownErrorKind;
|
||||||
|
use libimagerror::into::IntoError;
|
||||||
|
|
||||||
pub type HTML = String;
|
pub type HTML = String;
|
||||||
|
|
||||||
pub fn to_html(buffer: &str) -> Result<HTML> {
|
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 {
|
pub mod iter {
|
||||||
|
|
Loading…
Reference in a new issue