From e357b681e134f23ff1d01685dd87dfc4a6fab920 Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Thu, 19 Mar 2026 21:47:35 +0000 Subject: [PATCH] Remove arborium-theme, convert mutations to markdown --- Cargo.lock | 1 - crates/bough-docs-cli/Cargo.toml | 1 - crates/bough-docs-cli/src/build.rs | 106 ++--------------------------- docs/config/javascript.md | 2 +- docs/config/python.md | 2 +- docs/config/typescript.md | 2 +- 6 files changed, 9 insertions(+), 105 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e491cd90..684aacea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -344,7 +344,6 @@ name = "bough-docs-cli" version = "0.0.2" dependencies = [ "arborium", - "arborium-theme", "bough-cli", "bough-core", "comrak", diff --git a/crates/bough-docs-cli/Cargo.toml b/crates/bough-docs-cli/Cargo.toml index 14eea2a6..5aeb5c7d 100644 --- a/crates/bough-docs-cli/Cargo.toml +++ b/crates/bough-docs-cli/Cargo.toml @@ -15,7 +15,6 @@ description = "Documentation site generator for bough" facet = { version = "0.44", features = ["doc"] } facet-core = "0.44" figue = "2" -arborium-theme = "2.16" arborium = { version = "2.16", features = ["lang-rust", "lang-javascript", "lang-typescript", "lang-python", "lang-toml", "lang-bash", "lang-json", "lang-html", "lang-css"] } comrak = { version = "0.36", default-features = false } tiny_http = "0.12" diff --git a/crates/bough-docs-cli/src/build.rs b/crates/bough-docs-cli/src/build.rs index 20ac00cf..5cf525da 100644 --- a/crates/bough-docs-cli/src/build.rs +++ b/crates/bough-docs-cli/src/build.rs @@ -226,11 +226,6 @@ fn render_page(page: &Page, toc_html: &str) -> String { a-in, a-ex {{ color: var(--col-bright-red); }} a-em {{ font-weight: bold; }} a-dr, a-rp, a-rx {{ color: var(--col-orange); }} - pre code del {{ text-decoration: none; border-bottom: 2px solid var(--col-red); }} - pre code ins {{ text-decoration: none; border-bottom: 2px solid var(--col-green); }} - .mutation-comparison {{ display: flex; gap: 1rem; }} - .mutation-before, .mutation-afters {{ flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.5rem; }} - .mutation-comparison pre {{ margin: 0; }} @@ -288,84 +283,6 @@ fn collect_md_files(dir: &Path) -> Vec { const CORPUS_DIR: &str = "corpus"; -fn highlight_with_diff( - hl: &mut Highlighter, - lang: &str, - source: &str, - diff_start: usize, - diff_end: usize, - diff_tag: &str, -) -> String { - use arborium::advanced::html_escape; - - let spans = hl.highlight_spans(lang, source).unwrap_or_default(); - let source = source.trim_end_matches('\n'); - - let mut sorted = spans; - sorted.sort_by(|a, b| a.start.cmp(&b.start).then_with(|| b.end.cmp(&a.end))); - - // (pos, is_start, tag) — None tag means diff marker - let mut events: Vec<(usize, bool, Option)> = Vec::new(); - - for span in &sorted { - if let Some(tag) = arborium_theme::tag_for_capture(&span.capture) { - let t = format!("a-{tag}"); - events.push((span.start as usize, true, Some(t.clone()))); - events.push((span.end as usize, false, Some(t))); - } - } - - events.push((diff_start, true, None)); - events.push((diff_end, false, None)); - - events.sort_by(|a, b| a.0.cmp(&b.0).then_with(|| a.1.cmp(&b.1))); - - let mut out = String::from("
");
-    let mut pos = 0;
-    let mut syntax_stack: Vec = Vec::new();
-
-    for (ep, is_start, tag) in &events {
-        let ep = (*ep).min(source.len());
-        if ep > pos {
-            out.push_str(&html_escape(&source[pos..ep]));
-            pos = ep;
-        }
-        match tag {
-            None => {
-                if let Some(t) = syntax_stack.last() {
-                    out.push_str(&format!(""));
-                }
-                if *is_start {
-                    out.push_str(&format!("<{diff_tag}>"));
-                } else {
-                    out.push_str(&format!(""));
-                }
-                if let Some(t) = syntax_stack.last() {
-                    out.push_str(&format!("<{t}>"));
-                }
-            }
-            Some(t) => {
-                if *is_start {
-                    out.push_str(&format!("<{t}>"));
-                    syntax_stack.push(t.clone());
-                } else {
-                    out.push_str(&format!(""));
-                    if let Some(idx) = syntax_stack.iter().rposition(|s| s == t) {
-                        syntax_stack.remove(idx);
-                    }
-                }
-            }
-        }
-    }
-
-    if pos < source.len() {
-        out.push_str(&html_escape(&source[pos..]));
-    }
-
-    out.push_str("
"); - out -} - #[derive(Deserialize)] struct CorpusMutation { mutant: CorpusMutant, @@ -408,7 +325,7 @@ fn kind_key(kind: &serde_json::Value) -> String { } } -fn make_mutation_reference(lang: &bough_core::LanguageId, hl: &mut Highlighter) -> String { +fn make_mutation_reference(lang: &bough_core::LanguageId) -> String { use std::collections::BTreeMap; use std::fmt::Write; @@ -491,11 +408,8 @@ fn make_mutation_reference(lang: &bough_core::LanguageId, hl: &mut Highlighter) let key = kind_to_key(&kind); if let Some(example) = best.get(&key) { - let before_html = highlight_with_diff( - hl, ext, &example.source, - example.span_start, example.span_end, "del", - ); - let _ = write!(out, "

Before

{before_html}

After

"); + let _ = writeln!(out, "### Before\n\n```{ext}\n{}\n```\n", example.source.trim_end()); + let _ = writeln!(out, "### After\n"); for sub in &example.substitutions { let mutated = format!( "{}{}{}", @@ -503,15 +417,8 @@ fn make_mutation_reference(lang: &bough_core::LanguageId, hl: &mut Highlighter) sub, &example.source[example.span_end..], ); - let ins_start = example.span_start; - let ins_end = example.span_start + sub.len(); - let after_html = highlight_with_diff( - hl, ext, &mutated, - ins_start, ins_end, "ins", - ); - let _ = write!(out, "{after_html}"); + let _ = writeln!(out, "```{ext}\n{}\n```\n", mutated.trim_end()); } - let _ = writeln!(out, "
\n"); } } @@ -560,12 +467,10 @@ pub fn build() { fs::write(reference_dir.join("reference.md"), reference_md) .expect("failed to write config reference"); - let mut hl = Highlighter::new(); - let mutations_dir = generated_dir.join("mutations"); fs::create_dir_all(&mutations_dir).expect("failed to create generated mutations dir"); for lang in bough_core::LanguageId::ALL { - let md = make_mutation_reference(lang, &mut hl); + let md = make_mutation_reference(lang); fs::write(mutations_dir.join(format!("{}.md", lang.slug())), md) .expect("failed to write mutation reference"); } @@ -585,6 +490,7 @@ pub fn build() { toc.push(gen_entry); } } + let mut hl = Highlighter::new(); let mut opts = Options::default(); opts.extension.table = true; diff --git a/docs/config/javascript.md b/docs/config/javascript.md index b142dd54..666f2427 100644 --- a/docs/config/javascript.md +++ b/docs/config/javascript.md @@ -1,5 +1,5 @@ +++ -title = "Configuing for JavaScript" +title = "JavaScript" +++ Include a `[lang.js]` section in your config with `include` and `exclude` globs. These control which files bough will attempt to mutate. diff --git a/docs/config/python.md b/docs/config/python.md index 012b4f96..b276bc5b 100644 --- a/docs/config/python.md +++ b/docs/config/python.md @@ -1,5 +1,5 @@ +++ -title = "Configuring for Python" +title = "Python" +++ Include a `[lang.py]` section in your config with `include` and `exclude` globs. These control which files bough will attempt to mutate. diff --git a/docs/config/typescript.md b/docs/config/typescript.md index de952b54..5d3c3957 100644 --- a/docs/config/typescript.md +++ b/docs/config/typescript.md @@ -1,5 +1,5 @@ +++ -title = "Configuing for TypeScript" +title = "TypeScript" +++ Include a `[lang.ts]` section in your config with `include` and `exclude` globs. These control which files bough will attempt to mutate. -- knotmirror 0.0.1