Make the markdown filter compatible with String

This commit solves issue #719.

This is done by making the markdown filter borrow the string and
simplifying the filter to accept `&str` instead of `AsRef<str>`

Add test for the markdown filter using  as input

Revert markdown filter changes

Revert unnecessary changes

Improve test_markdown_owned_string test

Use cargo fmt
This commit is contained in:
Jakub Stachurski 2024-01-09 17:24:11 +01:00 committed by Dirkjan Ochtman
parent b8697ba202
commit 50c64bc865
2 changed files with 19 additions and 1 deletions

View File

@ -1200,7 +1200,7 @@ impl<'a> Generator<'a> {
};
buf.write(&format!(
"::askama::filters::markdown({}, ",
"::askama::filters::markdown({}, &",
self.input.escaper
));
self.visit_expr(buf, md)?;

View File

@ -70,3 +70,21 @@ before\
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(),
"<p>The markdown filter <em>indeed</em> works with <strong>String</strong></p>\n"
)
}