aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/generator.rs
diff options
context:
space:
mode:
authorLibravatar René Kijewski <kijewski@library.vetmed.fu-berlin.de>2022-02-01 15:01:17 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2022-02-07 22:30:37 +0100
commitfd8bfa43c0c20e4af195824ff95503e41ddb82e8 (patch)
treeb366f80cf13c83d93b2141490eb3730c6a6a13b5 /askama_shared/src/generator.rs
parent0aab78c6775493fb13fabce2b5eaef7ac83e6665 (diff)
downloadaskama-fd8bfa43c0c20e4af195824ff95503e41ddb82e8.tar.gz
askama-fd8bfa43c0c20e4af195824ff95503e41ddb82e8.tar.bz2
askama-fd8bfa43c0c20e4af195824ff95503e41ddb82e8.zip
Add markdown filter
Diffstat (limited to 'askama_shared/src/generator.rs')
-rw-r--r--askama_shared/src/generator.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs
index 63a0154..c3beb88 100644
--- a/askama_shared/src/generator.rs
+++ b/askama_shared/src/generator.rs
@@ -1097,6 +1097,45 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
DisplayWrap::Unwrapped
}
+ #[cfg(not(feature = "markdown"))]
+ fn _visit_markdown_filter(
+ &mut self,
+ _buf: &mut Buffer,
+ _args: &[Expr<'_>],
+ ) -> Result<DisplayWrap, CompileError> {
+ Err("the `markdown` filter requires the `markdown` feature to be enabled".into())
+ }
+
+ #[cfg(feature = "markdown")]
+ fn _visit_markdown_filter(
+ &mut self,
+ buf: &mut Buffer,
+ args: &[Expr<'_>],
+ ) -> Result<DisplayWrap, CompileError> {
+ let (md, options) = match args {
+ [md] => (md, None),
+ [md, options] => (md, Some(options)),
+ _ => return Err("markdown filter expects no more than one option argument".into()),
+ };
+
+ buf.write(&format!(
+ "::askama::filters::markdown({}, ",
+ self.input.escaper
+ ));
+ self.visit_expr(buf, md)?;
+ match options {
+ Some(options) => {
+ buf.write(", ::core::option::Option::Some(");
+ self.visit_expr(buf, options)?;
+ buf.write(")");
+ }
+ None => buf.write(", ::core::option::Option::None"),
+ }
+ buf.write(")?");
+
+ Ok(DisplayWrap::Wrapped)
+ }
+
fn visit_filter(
&mut self,
buf: &mut Buffer,
@@ -1115,6 +1154,8 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
} else if name == "join" {
self._visit_join_filter(buf, args)?;
return Ok(DisplayWrap::Unwrapped);
+ } else if name == "markdown" {
+ return self._visit_markdown_filter(buf, args);
}
if name == "tojson" {