Skip to content

Commit 98cbafb

Browse files
fix(web): gitignore fences in the rich-text composer highlight as ini, as chat does
Fixes #35600 AI-assisted; verified with the tests and tools listed above.
1 parent bd4add5 commit 98cbafb

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎apps/web/src/components/chat/MarkdownCodeBlock.logic.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ const CODE_FENCE_LANGUAGE_REGEX = /(?:^|\s)language-([^\s]+)/;
77

88
export function extractFenceLanguage(className: string | undefined): string {
99
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 {
1114
// Shiki doesn't bundle a gitignore grammar; ini is a close match.
12-
return raw === "gitignore" ? "ini" : raw;
15+
return language === "gitignore" ? "ini" : language;
1316
}
1417

1518
const FENCE_TITLE_ATTR_REGEX = /(?:^|\s)(?:title|file(?:name)?)=(?:"([^"]+)"|'([^']+)'|(\S+))/i;

‎apps/web/src/components/composerCodeBlockHighlight.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { Node as ProseMirrorNode } from "@tiptap/pm/model";
66
import type { DiffThemeName } from "~/lib/diffRendering";
77
import { languageOfInfoString } from "~/composer-code-languages";
88
import { getSyntaxHighlighterPromise } from "~/lib/syntaxHighlighting";
9+
import { highlighterLanguageOf } from "./chat/MarkdownCodeBlock.logic";
910

1011
interface HighlightedBlock {
1112
readonly signature: string;
@@ -119,8 +120,9 @@ export function composerCodeBlockHighlight(options: {
119120
void Promise.allSettled(
120121
pending.map(async ({ node }) => {
121122
// 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+
);
124126
const signature = blockSignature(node, theme);
125127
// Cache failure as plain text to clear retained colors.
126128
const highlighter = await getSyntaxHighlighterPromise(language).catch(() => null);

0 commit comments

Comments
 (0)