mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-26 10:26:26 +01:00
feat(markdown): add syntax colors to rendered code blocks
The block follows the theme now, but every token in it is one color. Add syntax highlighting, using the palette from the approved design. Render: add rehype-highlight and pass it to react-markdown. The plugin array sits at module scope, because react-markdown remounts the rendered tree when the array identity changes. That is the same hazard the remarkPlugins memo already guards against. Detection: `detect` is on, because most agent-authored fences carry no language tag and would never highlight without it. `subset` restricts detection to the languages agents actually post. highlight.js guesses badly on short snippets, and a wrong guess colors the whole block wrongly. Palette: eight `--code-syntax-*` aliases carry the roles. Each one points at a token that already exists and already has a `.dark` override, so a custom property resolves per mode at its use site and one definition covers both themes. The mapping is BORROWED, and this is the part to review. Paperclip has no syntax palette. `--status-task-icon-*` and `--chip-match-title-fg` name task-status and search-chip concerns. They were used because they are the only hues that carry a real per-mode value; the fixed `--status-task-*` hues go dim on the dark code surface. The coupling is confined to the alias block. Repointing those eight lines moves the whole palette, and no rule changes. A test asserts that the syntax rules never reference the borrowed tokens directly. Verified in both themes on a real task. Light resolves keyword #7c3aed, identifier oklch(0.145 0 0), function oklch(0.4 0.13 265), comment oklch(0.556 0 0). Dark resolves #9474f0, oklch(0.985 0 0), oklch(0.78 0.1 265), oklch(0.708 0 0). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8e927e6a1a
commit
bc1c6b7ddc
6 files changed
+242
-2
No files matched your search
@@ -68,3 +68,45 @@ describe("markdown code block styles", () => {
|
||||
expect(codeBlockActionStyle.backgroundColor).not.toContain("--muted");
|
||||
});
|
||||
});
|
||||
|
||||
describe("code syntax palette", () => {
|
||||
const aliases = [
|
||||
"--code-syntax-keyword",
|
||||
"--code-syntax-string",
|
||||
"--code-syntax-number",
|
||||
"--code-syntax-identifier",
|
||||
"--code-syntax-punctuation",
|
||||
"--code-syntax-comment",
|
||||
"--code-syntax-added",
|
||||
"--code-syntax-removed",
|
||||
];
|
||||
|
||||
it("defines every syntax role as an alias of an existing token", () => {
|
||||
for (const alias of aliases) {
|
||||
const declaration = new RegExp(`${alias}:\\s*var\\(--[a-z0-9_-]+\\)`, "i");
|
||||
expect(stylesheet, `${alias} must be defined as var(--existing-token)`).toMatch(declaration);
|
||||
}
|
||||
});
|
||||
|
||||
it("holds the borrowed-token coupling in the alias layer only", () => {
|
||||
// The syntax rules must reference the aliases, never the borrowed tokens
|
||||
// directly. That keeps repointing to a real palette a one-block edit.
|
||||
const syntaxRules = stylesheet.slice(stylesheet.indexOf(".paperclip-markdown :is(pre, code)"));
|
||||
|
||||
expect(syntaxRules).not.toContain("--status-task-icon-");
|
||||
expect(syntaxRules).not.toContain("--chip-match-title-fg");
|
||||
});
|
||||
|
||||
it("maps the highlight.js token classes the renderer emits", () => {
|
||||
for (const cls of [
|
||||
".hljs-keyword",
|
||||
".hljs-string",
|
||||
".hljs-number",
|
||||
".hljs-comment",
|
||||
".hljs-addition",
|
||||
".hljs-deletion",
|
||||
]) {
|
||||
expect(stylesheet, `${cls} must be mapped`).toContain(cls);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user