From 69e2db6efadf2d15514a8947f48acaf174024a57 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 4 Oct 2023 09:33:44 +0200 Subject: Upgrade to comrak 0.19 --- askama/Cargo.toml | 2 +- askama/src/filters/mod.rs | 51 ++++++++++------------------------------------- testing/Cargo.toml | 2 +- testing/tests/markdown.rs | 15 ++++++-------- 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(s: T) -> Result { pub fn markdown( e: E, s: S, - options: Option<&comrak::ComrakOptions>, + options: Option<&comrak::Options>, ) -> Result> where E: Escaper, S: AsRef, { - 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* \n* 3", - options: &ComrakOptions { - render: ComrakRenderOptions { - unsafe_: true, - ..Default::default() - }, - ..Default::default() - }, + options: &options, }; assert_eq!( s.render().unwrap(), -- cgit