mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-07-09 17:28:45 +00:00
fix(coding-agent): restore diff code block highlighting
Some checks are pending
CI / build-check-test (push) Waiting to run
Some checks are pending
CI / build-check-test (push) Waiting to run
closes #5092
This commit is contained in:
parent
1e168a89c5
commit
b85bf65678
3 changed files with 43 additions and 1 deletions
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed fenced `diff` code blocks and other highlight.js scopes to keep theme-aware syntax colors after the `cli-highlight` replacement ([#5092](https://github.com/earendil-works/pi/issues/5092)).
|
||||
|
||||
## [0.76.0] - 2026-05-27
|
||||
|
||||
### New Features
|
||||
|
|
|
|||
|
|
@ -1042,17 +1042,27 @@ function buildCliHighlightTheme(t: Theme): CliHighlightTheme {
|
|||
built_in: (s: string) => t.fg("syntaxType", s),
|
||||
literal: (s: string) => t.fg("syntaxNumber", s),
|
||||
number: (s: string) => t.fg("syntaxNumber", s),
|
||||
regexp: (s: string) => t.fg("syntaxString", s),
|
||||
string: (s: string) => t.fg("syntaxString", s),
|
||||
comment: (s: string) => t.fg("syntaxComment", s),
|
||||
doctag: (s: string) => t.fg("syntaxComment", s),
|
||||
meta: (s: string) => t.fg("muted", s),
|
||||
function: (s: string) => t.fg("syntaxFunction", s),
|
||||
title: (s: string) => t.fg("syntaxFunction", s),
|
||||
class: (s: string) => t.fg("syntaxType", s),
|
||||
type: (s: string) => t.fg("syntaxType", s),
|
||||
tag: (s: string) => t.fg("syntaxPunctuation", s),
|
||||
name: (s: string) => t.fg("syntaxKeyword", s),
|
||||
attr: (s: string) => t.fg("syntaxVariable", s),
|
||||
variable: (s: string) => t.fg("syntaxVariable", s),
|
||||
params: (s: string) => t.fg("syntaxVariable", s),
|
||||
operator: (s: string) => t.fg("syntaxOperator", s),
|
||||
punctuation: (s: string) => t.fg("syntaxPunctuation", s),
|
||||
emphasis: (s: string) => t.italic(s),
|
||||
strong: (s: string) => t.bold(s),
|
||||
link: (s: string) => t.underline(s),
|
||||
addition: (s: string) => t.fg("toolDiffAdded", s),
|
||||
deletion: (s: string) => t.fg("toolDiffRemoved", s),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { resetCapabilitiesCache, setCapabilities } from "@earendil-works/pi-tui";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { highlightCode, initTheme } from "../src/modes/interactive/theme/theme.ts";
|
||||
import { highlight, renderHighlightedHtml, supportsLanguage } from "../src/utils/syntax-highlight.ts";
|
||||
|
||||
describe("syntax highlight renderer", () => {
|
||||
|
|
@ -46,3 +48,29 @@ describe("syntax highlight renderer", () => {
|
|||
expect(rendered).toContain("[number:1]");
|
||||
});
|
||||
});
|
||||
|
||||
describe("theme syntax highlighting", () => {
|
||||
beforeEach(() => {
|
||||
setCapabilities({ images: null, trueColor: true, hyperlinks: false });
|
||||
initTheme("dark");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
resetCapabilitiesCache();
|
||||
});
|
||||
|
||||
it("colors diff additions and deletions in fenced diff blocks", () => {
|
||||
const lines = highlightCode("-old\n+new\n", "diff");
|
||||
|
||||
expect(lines[0]).toBe("\x1b[38;2;204;102;102m-old\x1b[39m");
|
||||
expect(lines[1]).toBe("\x1b[38;2;181;189;104m+new\x1b[39m");
|
||||
});
|
||||
|
||||
it("keeps cli-highlight default styled scopes mapped to theme styles", () => {
|
||||
expect(highlightCode("const re = /foo+/gi;", "javascript")[0]).toContain(
|
||||
"\x1b[38;2;206;145;120m/foo+/gi\x1b[39m",
|
||||
);
|
||||
expect(highlightCode("@decorator", "python")[0]).toBe("\x1b[38;2;128;128;128m@decorator\x1b[39m");
|
||||
expect(highlightCode("<div></div>", "html")[0]).toContain("\x1b[38;2;86;156;214mdiv\x1b[39m");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue