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:
@@ -978,6 +978,12 @@ function getCliHighlightTheme(t: Theme): CliHighlightTheme {
|
|||||||
export function highlightCode(code: string, lang?: string): string[] {
|
export function highlightCode(code: string, lang?: string): string[] {
|
||||||
// Validate language before highlighting to avoid stderr spam from cli-highlight
|
// Validate language before highlighting to avoid stderr spam from cli-highlight
|
||||||
const validLang = lang && supportsLanguage(lang) ? lang : undefined;
|
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 = {
|
const opts = {
|
||||||
language: validLang,
|
language: validLang,
|
||||||
ignoreIllegals: true,
|
ignoreIllegals: true,
|
||||||
@@ -1080,6 +1086,12 @@ export function getMarkdownTheme(): MarkdownTheme {
|
|||||||
highlightCode: (code: string, lang?: string): string[] => {
|
highlightCode: (code: string, lang?: string): string[] => {
|
||||||
// Validate language before highlighting to avoid stderr spam from cli-highlight
|
// Validate language before highlighting to avoid stderr spam from cli-highlight
|
||||||
const validLang = lang && supportsLanguage(lang) ? lang : undefined;
|
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 = {
|
const opts = {
|
||||||
language: validLang,
|
language: validLang,
|
||||||
ignoreIllegals: true,
|
ignoreIllegals: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user