|
|
@@ -70,13 +70,21 @@ pub fn markdown_to_html(content: &str, context: &Context) -> Result<(String, Vec |
|
|
|
// Defaults to a 0 level so not a real header |
|
|
|
// It should be an Option ideally but not worth the hassle to update |
|
|
|
let mut temp_header = TempHeader::default(); |
|
|
|
let mut clear_shortcode_block = false; |
|
|
|
|
|
|
|
let mut opts = Options::empty(); |
|
|
|
opts.insert(OPTION_ENABLE_TABLES); |
|
|
|
opts.insert(OPTION_ENABLE_FOOTNOTES); |
|
|
|
|
|
|
|
{ |
|
|
|
let parser = Parser::new_ext(content, opts).map(|event| match event { |
|
|
|
|
|
|
|
let parser = Parser::new_ext(content, opts).map(|event| { |
|
|
|
if clear_shortcode_block { |
|
|
|
clear_shortcode_block = false; |
|
|
|
shortcode_block = None; |
|
|
|
} |
|
|
|
|
|
|
|
match event { |
|
|
|
Event::Text(mut text) => { |
|
|
|
// Header first |
|
|
|
if in_header { |
|
|
@@ -129,7 +137,10 @@ pub fn markdown_to_html(content: &str, context: &Context) -> Result<(String, Vec |
|
|
|
|
|
|
|
added_shortcode = true; |
|
|
|
match render_simple_shortcode(context.tera, &name, &args) { |
|
|
|
Ok(s) => return Event::Html(Owned(format!("</p>{}", s))), |
|
|
|
// Make before and after cleaning up of extra <p> / </p> tags more parallel. |
|
|
|
// Or, in other words: |
|
|
|
// TERRIBLE HORRIBLE NO GOOD VERY BAD HACK |
|
|
|
Ok(s) => return Event::Html(Owned(format!("</p>{}<p>", s))), |
|
|
|
Err(e) => { |
|
|
|
error = Some(e); |
|
|
|
return Event::Html(Owned(String::new())); |
|
|
@@ -153,6 +164,7 @@ pub fn markdown_to_html(content: &str, context: &Context) -> Result<(String, Vec |
|
|
|
if let Some(ref mut shortcode) = shortcode_block { |
|
|
|
if text.trim() == "{% end %}" { |
|
|
|
added_shortcode = true; |
|
|
|
clear_shortcode_block = true; |
|
|
|
match shortcode.render(context.tera) { |
|
|
|
Ok(s) => return Event::Html(Owned(format!("</p>{}", s))), |
|
|
|
Err(e) => { |
|
|
@@ -271,7 +283,7 @@ pub fn markdown_to_html(content: &str, context: &Context) -> Result<(String, Vec |
|
|
|
// println!("event = {:?}", event); |
|
|
|
event |
|
|
|
}, |
|
|
|
}); |
|
|
|
}}); |
|
|
|
|
|
|
|
cmark::html::push_html(&mut html, parser); |
|
|
|
} |
|
|
@@ -282,6 +294,6 @@ pub fn markdown_to_html(content: &str, context: &Context) -> Result<(String, Vec |
|
|
|
|
|
|
|
match error { |
|
|
|
Some(e) => Err(e), |
|
|
|
None => Ok((html.replace("<p></p>", ""), make_table_of_contents(&headers))), |
|
|
|
None => Ok((html.replace("<p></p>", "").replace("</p></p>", "</p>"), make_table_of_contents(&headers))), |
|
|
|
} |
|
|
|
} |