From 533ea96d4f4ca6ce9a6325842d77e62488d3204c Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 23 May 2020 23:32:13 -0400 Subject: [PATCH 1/2] Add a test for literal string blocks. --- js/test_cases/literal_string_block/input1.json | 1 + js/test_cases/literal_string_block/main.dust | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 js/test_cases/literal_string_block/input1.json create mode 100644 js/test_cases/literal_string_block/main.dust diff --git a/js/test_cases/literal_string_block/input1.json b/js/test_cases/literal_string_block/input1.json new file mode 100644 index 0000000..ad7288d --- /dev/null +++ b/js/test_cases/literal_string_block/input1.json @@ -0,0 +1 @@ +{"name": "Bob"} diff --git a/js/test_cases/literal_string_block/main.dust b/js/test_cases/literal_string_block/main.dust new file mode 100644 index 0000000..781ca76 --- /dev/null +++ b/js/test_cases/literal_string_block/main.dust @@ -0,0 +1,5 @@ +{` +This block is supposed + to preserve {name} all +newlines, whitespace, and braces +`} From b73561caf9a7a4e6c51560ecda3d6618252e12e0 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 23 May 2020 23:41:05 -0400 Subject: [PATCH 2/2] Add support for literal string blocks. --- src/parser/parser.rs | 6 ++++++ src/renderer/inline_partial_tree.rs | 1 + src/renderer/renderer.rs | 1 + 3 files changed, 8 insertions(+) diff --git a/src/parser/parser.rs b/src/parser/parser.rs index c016e7e..fb0bf3d 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -27,6 +27,7 @@ use nom::IResult; pub enum DustTag<'a> { DTSpecial(Special), DTComment(Comment<'a>), + DTLiteralStringBlock(&'a str), DTReference(Reference<'a>), DTSection(Container<'a>), DTExists(Container<'a>), @@ -211,6 +212,7 @@ fn dust_tag(i: &str) -> IResult<&str, DustTag> { alt(( map(special, DustTag::DTSpecial), map(comment, DustTag::DTComment), + map(literal_string_block, DustTag::DTLiteralStringBlock), map(reference, DustTag::DTReference), conditional("{#", DustTag::DTSection), conditional("{?", DustTag::DTExists), @@ -634,6 +636,10 @@ fn ignore_new_line_leading_whitespace(i: &str) -> IResult<&str, IgnoredWhitespac )(i) } +fn literal_string_block(i: &str) -> IResult<&str, &str> { + delimited(tag("{`"), take_until("`}"), tag("`}"))(i) +} + /// Any text that is not a Dust element or ignored whitespace fn span(i: &str) -> IResult<&str, Span> { let (remaining, line) = verify( diff --git a/src/renderer/inline_partial_tree.rs b/src/renderer/inline_partial_tree.rs index ff7220b..d0a2020 100644 --- a/src/renderer/inline_partial_tree.rs +++ b/src/renderer/inline_partial_tree.rs @@ -63,6 +63,7 @@ fn extract_inline_partials_from_tag<'a, 'b>( match tag { DustTag::DTComment(..) => (), DustTag::DTSpecial(..) => (), + DustTag::DTLiteralStringBlock(..) => (), DustTag::DTReference(..) => (), DustTag::DTSection(container) => { match &container.contents { diff --git a/src/renderer/renderer.rs b/src/renderer/renderer.rs index 7cf4e99..145b3d4 100644 --- a/src/renderer/renderer.rs +++ b/src/renderer/renderer.rs @@ -144,6 +144,7 @@ impl<'a> DustRenderer<'a> { } .to_owned()) } + DustTag::DTLiteralStringBlock(literal) => return Ok((*literal).to_owned()), DustTag::DTReference(reference) => { let val = walk_path(breadcrumbs, &reference.path.keys); match val {