feat: add TUI code block syntax highlighting (#1200) (thanks @vignesh07)

This commit is contained in:
Peter Steinberger
2026-01-19 05:05:36 +00:00
parent 640e19988f
commit 3e06fe84dc
3 changed files with 4 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ Docs: https://docs.clawd.bot
### Changes
- Usage: add `/usage cost` summaries and macOS menu cost submenu with daily charting.
- Agents: clarify node_modules read-only guidance in agent instructions.
- TUI: add syntax highlighting for code blocks. (#1200) — thanks @vignesh07.
### Fixes
- Plugins: surface plugin load/register/config errors in gateway logs with plugin/source context.

View File

@@ -102,7 +102,8 @@ console.log(message);`;
const result = markdownTheme.highlightCode!(code, "javascript");
// Strip ANSI codes to verify content is preserved
const stripAnsi = (str: string) => str.replace(/\x1b\[[0-9;]*m/g, "");
const stripAnsi = (str: string) =>
str.replace(new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g"), "");
expect(stripAnsi(result[0])).toBe(`const message = "Hello, World!";`);
expect(stripAnsi(result[1])).toBe("console.log(message);");
});

View File

@@ -88,6 +88,7 @@ const syntaxTheme = {
*/
function highlightCode(code: string, lang?: string): string[] {
try {
// Auto-detect can be slow for very large blocks; prefer explicit language when available.
// Check if language is supported, fall back to auto-detect
const language = lang && supportsLanguage(lang) ? lang : undefined;
const highlighted = highlight(code, {