From 50307d0c3e5ca6859f8571a45ab75767862bbe85 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 26 Nov 2024 13:03:48 +0100 Subject: [PATCH] use comrak builder --- src/utils/markdown.rs | 83 ++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 48 deletions(-) diff --git a/src/utils/markdown.rs b/src/utils/markdown.rs index fd5fb86..03f1e73 100644 --- a/src/utils/markdown.rs +++ b/src/utils/markdown.rs @@ -21,54 +21,41 @@ pub struct File { } /// Options used for parser and compiler MD --> HTML -pub fn get_options<'a>() -> ComrakOptions<'a> { - let mut options = comrak::Options::default(); - - // Extension - options.extension.strikethrough = true; - options.extension.tagfilter = true; - options.extension.table = true; - options.extension.autolink = true; - options.extension.tasklist = true; - options.extension.superscript = true; - options.extension.header_ids = Some(String::new()); - options.extension.footnotes = true; - options.extension.description_lists = true; - options.extension.front_matter_delimiter = Some("---".into()); - options.extension.multiline_block_quotes = true; - options.extension.math_dollars = true; - options.extension.math_code = false; - options.extension.wikilinks_title_after_pipe = false; - options.extension.wikilinks_title_before_pipe = false; - options.extension.underline = true; - options.extension.spoiler = false; - options.extension.greentext = false; - - // Parser - options.parse.smart = true; // could be boring - options.parse.default_info_string = Some("plaintext".into()); - options.parse.relaxed_tasklist_matching = true; - options.parse.relaxed_autolinks = true; - // options.render.broken_link_callback = ...; - - // Renderer - options.render.hardbreaks = false; - options.render.github_pre_lang = false; - options.render.full_info_string = true; - options.render.width = 0; // 0 mean disabled? - options.render.unsafe_ = true; - options.render.escape = false; - options.render.list_style = ListStyleType::Dash; - options.render.sourcepos = false; - options.render.experimental_inline_sourcepos = false; - options.render.escaped_char_spans = false; - options.render.ignore_setext = true; - options.render.ignore_empty_links = true; - options.render.gfm_quirks = true; - options.render.prefer_fenced = false; - options.render.figure_with_caption = false; - - options +pub fn get_options() -> ComrakOptions { + comrak::Options { + extension: comrak::ExtensionOptions::builder() + .strikethrough(true) + .tagfilter(true) + .table(true) + .autolink(true) + .tasklist(true) + .superscript(true) + .header_ids(String::new()) + .footnotes(true) + .description_lists(true) + .front_matter_delimiter("---".into()) + .multiline_block_quotes(true) + .math_dollars(true) + .underline(true) + //.spoiler(true) // todo: css + //.image_url_rewriter(Arc::new(|url: &str| url.into())) // todo: image rewriter b64 + //.link_url_rewriter(Arc::new(|url: &str| url.into())) // todo: local link + .build(), + parse: comrak::ParseOptions::builder() + .smart(true) + .default_info_string("plaintext".into()) + .relaxed_tasklist_matching(true) + .relaxed_autolinks(true) + .build(), + render: comrak::RenderOptions::builder() + .full_info_string(true) + .unsafe_(true) + .list_style(ListStyleType::Dash) + .ignore_setext(true) + .ignore_empty_links(true) + .gfm_quirks(true) + .build(), + } } /// Resize images if needed