add more render options

This commit is contained in:
slonkazoid 2024-12-28 20:16:27 +03:00
parent ed74e84932
commit 1378fb4033
Signed by: slonk
SSH key fingerprint: SHA256:tbZfJX4IOvZ0LGWOWu5Ijo8jfMPi78TU7x1VoEeCIjM
4 changed files with 19 additions and 5 deletions

View file

@ -52,9 +52,14 @@ compress = true # compress the cache file
compression_level = 3 # zstd compression level, 3 is recommended compression_level = 3 # zstd compression level, 3 is recommended
[render] [render]
syntect.load_defaults = false # include default syntect themes escape = false # escape HTML in the markdown soucre instead of
syntect.themes_dir = "themes" # directory to include themes from # clobbering it (https://docs.rs/comrak/latest/comrak/struct.RenderOptions.html#structfield.escape)
syntect.theme = "Catppuccin Mocha" # theme file name (without `.tmTheme`) 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] [blag]
bin = "blag" # path to blag binary bin = "blag" # path to blag binary

View file

@ -22,6 +22,9 @@ pub struct SyntectConfig {
#[serde(default)] #[serde(default)]
pub struct RenderConfig { pub struct RenderConfig {
pub syntect: SyntectConfig, pub syntect: SyntectConfig,
pub escape: bool,
#[serde(rename = "unsafe")]
pub unsafe_: bool,
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]

View file

@ -26,7 +26,11 @@ pub fn build_syntect(config: &RenderConfig) -> eyre::Result<SyntectAdapter> {
Ok(builder.build()) 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(); let mut options = ComrakOptions::default();
options.extension.table = true; options.extension.table = true;
options.extension.autolink = true; options.extension.autolink = true;
@ -35,6 +39,8 @@ pub fn render(markdown: &str, syntect: Option<&dyn SyntaxHighlighterAdapter>) ->
options.extension.strikethrough = true; options.extension.strikethrough = true;
options.extension.multiline_block_quotes = true; options.extension.multiline_block_quotes = true;
options.extension.header_ids = Some(String::new()); options.extension.header_ids = Some(String::new());
options.render.escape = config.escape;
options.render.unsafe_ = config.unsafe_;
let mut render_plugins = RenderPlugins::default(); let mut render_plugins = RenderPlugins::default();
render_plugins.codefence_syntax_highlighter = syntect; render_plugins.codefence_syntax_highlighter = syntect;

View file

@ -117,7 +117,7 @@ impl MarkdownPosts {
let parsing = parsing_start.elapsed(); let parsing = parsing_start.elapsed();
let before_render = Instant::now(); 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(); let rendering = before_render.elapsed();
if let Some(cache) = &self.cache { if let Some(cache) = &self.cache {