Skip to content

Commit fb60dcb

Browse files
committed
fix(cli): clean up code redundancies and improve markdown rendering
- Simplify marginTop ternary logic - Don't trim markdown content to preserve paragraph spacing - Only strip trailing newlines from markdown output, not all whitespace
1 parent b541cfd commit fb60dcb

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

cli/src/components/message-block.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,22 +437,20 @@ export const MessageBlock = ({
437437
{blocks.map((block, idx) => {
438438
if (block.type === 'text') {
439439
const isStreamingText = isLoading || !isComplete
440+
const hasMarkdownContent = hasMarkdown(block.content)
440441
const rawContent = isStreamingText
441442
? trimTrailingNewlines(block.content)
442-
: block.content.trim()
443+
: hasMarkdownContent
444+
? block.content
445+
: block.content.trim()
443446
const renderKey = `${messageId}-text-${idx}`
444-
const renderedContent = hasMarkdown(rawContent)
447+
const renderedContent = hasMarkdownContent
445448
? isStreamingText
446449
? renderStreamingMarkdown(rawContent, markdownOptions)
447450
: renderMarkdown(rawContent, markdownOptions)
448451
: rawContent
449452
const prevBlock = idx > 0 ? blocks[idx - 1] : null
450-
const marginTop =
451-
prevBlock && prevBlock.type === 'text'
452-
? 1
453-
: prevBlock && (prevBlock.type === 'tool' || prevBlock.type === 'agent')
454-
? 0
455-
: 0
453+
const marginTop = prevBlock && prevBlock.type === 'text' ? 1 : 0
456454
const blockTextColor = block.color ?? textColor
457455
return (
458456
<text key={renderKey} style={{ fg: blockTextColor, marginTop }}>

cli/src/utils/markdown-renderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export function renderMarkdown(
152152
void palette // Keep signature compatibility for future color styling
153153

154154
const ast = processor.parse(markdown)
155-
const text = nodeToPlainText(ast).replace(/\s+$/g, '')
155+
const text = nodeToPlainText(ast).replace(/\n+$/g, '')
156156
return text
157157
} catch (error) {
158158
logger.error(error, 'Failed to parse markdown')

0 commit comments

Comments
 (0)