fix(ui-primitives): preserve raw HTML in text extraction

This commit is contained in:
_Kerman
2026-07-29 11:43:00 +08:00
parent 5939355b1a
commit 549315256a
6 changed files with 49 additions and 13 deletions

View File

@@ -34,10 +34,18 @@ describe('extractMarkdownPlainText', () => {
.toBe('First paragraph with a link and diagram.')
})
it('omits raw HTML and returns a useful fallback when no paragraph exists', () => {
const markdown = '<script>alert(1)</script>\n\n## Safe heading'
expect(extractMarkdownPlainText(markdown)).toBe('Safe heading')
expect(extractMarkdownPlainText(markdown, { mode: 'first-paragraph' })).toBe('Safe heading')
it('preserves raw HTML while removing Markdown presentation markup', () => {
const block = [
'<background-task-complete id="trajectory-ui-watch">',
'Command: pnpm test',
'Exit code: 0',
'</background-task-complete>',
].join('\n')
expect(extractMarkdownPlainText(block)).toBe(block)
expect(extractMarkdownPlainText('**Status:** <span data-state="ok">ready</span>'))
.toBe('Status: <span data-state="ok">ready</span>')
expect(extractMarkdownPlainText(block, { mode: 'first-paragraph' }))
.toBe('<background-task-complete id="trajectory-ui-watch">')
})
it('projects GFM tables, references, hard breaks, and block structure', () => {
@@ -54,7 +62,7 @@ describe('extractMarkdownPlainText', () => {
'[asset]: diagram.png',
].join('\n')
expect(extractMarkdownPlainText(markdown)).toBe([
'first second with diagram and visible',
'first second with diagram and <span>visible</span>',
'',
'Name\tValue',
'alpha\t1',