From 1378fb4033feb31afdcab2a511504e408141bb90 Mon Sep 17 00:00:00 2001 From: slonkazoid Date: Sat, 28 Dec 2024 20:16:27 +0300 Subject: [PATCH] add more render options --- CONFIG.md | 11 ++++++++--- src/config.rs | 3 +++ src/markdown_render.rs | 8 +++++++- src/post/markdown_posts.rs | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CONFIG.md b/CONFIG.md index 95b4ad7..c0b811e 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -52,9 +52,14 @@ compress = true # compress the cache file compression_level = 3 # zstd compression level, 3 is recommended [render] -syntect.load_defaults = false # include default syntect themes -syntect.themes_dir = "themes" # directory to include themes from -syntect.theme = "Catppuccin Mocha" # theme file name (without `.tmTheme`) +escape = false # escape HTML in the markdown soucre instead of + # clobbering it (https://docs.rs/comrak/latest/comrak/struct.RenderOptions.html#structfield.escape) +unsafe = false # allow HTML and dangerous links (https://docs.rs/comrak/latest/comrak/struct.RenderOptions.html#structfield.unsafe_) + +[render.syntect] +load_defaults = false # include default syntect themes +themes_dir = "themes" # directory to include themes from +theme = "Catppuccin Mocha" # theme file name (without `.tmTheme`) [blag] bin = "blag" # path to blag binary diff --git a/src/config.rs b/src/config.rs index df1a0a2..b1229f7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,6 +22,9 @@ pub struct SyntectConfig { #[serde(default)] pub struct RenderConfig { pub syntect: SyntectConfig, + pub escape: bool, + #[serde(rename = "unsafe")] + pub unsafe_: bool, } #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/src/markdown_render.rs b/src/markdown_render.rs index 0d486fe..2b404ce 100644 --- a/src/markdown_render.rs +++ b/src/markdown_render.rs @@ -26,7 +26,11 @@ pub fn build_syntect(config: &RenderConfig) -> eyre::Result { Ok(builder.build()) } -pub fn render(markdown: &str, syntect: Option<&dyn SyntaxHighlighterAdapter>) -> String { +pub fn render( + markdown: &str, + config: &RenderConfig, + syntect: Option<&dyn SyntaxHighlighterAdapter>, +) -> String { let mut options = ComrakOptions::default(); options.extension.table = true; options.extension.autolink = true; @@ -35,6 +39,8 @@ pub fn render(markdown: &str, syntect: Option<&dyn SyntaxHighlighterAdapter>) -> options.extension.strikethrough = true; options.extension.multiline_block_quotes = true; options.extension.header_ids = Some(String::new()); + options.render.escape = config.escape; + options.render.unsafe_ = config.unsafe_; let mut render_plugins = RenderPlugins::default(); render_plugins.codefence_syntax_highlighter = syntect; diff --git a/src/post/markdown_posts.rs b/src/post/markdown_posts.rs index b41d197..65ca241 100644 --- a/src/post/markdown_posts.rs +++ b/src/post/markdown_posts.rs @@ -117,7 +117,7 @@ impl MarkdownPosts { let parsing = parsing_start.elapsed(); let before_render = Instant::now(); - let post = render(body, Some(&self.syntect)).into(); + let post = render(body, &self.config.render, Some(&self.syntect)).into(); let rendering = before_render.elapsed(); if let Some(cache) = &self.cache {