Skip to content

Commit

Permalink
Change Comrak options to thread local
Browse files Browse the repository at this point in the history
  • Loading branch information
lambda-fairy committed Aug 21, 2024
1 parent f0d11ce commit 5f6a9a4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
27 changes: 27 additions & 0 deletions docs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description = "Documentation for Maud."
edition = "2021"

[dependencies]
comrak = { version = "*", default-features = false }
comrak = { version = "*", default-features = false, features = ["syntect"] }
maud = { path = "../maud" }
serde_json = "*"
syntect = "*"
18 changes: 12 additions & 6 deletions docs/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use comrak::{
nodes::{AstNode, NodeHeading, NodeValue},
Arena, Options,
};
use std::{fs, io, path::Path};
use std::{fs, io, path::Path, rc::Rc};

pub struct Page<'a> {
pub title: Option<&'a AstNode<'a>>,
Expand Down Expand Up @@ -31,9 +31,15 @@ impl<'a> Page<'a> {
}
}

pub fn default_comrak_options() -> Options<'static> {
let mut options = Options::default();
options.extension.header_ids = Some("".to_string());
options.render.unsafe_ = true;
options
thread_local! {
static COMRAK_OPTIONS: Rc<Options<'static>> = Rc::new({
let mut options = Options::default();
options.extension.header_ids = Some("".to_string());
options.render.unsafe_ = true;
options
});
}

pub fn default_comrak_options() -> Rc<Options<'static>> {
COMRAK_OPTIONS.with(Rc::clone)
}

0 comments on commit 5f6a9a4

Please sign in to comment.