aboutsummaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/Cargo.toml5
-rw-r--r--testing/tests/markdown.rs75
2 files changed, 79 insertions, 1 deletions
diff --git a/testing/Cargo.toml b/testing/Cargo.toml
index 008b200..bd7bbc9 100644
--- a/testing/Cargo.toml
+++ b/testing/Cargo.toml
@@ -7,10 +7,13 @@ edition = "2018"
publish = false
[features]
-default = ["serde_json", "askama/serde-json"]
+default = ["serde-json", "markdown"]
+serde-json = ["serde_json", "askama/serde-json"]
+markdown = ["comrak", "askama/markdown"]
[dependencies]
askama = { path = "../askama", version = "0.11.0-beta.1" }
+comrak = { version = "0.12", default-features = false, optional = true }
serde_json = { version = "1.0", optional = true }
[dev-dependencies]
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\
+&lt;script&gt;alert('Lol, hacked!')&lt;/script&gt;\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",
+ );
+}