-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathcontent-renderer.spec.ts
More file actions
78 lines (70 loc) · 2.93 KB
/
content-renderer.spec.ts
File metadata and controls
78 lines (70 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* @fileoverview Unit tests for content-renderer
* Regression tests for markdown rendering with angle brackets in code blocks
* @see https://github.com/eyaltoledano/claude-task-master/issues/1562
*/
import { describe, expect, it } from 'vitest';
import { renderContent } from './content-renderer.js';
describe('renderContent', () => {
it('should return empty string for empty input', () => {
expect(renderContent('')).toBe('');
});
it('should render plain markdown without corruption', () => {
const input = '## Heading\\n\\nSome paragraph text.';
const result = renderContent(input);
// Should contain the heading text and paragraph — not be empty or corrupted
expect(result).toContain('Heading');
expect(result).toContain('Some paragraph text');
});
it('should not treat angle brackets inside fenced code blocks as HTML (issue #1562)', () => {
const input =
'## Implementation\\n\\n```tsx\\nexport function Component() {\\n return <Navigate to="/" replace />\\n}\\n```';
const result = renderContent(input);
// The key assertion: the output should still contain "Implementation" as a
// recognizable section and should NOT collapse into a single mangled line.
expect(result).toContain('Implementation');
// The code content should be preserved (Navigate component reference)
expect(result).toContain('Navigate');
});
it('should not treat angle brackets inside inline code as HTML', () => {
const input = 'Use the `<Navigate>` component for redirects.';
const result = renderContent(input);
expect(result).toContain('Navigate');
expect(result).toContain('redirects');
});
it('should still convert actual HTML content to markdown', () => {
const input = '<h1>Title</h1><p>Paragraph</p>';
const result = renderContent(input);
// Turndown should have converted this to markdown, then marked-terminal renders it
expect(result).toContain('Title');
expect(result).toContain('Paragraph');
});
it('should handle mixed markdown with code blocks containing multiple angle brackets', () => {
const input = [
'## Current State\\n\\n',
'The PRD mentions `RequireGuest` route guard.\\n\\n',
'```tsx\\n',
'function App() {\\n',
' return (\\n',
' <BrowserRouter>\\n',
' <Routes>\\n',
' <Route path="/" element={<Home />} />\\n',
' </Routes>\\n',
' </BrowserRouter>\\n',
' );\\n',
'}\\n',
'```'
].join('');
const result = renderContent(input);
// Should render the heading and prose properly, not collapse into one line
expect(result).toContain('Current State');
expect(result).toContain('RequireGuest');
});
it('should handle content with angle brackets outside code blocks as HTML', () => {
// Real HTML mixed with text (not inside code blocks) should still be converted
const input = 'Some text <strong>bold</strong> more text';
const result = renderContent(input);
expect(result).toContain('bold');
expect(result).toContain('more text');
});
});