aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-04-17 17:34:44 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-04-17 17:34:44 +0200
commit8d8374a10f09729b403f3519a7bceac919c484c3 (patch)
treeb2e2e7bc5233f1e6cfc1148b68d486a89f600ed6 /askama_derive/src
parent02266bed683080e6412c337251d69df23b5da3c6 (diff)
downloadaskama-8d8374a10f09729b403f3519a7bceac919c484c3.tar.gz
askama-8d8374a10f09729b403f3519a7bceac919c484c3.tar.bz2
askama-8d8374a10f09729b403f3519a7bceac919c484c3.zip
Properly handle whitespace around comments (fixes #79)
Diffstat (limited to '')
-rw-r--r--askama_derive/src/generator.rs8
-rw-r--r--askama_derive/src/parser.rs7
2 files changed, 11 insertions, 4 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 0ff30ed..449a969 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -310,7 +310,9 @@ impl<'a> Generator<'a> {
Node::Lit(lws, val, rws) => {
self.write_lit(lws, val, rws);
},
- Node::Comment() => {},
+ Node::Comment(ref ws) => {
+ self.write_comment(ws);
+ },
Node::Expr(ref ws, ref val) => {
self.write_expr(state, ws, val);
},
@@ -600,6 +602,10 @@ impl<'a> Generator<'a> {
}
}
+ fn write_comment(&mut self, ws: &WS) {
+ self.handle_ws(ws);
+ }
+
/* Visitor methods for expression types */
fn visit_expr_root(&mut self, expr: &Expr) -> DisplayWrap {
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<Expr<'a>>),
LetDecl(WS, Target<'a>),
@@ -638,9 +638,10 @@ named!(block_node<Node>, do_parse!(
named!(block_comment<Node>, 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<Vec<Node<'a>>>, many0!(alt!(