Skip to content

Commit b665f0b

Browse files
only21milcodex
andauthored
fix(web): recognize plain text aliases in code fences (#23446)
Co-authored-by: GPT-6.1 Sol <[email protected]>
1 parent 9522c7d commit b665f0b

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect, it } from "vite-plus/test";
2+
3+
import { codeLanguageEntry, languageOfInfoString } from "./composer-code-languages";
4+
5+
it("recognizes plain-text fence info strings without treating metadata as the language", () => {
6+
const entries = ["Text", "TEXT", "plaintext", "txt"].map((language) =>
7+
codeLanguageEntry(languageOfInfoString(` ${language} title=notes.txt`)),
8+
);
9+
10+
expect(entries).toEqual(Array.from({ length: 4 }, () => ({ id: "", label: "Plain text" })));
11+
});

‎apps/web/src/composer-code-languages.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ const LANGUAGE_ALIASES: Record<string, string> = {
4747
"c++": "cpp",
4848
js: "javascript",
4949
md: "markdown",
50+
plaintext: "",
5051
py: "python",
5152
rb: "ruby",
5253
rs: "rust",
5354
sh: "bash",
5455
shell: "bash",
56+
text: "",
5557
ts: "typescript",
58+
txt: "",
5659
yml: "yaml",
5760
};
5861

@@ -69,7 +72,7 @@ export function withInfoStringLanguage(info: string, language: string): string {
6972
}
7073

7174
export function codeLanguageEntry(language: string): CodeBlockLanguage | null {
72-
const id = language === "text" ? "" : (LANGUAGE_ALIASES[language.toLowerCase()] ?? language);
75+
const id = LANGUAGE_ALIASES[language.toLowerCase()] ?? language;
7376
return CODE_BLOCK_LANGUAGES.find((entry) => entry.id === id.toLowerCase()) ?? null;
7477
}
7578

0 commit comments

Comments
 (0)