From 4571b067ea86df90414dafd941f1a31a538a7b8a Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Wed, 12 Sep 2018 16:44:52 +0200 Subject: [PATCH] Fix ignored shortcode swallowing whitespace Fix #383 --- components/rendering/src/content.pest | 2 +- components/rendering/src/shortcode.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/components/rendering/src/content.pest b/components/rendering/src/content.pest index 662ac3aa..104fab4a 100644 --- a/components/rendering/src/content.pest +++ b/components/rendering/src/content.pest @@ -54,7 +54,7 @@ ignored_sc_body_start = !{ "{%/*" ~ sc_def ~ "*/%}" } ignored_sc_body_end = !{ "{%/*" ~ "end" ~ "*/%}" } shortcode_with_body = !{ sc_body_start ~ text_in_body_sc ~ sc_body_end } -ignored_shortcode_with_body = !{ ignored_sc_body_start ~ text_in_ignored_body_sc ~ ignored_sc_body_end } +ignored_shortcode_with_body = { ignored_sc_body_start ~ text_in_ignored_body_sc ~ ignored_sc_body_end } text_in_body_sc = ${ (!(sc_body_end) ~ any)+ } text_in_ignored_body_sc = ${ (!(ignored_sc_body_end) ~ any)+ } diff --git a/components/rendering/src/shortcode.rs b/components/rendering/src/shortcode.rs index 349dba8d..bc18343c 100644 --- a/components/rendering/src/shortcode.rs +++ b/components/rendering/src/shortcode.rs @@ -310,6 +310,16 @@ Hello World assert_eq!(res, "\nHello World\n{% youtube() %}Some body {{ hello() }}{% end %}"); } + // https://github.com/Keats/gutenberg/issues/383 + #[test] + fn unignore_shortcode_with_body_does_not_swallow_initial_whitespace() { + let res = render_shortcodes(r#" +Hello World +{%/* youtube() */%} +Some body {{ hello() }}{%/* end */%}"#, &Tera::default()); + assert_eq!(res, "\nHello World\n{% youtube() %}\nSome body {{ hello() }}{% end %}"); + } + #[test] fn can_parse_shortcode_arguments() { let inputs = vec![