add more render options
This commit is contained in:
parent
ed74e84932
commit
1378fb4033
4 changed files with 19 additions and 5 deletions
11
CONFIG.md
11
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
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -26,7 +26,11 @@ pub fn build_syntect(config: &RenderConfig) -> eyre::Result<SyntectAdapter> {
|
|||
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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue