Browse Source

Fix ignored shortcode swallowing whitespace

Fix #383
index-subcmd
Vincent Prouillet 6 years ago
parent
commit
4571b067ea
2 changed files with 11 additions and 1 deletions
  1. +1
    -1
      components/rendering/src/content.pest
  2. +10
    -0
      components/rendering/src/shortcode.rs

+ 1
- 1
components/rendering/src/content.pest View File

@@ -54,7 +54,7 @@ ignored_sc_body_start = !{ "{%/*" ~ sc_def ~ "*/%}" }
ignored_sc_body_end = !{ "{%/*" ~ "end" ~ "*/%}" } ignored_sc_body_end = !{ "{%/*" ~ "end" ~ "*/%}" }


shortcode_with_body = !{ sc_body_start ~ text_in_body_sc ~ sc_body_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_body_sc = ${ (!(sc_body_end) ~ any)+ }
text_in_ignored_body_sc = ${ (!(ignored_sc_body_end) ~ any)+ } text_in_ignored_body_sc = ${ (!(ignored_sc_body_end) ~ any)+ }


+ 10
- 0
components/rendering/src/shortcode.rs View File

@@ -310,6 +310,16 @@ Hello World
assert_eq!(res, "\nHello World\n{% youtube() %}Some body {{ hello() }}{% end %}"); 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] #[test]
fn can_parse_shortcode_arguments() { fn can_parse_shortcode_arguments() {
let inputs = vec![ let inputs = vec![


Loading…
Cancel
Save