#![cfg(feature = "markdown")]
use askama::Template;
use comrak::Options;
#[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* \n* 3",
};
assert_eq!(
s.render().unwrap(),
"\
before\
\n\
- 1
\n\
- \n\
<script>alert('Lol, hacked!')</script>\n\
\n\
- 3
\n\
\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 Options,
}
#[test]
fn test_markdown_with_options() {
let mut options = Options::default();
options.render.unsafe_ = true;
let s = MarkdownWithOptionsTemplate {
before: "before",
after: "after",
content: "* 1\n* \n* 3",
options: &options,
};
assert_eq!(
s.render().unwrap(),
"\
before\
\n\
- 1
\n\
- \n\
\n\
\n\
- 3
\n\
\n\
after",
);
}
#[derive(Template)]
#[template(source = "{{content|markdown}}", ext = "html")]
struct MarkdownStringTemplate {
content: String,
}
// Tests if the markdown filter accepts String
#[test]
fn test_markdown_owned_string() {
let template = MarkdownStringTemplate {
content: "The markdown filter _indeed_ works with __String__".into(),
};
assert_eq!(
template.render().unwrap(),
"The markdown filter indeed works with String
\n"
)
}