From 8d8374a10f09729b403f3519a7bceac919c484c3 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 17 Apr 2018 17:34:44 +0200 Subject: Properly handle whitespace around comments (fixes #79) --- askama_derive/src/parser.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'askama_derive/src/parser.rs') diff --git a/askama_derive/src/parser.rs b/askama_derive/src/parser.rs index 402801f..f1e3c72 100644 --- a/askama_derive/src/parser.rs +++ b/askama_derive/src/parser.rs @@ -52,7 +52,7 @@ pub struct Macro<'a> { #[derive(Debug)] pub enum Node<'a> { Lit(&'a str, &'a str, &'a str), - Comment(), + Comment(WS), Expr(WS, Expr<'a>), Call(WS, Option<& 'a str>, &'a str, Vec>), LetDecl(WS, Target<'a>), @@ -638,9 +638,10 @@ named!(block_node, do_parse!( named!(block_comment, do_parse!( tag_s!("{#") >> - take_until_s!("#}") >> + pws: opt!(tag_s!("-")) >> + inner: take_until_s!("#}") >> tag_s!("#}") >> - (Node::Comment()) + (Node::Comment(WS(pws.is_some(), inner.len() > 1 && inner[inner.len() - 1] == b'-'))) )); named!(parse_template>>, many0!(alt!( -- cgit