From e662f734381a773dd4124f51444e7a61fc58c1a2 Mon Sep 17 00:00:00 2001
From: Reilly Tucker Siemens
/
tags more parallel. + // Or, in other words: + // TERRIBLE HORRIBLE NO GOOD VERY BAD HACK + Ok(s) => return Event::Html(Owned(format!("{}", 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!("
{}", 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("", ""), make_table_of_contents(&headers))), + None => Ok((html.replace("", "").replace("", ""), make_table_of_contents(&headers))), } } diff --git a/components/rendering/tests/markdown.rs b/components/rendering/tests/markdown.rs index e7687bc..599e5d5 100644 --- a/components/rendering/tests/markdown.rs +++ b/components/rendering/tests/markdown.rs @@ -137,6 +137,65 @@ fn can_render_body_shortcode_with_markdown_char_in_name() { } } +#[test] +fn can_render_body_shortcode_and_paragraph_after() { + let permalinks_ctx = HashMap::new(); + let mut tera = Tera::default(); + tera.extend(&GUTENBERG_TERA).unwrap(); + + let shortcode = "{{ body }}
"; + let markdown_string = r#" +{% figure() %} +This is a figure caption. +{% end %} + +Here is another paragraph. +"#; + + let expected = "This is a figure caption.
+Here is another paragraph.
+"; + + tera.add_raw_template(&format!("shortcodes/{}.html", "figure"), shortcode).unwrap(); + let context = Context::new(&tera, true, "base16-ocean-dark".to_string(), "", &permalinks_ctx, InsertAnchor::None); + + let res = markdown_to_html(markdown_string, &context).unwrap(); + println!("{:?}", res); + assert_eq!(res.0, expected); +} + +#[test] +fn can_render_two_body_shortcode_and_paragraph_after_with_line_break_between() { + let permalinks_ctx = HashMap::new(); + let mut tera = Tera::default(); + tera.extend(&GUTENBERG_TERA).unwrap(); + + let shortcode = "{{ body }}
"; + let markdown_string = r#" +{% figure() %} +This is a figure caption. +{% end %} + +{% figure() %} +This is a figure caption. +{% end %} + +Here is another paragraph. +"#; + + let expected = "This is a figure caption.
+This is a figure caption.
+Here is another paragraph.
+"; + + tera.add_raw_template(&format!("shortcodes/{}.html", "figure"), shortcode).unwrap(); + let context = Context::new(&tera, true, "base16-ocean-dark".to_string(), "", &permalinks_ctx, InsertAnchor::None); + + let res = markdown_to_html(markdown_string, &context).unwrap(); + println!("{:?}", res); + assert_eq!(res.0, expected); +} + #[test] fn can_render_several_shortcode_in_row() { let permalinks_ctx = HashMap::new();