diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-09-05 20:34:18 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-09-05 20:34:18 +0200 |
commit | f02ade3b94e0eb7f97498439142a2448ebdcdfcc (patch) | |
tree | f481e79056576dc5a6c50daaa2bf864f16e5aff2 /askama_shared/src/generator.rs | |
parent | 84fee0cf890fcc88ae9db1e1a17d0d784a73871a (diff) | |
download | askama-f02ade3b94e0eb7f97498439142a2448ebdcdfcc.tar.gz askama-f02ade3b94e0eb7f97498439142a2448ebdcdfcc.tar.bz2 askama-f02ade3b94e0eb7f97498439142a2448ebdcdfcc.zip |
Introduce attribute parameter to disable escaping
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/generator.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 7fbc5d9..d8b3a42 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -352,16 +352,20 @@ impl<'a> Generator<'a> { } } - fn write_expr(&mut self, ws: &WS, s: &Expr) { + fn write_expr(&mut self, state: &'a State, ws: &WS, s: &Expr) { self.handle_ws(ws); self.write("let askama_expr = &"); let wrapped = self.visit_expr(s); self.writeln(";"); + use self::DisplayWrap::*; + use super::input::EscapeMode::*; self.write("writer.write_fmt(format_args!(\"{}\", "); - self.write(match wrapped { - DisplayWrap::Wrapped => "askama_expr", - DisplayWrap::Unwrapped => "&::askama::MarkupDisplay::from(askama_expr)", + self.write(match (wrapped, &state.input.meta.escaping) { + (Wrapped, &Html) | + (Wrapped, &None) | + (Unwrapped, &None) => "askama_expr", + (Unwrapped, &Html) => "&::askama::MarkupDisplay::from(askama_expr)", }); self.writeln("))?;"); } @@ -508,7 +512,7 @@ impl<'a> Generator<'a> { match *n { Node::Lit(lws, val, rws) => { self.write_lit(lws, val, rws); } Node::Comment() => {}, - Node::Expr(ref ws, ref val) => { self.write_expr(ws, val); }, + Node::Expr(ref ws, ref val) => { self.write_expr(state, ws, val); }, Node::LetDecl(ref ws, ref var) => { self.write_let_decl(ws, var); }, Node::Let(ref ws, ref var, ref val) => { self.write_let(ws, var, val); }, Node::Cond(ref conds, ref ws) => { |