feat: add TUI code block syntax highlighting (#1200) (thanks @vignesh07)
This commit is contained in:
@@ -10,6 +10,7 @@ Docs: https://docs.clawd.bot
|
|||||||
### Changes
|
### Changes
|
||||||
- Usage: add `/usage cost` summaries and macOS menu cost submenu with daily charting.
|
- Usage: add `/usage cost` summaries and macOS menu cost submenu with daily charting.
|
||||||
- Agents: clarify node_modules read-only guidance in agent instructions.
|
- Agents: clarify node_modules read-only guidance in agent instructions.
|
||||||
|
- TUI: add syntax highlighting for code blocks. (#1200) — thanks @vignesh07.
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
- Plugins: surface plugin load/register/config errors in gateway logs with plugin/source context.
|
- Plugins: surface plugin load/register/config errors in gateway logs with plugin/source context.
|
||||||
|
|||||||
@@ -102,7 +102,8 @@ console.log(message);`;
|
|||||||
const result = markdownTheme.highlightCode!(code, "javascript");
|
const result = markdownTheme.highlightCode!(code, "javascript");
|
||||||
|
|
||||||
// Strip ANSI codes to verify content is preserved
|
// 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[0])).toBe(`const message = "Hello, World!";`);
|
||||||
expect(stripAnsi(result[1])).toBe("console.log(message);");
|
expect(stripAnsi(result[1])).toBe("console.log(message);");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ const syntaxTheme = {
|
|||||||
*/
|
*/
|
||||||
function highlightCode(code: string, lang?: string): string[] {
|
function highlightCode(code: string, lang?: string): string[] {
|
||||||
try {
|
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
|
// Check if language is supported, fall back to auto-detect
|
||||||
const language = lang && supportsLanguage(lang) ? lang : undefined;
|
const language = lang && supportsLanguage(lang) ? lang : undefined;
|
||||||
const highlighted = highlight(code, {
|
const highlighted = highlight(code, {
|
||||||
|
|||||||
Reference in New Issue
Block a user