diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2022-02-01 15:01:17 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2022-02-07 22:30:37 +0100 |
commit | fd8bfa43c0c20e4af195824ff95503e41ddb82e8 (patch) | |
tree | b366f80cf13c83d93b2141490eb3730c6a6a13b5 /testing/tests | |
parent | 0aab78c6775493fb13fabce2b5eaef7ac83e6665 (diff) | |
download | askama-fd8bfa43c0c20e4af195824ff95503e41ddb82e8.tar.gz askama-fd8bfa43c0c20e4af195824ff95503e41ddb82e8.tar.bz2 askama-fd8bfa43c0c20e4af195824ff95503e41ddb82e8.zip |
Add markdown filter
Diffstat (limited to '')
-rw-r--r-- | testing/tests/markdown.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/testing/tests/markdown.rs b/testing/tests/markdown.rs new file mode 100644 index 0000000..e0150f6 --- /dev/null +++ b/testing/tests/markdown.rs @@ -0,0 +1,75 @@ +#![cfg(feature = "markdown")] + +use askama::Template; +use comrak::{ComrakOptions, ComrakRenderOptions}; + +#[derive(Template)] +#[template(source = "{{before}}{{content|markdown}}{{after}}", ext = "html")] +struct MarkdownTemplate<'a> { + before: &'a str, + after: &'a str, + content: &'a str, +} + +#[test] +fn test_markdown() { + let s = MarkdownTemplate { + before: "before", + after: "after", + content: "* 1\n* <script>alert('Lol, hacked!')</script>\n* 3", + }; + assert_eq!( + s.render().unwrap(), + "\ +before\ +<ul>\n\ +<li>1</li>\n\ +<li>\n\ +<script>alert('Lol, hacked!')</script>\n\ +</li>\n\ +<li>3</li>\n\ +</ul>\n\ +after", + ); +} + +#[derive(Template)] +#[template( + source = "{{before}}{{content|markdown(options)}}{{after}}", + ext = "html" +)] +struct MarkdownWithOptionsTemplate<'a> { + before: &'a str, + after: &'a str, + content: &'a str, + options: &'a ComrakOptions, +} + +#[test] +fn test_markdown_with_options() { + let s = MarkdownWithOptionsTemplate { + before: "before", + after: "after", + content: "* 1\n* <script>alert('Lol, hacked!')</script>\n* 3", + options: &ComrakOptions { + render: ComrakRenderOptions { + unsafe_: true, + ..Default::default() + }, + ..Default::default() + }, + }; + assert_eq!( + s.render().unwrap(), + "\ +before\ +<ul>\n\ +<li>1</li>\n\ +<li>\n\ +<script>alert('Lol, hacked!')</script>\n\ +</li>\n\ +<li>3</li>\n\ +</ul>\n\ +after", + ); +} |