aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-10-04 09:33:44 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-11-30 13:33:06 +0100
commit69e2db6efadf2d15514a8947f48acaf174024a57 (patch)
treef965676406b931a7b767e8bc5f978af50f624178
parent21f840a2ad03b23fc9d54f581323b30a3cc9b620 (diff)
downloadaskama-69e2db6efadf2d15514a8947f48acaf174024a57.tar.gz
askama-69e2db6efadf2d15514a8947f48acaf174024a57.tar.bz2
askama-69e2db6efadf2d15514a8947f48acaf174024a57.zip
Upgrade to comrak 0.19
Diffstat (limited to '')
-rw-r--r--askama/Cargo.toml2
-rw-r--r--askama/src/filters/mod.rs51
-rw-r--r--testing/Cargo.toml2
-rw-r--r--testing/tests/markdown.rs15
4 files changed, 19 insertions, 51 deletions
diff --git a/askama/Cargo.toml b/askama/Cargo.toml
index 1fe1afa..a4300bc 100644
--- a/askama/Cargo.toml
+++ b/askama/Cargo.toml
@@ -41,7 +41,7 @@ mime_guess = []
[dependencies]
askama_derive = { version = "0.12.0", path = "../askama_derive" }
askama_escape = { version = "0.10.3", path = "../askama_escape" }
-comrak = { version = "0.18", optional = true, default-features = false }
+comrak = { version = "0.19", optional = true, default-features = false }
dep_humansize = { package = "humansize", version = "2", optional = true }
dep_num_traits = { package = "num-traits", version = "0.2.6", optional = true }
percent-encoding = { version = "2.1.0", optional = true }
diff --git a/askama/src/filters/mod.rs b/askama/src/filters/mod.rs
index a7aa62b..f77e2f8 100644
--- a/askama/src/filters/mod.rs
+++ b/askama/src/filters/mod.rs
@@ -345,51 +345,22 @@ pub fn wordcount<T: fmt::Display>(s: T) -> Result<usize> {
pub fn markdown<E, S>(
e: E,
s: S,
- options: Option<&comrak::ComrakOptions>,
+ options: Option<&comrak::Options>,
) -> Result<MarkupDisplay<E, String>>
where
E: Escaper,
S: AsRef<str>,
{
- use comrak::{
- markdown_to_html, ComrakExtensionOptions, ComrakOptions, ComrakParseOptions,
- ComrakRenderOptions, ListStyleType,
- };
-
- const DEFAULT_OPTIONS: ComrakOptions = ComrakOptions {
- extension: ComrakExtensionOptions {
- strikethrough: true,
- tagfilter: true,
- table: true,
- autolink: true,
- // default:
- tasklist: false,
- superscript: false,
- header_ids: None,
- footnotes: false,
- description_lists: false,
- front_matter_delimiter: None,
- },
- parse: ComrakParseOptions {
- // default:
- smart: false,
- default_info_string: None,
- relaxed_tasklist_matching: false,
- },
- render: ComrakRenderOptions {
- escape: true,
- // default:
- hardbreaks: false,
- github_pre_lang: false,
- full_info_string: false,
- width: 0,
- unsafe_: false,
- list_style: ListStyleType::Dash,
- sourcepos: false,
- },
- };
-
- let s = markdown_to_html(s.as_ref(), options.unwrap_or(&DEFAULT_OPTIONS));
+ use comrak::{markdown_to_html, Options};
+
+ let mut defaults = Options::default();
+ defaults.extension.strikethrough = true;
+ defaults.extension.tagfilter = true;
+ defaults.extension.table = true;
+ defaults.extension.autolink = true;
+ defaults.render.escape = true;
+
+ let s = markdown_to_html(s.as_ref(), options.unwrap_or(&defaults));
Ok(MarkupDisplay::new_safe(s, e))
}
diff --git a/testing/Cargo.toml b/testing/Cargo.toml
index 23b5743..1d7050d 100644
--- a/testing/Cargo.toml
+++ b/testing/Cargo.toml
@@ -14,7 +14,7 @@ markdown = ["comrak", "askama/markdown"]
[dependencies]
askama = { path = "../askama", version = "0.12" }
-comrak = { version = "0.18", default-features = false, optional = true }
+comrak = { version = "0.19", 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
index e0150f6..75163c9 100644
--- a/testing/tests/markdown.rs
+++ b/testing/tests/markdown.rs
@@ -1,7 +1,7 @@
#![cfg(feature = "markdown")]
use askama::Template;
-use comrak::{ComrakOptions, ComrakRenderOptions};
+use comrak::Options;
#[derive(Template)]
#[template(source = "{{before}}{{content|markdown}}{{after}}", ext = "html")]
@@ -42,22 +42,19 @@ struct MarkdownWithOptionsTemplate<'a> {
before: &'a str,
after: &'a str,
content: &'a str,
- options: &'a ComrakOptions,
+ 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* <script>alert('Lol, hacked!')</script>\n* 3",
- options: &ComrakOptions {
- render: ComrakRenderOptions {
- unsafe_: true,
- ..Default::default()
- },
- ..Default::default()
- },
+ options: &options,
};
assert_eq!(
s.render().unwrap(),