Changesets · Branches · Tags · Compare
| Changeset | 177d3bbe4f2a2c63734c3c4fe630b52341d5060f69c6c8e45edf49dfd7d4c618 |
|---|---|
| Author | Nate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-09-10 14:50 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-09-10 14:50 -07:00 |
| Parents | b339f37e78ce, ac220e7e5ff5 |
2 files changed
added extensions/cli/src/ui/MarkdownRenderer.thinking.test.tsx +36 −0
| @@ -0,0 +1,36 @@ | ||
| 1 | +import { render } from "ink-testing-library"; | |
| 2 | +import React from "react"; | |
| 3 | + | |
| 4 | +import { MarkdownRenderer } from "./MarkdownRenderer.js"; | |
| 5 | + | |
| 6 | +describe("MarkdownRenderer - thinking tags", () => { | |
| 7 | + it("handles multiple thinking tags", () => { | |
| 8 | + const content = | |
| 9 | + "Text <think>First thought</think> middle <think>Second thought</think> end"; | |
| 10 | + const { lastFrame } = render(<MarkdownRenderer content={content} />); | |
| 11 | + | |
| 12 | + expect(lastFrame()).toContain("First thought"); | |
| 13 | + expect(lastFrame()).toContain("Second thought"); | |
| 14 | + }); | |
| 15 | + | |
| 16 | + it("handles thinking tags with multiline content", () => { | |
| 17 | + const content = `<think> | |
| 18 | + This is a multiline | |
| 19 | + thinking block | |
| 20 | + </think>`; | |
| 21 | + const { lastFrame } = render(<MarkdownRenderer content={content} />); | |
| 22 | + | |
| 23 | + expect(lastFrame()).toContain("This is a multiline"); | |
| 24 | + expect(lastFrame()).toContain("thinking block"); | |
| 25 | + }); | |
| 26 | + | |
| 27 | + it("ignores thinking tags inside code blocks", () => { | |
| 28 | + const content = "```\n<think>This should not be processed</think>\n```"; | |
| 29 | + const { lastFrame } = render(<MarkdownRenderer content={content} />); | |
| 30 | + | |
| 31 | + // The thinking tag should appear as literal text within the code block | |
| 32 | + expect(lastFrame()).toContain( | |
| 33 | + "<think>This should not be processed</think>", | |
| 34 | + ); | |
| 35 | + }); | |
| 36 | +}); |
modified extensions/cli/src/ui/MarkdownRenderer.tsx +11 −4
| @@ -2,10 +2,10 @@ | ||
| 2 | 2 | import React from "react"; |
| 3 | 3 | |
| 4 | 4 | import { |
| 5 | - highlightCode, | |
| 5 | + defaultTheme, | |
| 6 | 6 | detectLanguage, |
| 7 | + highlightCode, | |
| 7 | 8 | SyntaxHighlighterTheme, |
| 8 | - defaultTheme, | |
| 9 | 9 | } from "./SyntaxHighlighter.js"; |
| 10 | 10 | |
| 11 | 11 | interface MarkdownRendererProps { |
| @@ -28,6 +28,14 @@ | ||
| 28 | 28 | return null; // This will be handled separately |
| 29 | 29 | }, |
| 30 | 30 | }, |
| 31 | + { | |
| 32 | + regex: /<think>([\s\S]*?)<\/think>/g, | |
| 33 | + render: (content, key) => ( | |
| 34 | + <Text key={key} color="gray"> | |
| 35 | + {content.trim()} | |
| 36 | + </Text> | |
| 37 | + ), | |
| 38 | + }, | |
| 31 | 39 | { |
| 32 | 40 | regex: /^(#{1,6})\s+(.+)$/gm, |
| 33 | 41 | render: (content, key) => ( |
| @@ -225,6 +233,5 @@ | ||
| 225 | 233 | |
| 226 | 234 | MarkdownRenderer.displayName = "MarkdownRenderer"; |
| 227 | 235 | |
| 228 | -export { MarkdownRenderer }; | |
| 236 | +export { defaultTheme, MarkdownRenderer }; | |
| 229 | 237 | export type { SyntaxHighlighterTheme }; |
| 230 | -export { defaultTheme }; |