@devries-cameron20 / t3code Mirror · read-only / commits / 9c7618ba1c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 18:30 UTC

fix(web): gitignore fences in the rich-text composer highlight as ini, as chat does (#35603)

Julius Marminge committed Nov 12, 2026 at 13:51 UTC 9c7618ba1cdbf88f775c1d9f70bc1f38eaf1b8e0
3 files changed +17 -8
apps/web/src/components/chat/MarkdownCodeBlock.logic.ts
+5 -2
@@ -7,9 +7,12 @@ const CODE_FENCE_LANGUAGE_REGEX = /(?:^|\s)language-([^\s]+)/;
7
8 export function extractFenceLanguage(className: string | undefined): string {
9 const match = className?.match(CODE_FENCE_LANGUAGE_REGEX);
10 - const raw = match?.[1] ?? "text";
10 + return highlighterLanguageOf(match?.[1] ?? "text");
11 +}
12 +
13 +export function highlighterLanguageOf(language: string): string {
14 // Shiki doesn't bundle a gitignore grammar; ini is a close match.
12 - return raw === "gitignore" ? "ini" : raw;
15 + return language === "gitignore" ? "ini" : language;
16 }
17
18 const FENCE_TITLE_ATTR_REGEX = /(?:^|\s)(?:title|file(?:name)?)=(?:"([^"]+)"|'([^']+)'|(\S+))/i;
apps/web/src/components/composerCodeBlockHighlight.test.ts
+8 -4
@@ -45,7 +45,7 @@ describe("highlighting edited fences", () => {
45 vi.unstubAllGlobals();
46 });
47
48 - async function mountFence(text: string, resolveTheme = () => THEME) {
48 + async function mountFence(text: string, resolveTheme = () => THEME, language = "ts") {
49 vi.useFakeTimers();
50 const highlighter = fakeHighlighter((content) =>
51 content.startsWith("x") ? "#ff0000" : undefined,
@@ -60,9 +60,7 @@ describe("highlighting edited fences", () => {
60 ],
61 content: {
62 type: "doc",
63 - content: [
64 - { type: "codeBlock", attrs: { language: "ts" }, content: [{ type: "text", text }] },
65 - ],
63 + content: [{ type: "codeBlock", attrs: { language }, content: [{ type: "text", text }] }],
64 },
65 });
66 vi.stubGlobal("document", { documentElement: {} });
@@ -134,4 +132,10 @@ describe("highlighting edited fences", () => {
132 ]);
133 expect(fence.colored()).toEqual(["x".repeat(3_000), "x".repeat(3_000)]);
134 });
135 +
136 + it("highlights a gitignore fence with the ini grammar, as chat does", async () => {
137 + await mountFence("*.log\n!keep.log", () => THEME, 'gitignore title=".gitignore"');
138 +
139 + expect(vi.mocked(getSyntaxHighlighterPromise)).toHaveBeenLastCalledWith("ini");
140 + });
141 });
apps/web/src/components/composerCodeBlockHighlight.ts
+4 -2
@@ -6,6 +6,7 @@ import type { Node as ProseMirrorNode } from "@tiptap/pm/model";
6 import type { DiffThemeName } from "~/lib/diffRendering";
7 import { languageOfInfoString } from "~/composer-code-languages";
8 import { getSyntaxHighlighterPromise } from "~/lib/syntaxHighlighting";
9 +import { highlighterLanguageOf } from "./chat/MarkdownCodeBlock.logic";
10
11 interface HighlightedBlock {
12 readonly signature: string;
@@ -119,8 +120,9 @@ export function composerCodeBlockHighlight(options: {
120 void Promise.allSettled(
121 pending.map(async ({ node }) => {
122 // Stored info includes metadata after the language; Shiki needs only the name.
122 - const language =
123 - languageOfInfoString(String(node.attrs.language ?? "")) || "text";
123 + const language = highlighterLanguageOf(
124 + languageOfInfoString(String(node.attrs.language ?? "")) || "text",
125 + );
126 const signature = blockSignature(node, theme);
127 // Cache failure as plain text to clear retained colors.
128 const highlighter = await getSyntaxHighlighterPromise(language).catch(() => null);