diff --git a/Cargo.toml b/Cargo.toml index 44fc88e0..61749a89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ log = "0.4.17" memchr = "2.5.0" opener = "0.6.1" pulldown-cmark = { version = "0.9.3", default-features = false } -pathdiff = "0.2.1" regex = "1.8.1" serde = { version = "1.0.163", features = ["derive"] } serde_json = "1.0.96" @@ -41,6 +40,7 @@ topological-sort = "0.2.2" notify = { version = "6.1.1", optional = true } notify-debouncer-mini = { version = "0.4.1", optional = true } ignore = { version = "0.4.20", optional = true } +pathdiff = { version = "0.2.1", optional = true } # Serve feature futures-util = { version = "0.3.28", optional = true } @@ -61,7 +61,7 @@ walkdir = "2.3.3" [features] default = ["watch", "serve", "search"] -watch = ["dep:notify", "dep:notify-debouncer-mini", "dep:ignore"] +watch = ["dep:notify", "dep:notify-debouncer-mini", "dep:ignore", "dep:pathdiff"] serve = ["dep:futures-util", "dep:tokio", "dep:warp"] search = ["dep:elasticlunr-rs", "dep:ammonia"] diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 6e08203b..9f5277f5 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -939,8 +939,9 @@ fn add_playground_pre( /// Modifies all `` blocks to convert "hidden" lines and to wrap them in /// a ``. fn hide_lines(html: &str, code_config: &Code) -> String { - let language_regex = Regex::new(r"\blanguage-(\w+)\b").unwrap(); - let hidelines_regex = Regex::new(r"\bhidelines=(\S+)").unwrap(); + static LANGUAGE_REGEX: Lazy = Lazy::new(|| Regex::new(r"\blanguage-(\w+)\b").unwrap()); + static HIDELINES_REGEX: Lazy = Lazy::new(|| Regex::new(r"\bhidelines=(\S+)").unwrap()); + CODE_BLOCK_RE .replace_all(html, |caps: &Captures<'_>| { let text = &caps[1]; @@ -955,12 +956,12 @@ fn hide_lines(html: &str, code_config: &Code) -> String { ) } else { // First try to get the prefix from the code block - let hidelines_capture = hidelines_regex.captures(classes); + let hidelines_capture = HIDELINES_REGEX.captures(classes); let hidelines_prefix = match &hidelines_capture { Some(capture) => Some(&capture[1]), None => { // Then look up the prefix by language - language_regex.captures(classes).and_then(|capture| { + LANGUAGE_REGEX.captures(classes).and_then(|capture| { code_config.hidelines.get(&capture[1]).map(|p| p.as_str()) }) } diff --git a/src/renderer/html_handlebars/helpers/navigation.rs b/src/renderer/html_handlebars/helpers/navigation.rs index 86b240ba..12c69027 100644 --- a/src/renderer/html_handlebars/helpers/navigation.rs +++ b/src/renderer/html_handlebars/helpers/navigation.rs @@ -103,7 +103,7 @@ fn find_chapter( } } - previous = Some(item.clone()); + previous = Some(item); } _ => continue, }