import assert from 'node:assert/strict' import test from 'node:test' import { stripSearchExcerptMarkdown } from '../src/components/docs/search-excerpt.mjs' test('link destinations retain escaped closing parentheses and literal escapes', () => { for (const prefix of ['![label](', '[label](']) { assert.equal(stripSearchExcerptMarkdown(prefix + 'https://example.com/a\\)b)'), 'label') assert.equal(stripSearchExcerptMarkdown(prefix + 'https://example.com/a\\(b)'), 'label') assert.equal(stripSearchExcerptMarkdown(prefix + 'https://example.com/a\\)'), 'label') assert.equal(stripSearchExcerptMarkdown(prefix + 'https://example.com/a\\\\))'), 'label)') assert.equal(stripSearchExcerptMarkdown(prefix + 'https://example.com/a\\\nb)'), 'label') } }) test('search excerpts omit inline Markdown syntax', () => { assert.equal( stripSearchExcerptMarkdown( 'Use **bold**, *emphasis*, `inline code`, and [linked text](https://example.com).' ), 'Use bold, emphasis, inline code, and linked text.' ) }) test('search excerpts preserve highlighted matches inside Markdown', () => { assert.equal( stripSearchExcerptMarkdown('**Privacy controls**'), 'Privacy controls' ) assert.equal( stripSearchExcerptMarkdown('[Open settings](https://example.com/settings)'), 'Open settings' ) assert.equal( stripSearchExcerptMarkdown('Use `git **status**`'), 'Use git **status**' ) assert.equal( stripSearchExcerptMarkdown('**Privacy controls**'), 'Privacy controls' ) assert.equal(stripSearchExcerptMarkdown('`git status`'), 'git status') assert.equal( stripSearchExcerptMarkdown('[Privacy controls](https://example.com/privacy)'), 'Privacy controls' ) }) test('tag guards preserve malformed markup, protected code and highlighted matches', () => { const cases = [ ['**bold**', 'bold'], ['<> **bold**', '<> bold'], ['<bold', 'bold'], ['hello', 'hello'], ['`**literal**`', '**literal**'], ['**highlight**', 'highlight'], ['**highlight**', 'highlight'], ['[)', '<<<', '<<<'], ['\\> text', '> text'], ['plain > text', 'plain > text'], ['text', 'text'], ['<><', '<><'], ['<\0orca-search-code-99\0', '<'], ['Use [**unclosed**', 'Use [unclosed'], ['[text', '[text'], ['Use `[**literal**` and **emphasis**', 'Use [**literal** and emphasis'], ['![alt](url)', 'alt'], ['[[path]]', 'path'], ['[label][ref]', 'label'], [']', ']'] ] for (const [input, expected] of cases) { assert.equal(stripSearchExcerptMarkdown(input), expected, input) } })