diff options
author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2022-04-21 15:47:57 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2022-04-26 10:15:34 +0200 |
commit | e54039162ab71e74345055f5000b2689627e8f03 (patch) | |
tree | 5ab6bd1a54277ca779c47237cb8b49c018ef7468 /askama_shared/src | |
parent | 358f7cd07dc42ba4189d2661461ff0b43a27c304 (diff) | |
download | askama-e54039162ab71e74345055f5000b2689627e8f03.tar.gz askama-e54039162ab71e74345055f5000b2689627e8f03.tar.bz2 askama-e54039162ab71e74345055f5000b2689627e8f03.zip |
Add new minimize jinja character handling: `~`
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/parser.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 4654e82..d7e33fb 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -133,6 +133,7 @@ pub(crate) enum Target<'a> { pub(crate) enum Whitespace { Preserve, Trim, + Minimize, } impl From<char> for Whitespace { @@ -140,6 +141,7 @@ impl From<char> for Whitespace { match c { '+' => Self::Preserve, '-' => Self::Trim, + '~' => Self::Minimize, _ => panic!("unsupported `Whitespace` conversion"), } } @@ -677,7 +679,7 @@ expr_prec_layer!(expr_and, expr_compare, "&&"); expr_prec_layer!(expr_or, expr_and, "||"); fn expr_handle_ws(i: &str) -> IResult<&str, Whitespace> { - alt((char('-'), char('+')))(i).map(|(s, r)| (s, Whitespace::from(r))) + alt((char('-'), char('+'), char('~')))(i).map(|(s, r)| (s, Whitespace::from(r))) } fn expr_any(i: &str) -> IResult<&str, Expr<'_>> { @@ -1138,6 +1140,8 @@ fn block_comment<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, Node<'a>> { Some(Whitespace::Trim) } else if tail.ends_with('+') { Some(Whitespace::Preserve) + } else if tail.ends_with('~') { + Some(Whitespace::Minimize) } else { None }; |