fix(coding-agent): disable cli-highlight auto-detection for languageless code blocks

cli-highlight's auto-detection misidentifies prose as AppleScript,
LiveCodeServer, etc., coloring random English words (if, but, and, the,
that, is) as keywords. This happens when code blocks have no language
specified: fenced blocks without a language tag, indented code blocks,
or unclosed fences during streaming.

Skip auto-detection entirely and apply plain mdCodeBlock styling instead.
This commit is contained in:
Mario Zechner
2026-03-21 10:46:01 +01:00
parent 77db2e4c18
commit f90647ea8e

View File

@@ -978,6 +978,12 @@ function getCliHighlightTheme(t: Theme): CliHighlightTheme {
export function highlightCode(code: string, lang?: string): string[] {
// Validate language before highlighting to avoid stderr spam from cli-highlight
const validLang = lang && supportsLanguage(lang) ? lang : undefined;
// Skip highlighting when no valid language is specified. cli-highlight's
// auto-detection is unreliable and can misidentify prose as AppleScript,
// LiveCodeServer, etc., coloring random English words as keywords.
if (!validLang) {
return code.split("\n").map((line) => theme.fg("mdCodeBlock", line));
}
const opts = {
language: validLang,
ignoreIllegals: true,
@@ -1080,6 +1086,12 @@ export function getMarkdownTheme(): MarkdownTheme {
highlightCode: (code: string, lang?: string): string[] => {
// Validate language before highlighting to avoid stderr spam from cli-highlight
const validLang = lang && supportsLanguage(lang) ? lang : undefined;
// Skip highlighting when no valid language is specified. cli-highlight's
// auto-detection is unreliable and can misidentify prose as AppleScript,
// LiveCodeServer, etc., coloring random English words as keywords.
if (!validLang) {
return code.split("\n").map((line) => theme.fg("mdCodeBlock", line));
}
const opts = {
language: validLang,
ignoreIllegals: true,