@@ -9,7 +9,6 @@
99 */
1010
1111 import {
12- Markdown,
1312 SyntaxHighlight,
1413 type SyntaxHighlightTheme,
1514 } from "@cel-tui/components";
@@ -142,11 +141,15 @@ type ToolRenderLineKind =
142141 | "summary"
143142 | "error";
144143
145-interface HighlightedToolBodySpec {
144+type SyntaxThemeVariant = "markdown" | "shell";
145+
146+interface HighlightedBodySpec {
146147 /** Full raw source content to syntax-highlight. */
147148 text: string;
148149 /** Registered lextide language id. */
149150 language: string;
151+ /** Semantic theme variant for this highlighted content. */
152+ themeVariant: SyntaxThemeVariant;
150153 }
151154
152155 interface ToolBlockSpec {
@@ -157,7 +160,7 @@ interface ToolBlockSpec {
157160 /** Logical body lines for the tool block. */
158161 bodyLines: readonly ToolRenderLine[];
159162 /** Optional syntax-highlighted body rendered from the full unsplit source. */
160- highlightedBody?: HighlightedToolBodySpec;
163+ highlightedBody?: HighlightedBodySpec;
161164 /** Whether `/verbose` preview rules apply to the body. */
162165 previewBody: boolean;
163166 }
@@ -222,16 +225,25 @@ function renderUserMessage(msg: UserMessage, theme: Theme): Node {
222225 ]);
223226 }
224227
225-/** Render a markdown block with stable internal paragraph spacing. */
226-function renderMarkdownBlock(content: string): Node | null {
227- const children = Markdown(content).map((node) => {
228- if (node.type === "text" && node.content === "") {
229- return node;
230- }
231- return HStack({ padding: { x: 1 } }, [VStack({ flex: 1 }, [node])]);
232- });
228+/** Render a syntax-highlighted raw markdown block. */
229+function renderMarkdownTextBlock(content: string, theme: Theme): Node | null {
230+ if (content === "") {
231+ return null;
232+ }
233233
234- return children.length > 0 ? VStack({ gap: 0 }, children) : null;
234+ const children = getHighlightedBodyLines(
235+ {
236+ text: content,
237+ language: "markdown",
238+ themeVariant: "markdown",
239+ },
240+ theme,
241+ );
242+ if (children.length === 0) {
243+ return null;
244+ }
245+
246+ return HStack({ padding: { x: 1 } }, [VStack({ flex: 1 }, children)]);
235247 }
236248
237249 function getAssistantErrorMessage(
@@ -275,7 +287,7 @@ function renderAssistantContentBlock(
275287 opts: ConversationRenderOpts,
276288 ): Node | null {
277289 if (block.type === "text" && block.text) {
278- return renderMarkdownBlock(block.text);
290+ return renderMarkdownTextBlock(block.text, opts.theme);
279291 }
280292 if (block.type === "thinking" && block.thinking) {
281293 return renderThinkingBlock(block.thinking, opts);
@@ -388,7 +400,13 @@ type SyntaxThemeTokenColor = NonNullable<
388400 const graphemeSegmenter = new Intl.Segmenter(undefined, {
389401 granularity: "grapheme",
390402 });
391-const shellSyntaxThemeCache = new WeakMap<Theme, SyntaxThemeRegistration>();
403+const syntaxThemeCache: Record<
404+ SyntaxThemeVariant,
405+ WeakMap<Theme, SyntaxThemeRegistration>
406+> = {
407+ markdown: new WeakMap(),
408+ shell: new WeakMap(),
409+};
392410
393411 function colorToHex(color: Color | undefined): string | undefined {
394412 return color ? ANSI_COLOR_HEX[color] : undefined;
@@ -414,14 +432,11 @@ function pushSyntaxTokenColor(
414432 });
415433 }
416434
417-function getShellSyntaxTheme(theme: Theme): SyntaxThemeRegistration {
418- const cached = shellSyntaxThemeCache.get(theme);
419- if (cached) {
420- return cached;
421- }
422-
423- const tokenColors: SyntaxThemeTokenColor[] = [];
424- pushSyntaxTokenColor(tokenColors, ["comment", "quote"], theme.mutedText);
435+function pushShellSyntaxTokenColors(
436+ tokenColors: SyntaxThemeTokenColor[],
437+ theme: Theme,
438+): void {
439+ pushSyntaxTokenColor(tokenColors, "comment", theme.mutedText);
425440 pushSyntaxTokenColor(
426441 tokenColors,
427442 ["keyword", "storage"],
@@ -472,12 +487,47 @@ function getShellSyntaxTheme(theme: Theme): SyntaxThemeRegistration {
472487 ["entity.name.tag", "name", "tag"],
473488 theme.accentText,
474489 );
490+}
491+
492+function pushMarkdownSyntaxTokenColors(
493+ tokenColors: SyntaxThemeTokenColor[],
494+ theme: Theme,
495+): void {
496+ pushSyntaxTokenColor(tokenColors, "quote", theme.mutedText, "italic");
497+ pushSyntaxTokenColor(tokenColors, "section", theme.accentText, "bold");
498+ pushSyntaxTokenColor(
499+ tokenColors,
500+ "bullet",
501+ theme.secondaryAccentText,
502+ "bold",
503+ );
504+ pushSyntaxTokenColor(tokenColors, ["code", "string"], theme.diffAdded);
505+ pushSyntaxTokenColor(tokenColors, "link", theme.accentText, "underline");
506+ pushSyntaxTokenColor(tokenColors, "strong", undefined, "bold");
507+ pushSyntaxTokenColor(tokenColors, "emphasis", undefined, "italic");
508+}
509+
510+function getSyntaxTheme(
511+ theme: Theme,
512+ variant: SyntaxThemeVariant,
513+): SyntaxThemeRegistration {
514+ const cache = syntaxThemeCache[variant];
515+ const cached = cache.get(theme);
516+ if (cached) {
517+ return cached;
518+ }
519+
520+ const tokenColors: SyntaxThemeTokenColor[] = [];
521+ if (variant === "shell") {
522+ pushShellSyntaxTokenColors(tokenColors, theme);
523+ } else {
524+ pushMarkdownSyntaxTokenColors(tokenColors, theme);
525+ }
475526
476527 const syntaxTheme: SyntaxThemeRegistration = {
477- ...(colorToHex(theme.toolText) ? { fg: colorToHex(theme.toolText) } : {}),
478528 tokenColors,
479529 };
480- shellSyntaxThemeCache.set(theme, syntaxTheme);
530+ cache.set(theme, syntaxTheme);
481531 return syntaxTheme;
482532 }
483533
@@ -508,7 +558,7 @@ function splitHighlightedTextNode(
508558 return children;
509559 }
510560
511-function normalizeHighlightedToolLine(line: Node): Node {
561+function normalizeHighlightedLine(line: Node): Node {
512562 if (line.type !== "hstack") {
513563 return line;
514564 }
@@ -519,8 +569,8 @@ function normalizeHighlightedToolLine(line: Node): Node {
519569 return HStack(line.props, children);
520570 }
521571
522-function getHighlightedToolBodyLines(
523- spec: HighlightedToolBodySpec,
572+function getHighlightedBodyLines(
573+ spec: HighlightedBodySpec,
524574 theme: Theme,
525575 ): Node[] {
526576 if (spec.text === "") {
@@ -528,9 +578,9 @@ function getHighlightedToolBodyLines(
528578 }
529579
530580 const highlighted = SyntaxHighlight(spec.text, spec.language, {
531- theme: getShellSyntaxTheme(theme),
581+ theme: getSyntaxTheme(theme, spec.themeVariant),
532582 });
533- return highlighted.children.map((line) => normalizeHighlightedToolLine(line));
583+ return highlighted.children.map((line) => normalizeHighlightedLine(line));
534584 }
535585
536586 /** Render a single styled text node for a tool line. */
@@ -663,7 +713,7 @@ function renderToolBody(
663713 ): { body: Node | null; summary?: ToolRenderLine } {
664714 if (spec.highlightedBody) {
665715 return renderToolBodyFromNodes(
666- getHighlightedToolBodyLines(spec.highlightedBody, opts.theme),
716+ getHighlightedBodyLines(spec.highlightedBody, opts.theme),
667717 spec.previewBody,
668718 opts,
669719 );
@@ -720,6 +770,7 @@ function buildShellToolCallSpec(args: Record<string, unknown>): ToolBlockSpec {
720770 : {
721771 text: command,
722772 language: "bash",
773+ themeVariant: "shell",
723774 },
724775 previewBody: true,
725776 };