aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--askama_derive/src/generator.rs5
-rw-r--r--askama_derive/src/parser.rs23
2 files changed, 27 insertions, 1 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 4a6eb89..aa91de0 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -345,6 +345,11 @@ impl<'a> Generator<'a> {
self.flush_ws(m.ws1);
self.prepare_ws(m.ws2);
}
+ Node::Raw(ws1, contents, ws2) => {
+ self.handle_ws(ws1);
+ self.buf_writable.push(Writable::Lit(contents));
+ self.handle_ws(ws2);
+ }
Node::Import(ws, _, _) => {
if level != AstLevel::Top {
panic!("import blocks only allowed at the top level");
diff --git a/askama_derive/src/parser.rs b/askama_derive/src/parser.rs
index 2a342fc..c880202 100644
--- a/askama_derive/src/parser.rs
+++ b/askama_derive/src/parser.rs
@@ -72,6 +72,7 @@ pub enum Node<'a> {
Include(WS, &'a str),
Import(WS, &'a str, &'a str),
Macro(&'a str, Macro<'a>),
+ Raw(WS, &'a str, WS),
}
pub type Cond<'a> = (WS, Option<Expr<'a>>, Vec<Node<'a>>);
@@ -126,6 +127,7 @@ fn split_ws_parts(s: &[u8]) -> Node {
)
}
+#[derive(Debug)]
enum ContentState {
Any,
Brace(usize),
@@ -836,6 +838,24 @@ named_args!(block_macro<'a>(s: &'a Syntax<'a>) <Input<'a>, Node<'a>>, do_parse!(
})
));
+named_args!(block_raw<'a>(s: &'a Syntax<'a>) <Input<'a>, Node<'a>>, do_parse!(
+ pws1: opt!(tag!("-")) >>
+ ws!(tag!("raw")) >>
+ nws1: opt!(tag!("-")) >>
+ call!(tag_block_end, s) >>
+ contents: take_until!("{% endraw %}") >>
+ call!(tag_block_start, s) >>
+ pws2: opt!(tag!("-")) >>
+ ws!(tag!("endraw")) >>
+ nws2: opt!(tag!("-")) >>
+ ({
+ let str_contents = str::from_utf8(&contents).unwrap();
+ (Node::Raw(WS(pws1.is_some(), nws1.is_some()),
+ str_contents,
+ WS(pws2.is_some(), nws2.is_some())))
+ })
+));
+
named_args!(block_node<'a>(s: &'a Syntax<'a>) <Input<'a>, Node<'a>>, do_parse!(
call!(tag_block_start, s) >>
contents: alt!(
@@ -848,7 +868,8 @@ named_args!(block_node<'a>(s: &'a Syntax<'a>) <Input<'a>, Node<'a>>, do_parse!(
block_include |
block_import |
call!(block_block, s) |
- call!(block_macro, s)
+ call!(block_macro, s) |
+ call!(block_raw, s)
) >>
call!(tag_block_end, s) >>
(contents)