From bb8f6b376d83a9b70406279c87ab8b163fb32a38 Mon Sep 17 00:00:00 2001
From: zfflxx <106017702+zfflxx@users.noreply.github.com>
Date: Mon, 7 Jul 2025 13:33:46 +0800
Subject: Fix nested markdown Rendering for table headers and rows #3331
 (#3362)

Co-authored-by: Ryan Fang <ryan.fang@gllue.com>
---
 packages/cli/src/ui/utils/MarkdownDisplay.test.tsx | 47 ++++++++++++++++++++++
 1 file changed, 47 insertions(+)

(limited to 'packages/cli/src/ui/utils/MarkdownDisplay.test.tsx')

diff --git a/packages/cli/src/ui/utils/MarkdownDisplay.test.tsx b/packages/cli/src/ui/utils/MarkdownDisplay.test.tsx
index 316c2d5d..9e0cb96c 100644
--- a/packages/cli/src/ui/utils/MarkdownDisplay.test.tsx
+++ b/packages/cli/src/ui/utils/MarkdownDisplay.test.tsx
@@ -232,6 +232,53 @@ But there's no separator line
       const { lastFrame } = renderNarrow();
       expect(lastFrame()).not.toBe('');
     });
+
+    it('should handle inline markdown in tables', () => {
+      // Test content from MarkdownDisplay.demo.tsx
+      const testContent = `
+# execSync vs spawn
+
+| Characteristic | \`execSync\` (Old Way) | \`spawn\` (New Way in PR) |
+|----------------|------------------------|---------------------------|
+| **Execution** | Synchronous (blocks everything) | Asynchronous (non-blocking) |
+| **I/O Handling** | Buffers entire output in memory | Streams data in chunks (memory efficient) |
+| **Security** | **Vulnerable to shell injection** | **Safe from shell injection** |
+| **Use Case** | Simple, quick commands with small, trusted... | Long-running processes, large I/O, and especially for running user-configur... |
+
+`;
+
+      const { lastFrame } = render(
+        <MarkdownDisplay
+          text={testContent}
+          isPending={false}
+          terminalWidth={120}
+        />,
+      );
+
+      const output = lastFrame();
+
+      // Check header
+      expect(output).toContain('execSync vs spawn');
+
+      // Check table headers - handle possible truncation
+      expect(output).toMatch(/Cha(racteristic)?/); // Match "Cha" or "Characteristic"
+      expect(output).toContain('execSync');
+      expect(output).toContain('spawn');
+
+      // Check table content - test keywords rather than full sentences
+      expect(output).toMatch(/Exe(cution)?/); // Match "Exe" or "Execution"
+      expect(output).toContain('Synchronous');
+      expect(output).toContain('Asynchronous');
+      expect(output).toMatch(/I\/O|Handling/); // Match "I/O" or "Handling"
+      expect(output).toContain('Buffers');
+      expect(output).toContain('Streams');
+      expect(output).toMatch(/Sec(urity)?/); // Match "Sec" or "Security"
+      expect(output).toContain('Vulnerable');
+      expect(output).toContain('Safe');
+      expect(output).toMatch(/Use|Case/); // Match "Use" or "Case"
+      expect(output).toContain('Simple');
+      expect(output).toContain('Long-running');
+    });
   });
 
   describe('Existing Functionality', () => {
-- 
cgit v1.2.3

