mirror of
https://github.com/stablyai/orca.git
synced 2026-11-13 17:37:40 +00:00
68 lines
2.7 KiB
JavaScript
68 lines
2.7 KiB
JavaScript
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 [' {
|
|
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 preserve highlighted matches inside Markdown', () => {
|
|
assert.equal(
|
|
stripSearchExcerptMarkdown('**<mark>Privacy</mark> controls**'),
|
|
'<mark>Privacy</mark> controls'
|
|
)
|
|
assert.equal(
|
|
stripSearchExcerptMarkdown('[Open <mark>settings</mark>](https://example.com/settings)'),
|
|
'Open <mark>settings</mark>'
|
|
)
|
|
assert.equal(
|
|
stripSearchExcerptMarkdown('Use `<mark>git</mark> **status**`'),
|
|
'Use <mark>git</mark> **status**'
|
|
)
|
|
assert.equal(
|
|
stripSearchExcerptMarkdown('<mark>**Privacy controls**</mark>'),
|
|
'<mark>Privacy controls</mark>'
|
|
)
|
|
assert.equal(stripSearchExcerptMarkdown('<mark>`git status`</mark>'), '<mark>git status</mark>')
|
|
assert.equal(
|
|
stripSearchExcerptMarkdown('<mark>[Privacy controls](https://example.com/privacy)</mark>'),
|
|
'<mark>Privacy controls</mark>'
|
|
)
|
|
})
|
|
|
|
test('tag guards preserve malformed markup, protected code and highlighted matches', () => {
|
|
const cases = [
|
|
['<em>**bold**</em>', 'bold'],
|
|
['<> **bold**', '<> bold'],
|
|
['<<em>bold</em>', 'bold'],
|
|
['<tag\nattr>hello</tag>', 'hello'],
|
|
['`<em>**literal**</em>`', '<em>**literal**</em>'],
|
|
['<mark>**highlight**</mark>', '<mark>highlight</mark>'],
|
|
['<MARK>**highlight**</MARK>', '<MARK>highlight</MARK>'],
|
|
['[<label](https://example.com/a>)', '<label'],
|
|
['<a **bold**', '<a bold'],
|
|
['<mark><<<</mark>', '<mark><<<</mark>'],
|
|
['\\> <tag>text</tag>', '> text'],
|
|
['plain > text', 'plain > text'],
|
|
['<!>text', 'text'],
|
|
['<><', '<><'],
|
|
['<\0orca-search-code-99\0', '<'],
|
|
['Use <mark>[**unclosed**</mark>', 'Use <mark>[unclosed</mark>'],
|
|
['<span>[<em>text</em></span>', '[text'],
|
|
['Use `[**literal**` and **emphasis**', 'Use [**literal** and emphasis'],
|
|
['', '<mark>alt</mark>'],
|
|
['[[path]]', 'path'],
|
|
['[label][ref]', 'label'],
|
|
[']', ']']
|
|
]
|
|
for (const [input, expected] of cases) {
|
|
assert.equal(stripSearchExcerptMarkdown(input), expected, input)
|
|
}
|
|
})
|