keep quotes and brackets outside the html() span, refs #1154
This commit is contained in:
1 parent
259bc70ea5
commit
398b3d626c
2 files changed
+18
-2
No files matched your search
@@ -60,11 +60,11 @@ const html = function (obj) {
|
|||||||
this.docs.forEach(terms => {
|
this.docs.forEach(terms => {
|
||||||
for (let i = 0; i < terms.length; i += 1) {
|
for (let i = 0; i < terms.length; i += 1) {
|
||||||
const t = terms[i]
|
const t = terms[i]
|
||||||
// do a span tag
|
out += t.pre || ''
|
||||||
|
// do a span tag, inside the pre-punctuation
|
||||||
if (Object.hasOwn(starts, t.id)) {
|
if (Object.hasOwn(starts, t.id)) {
|
||||||
out += starts[t.id].join('')
|
out += starts[t.id].join('')
|
||||||
}
|
}
|
||||||
out += t.pre || ''
|
|
||||||
out += t.text || ''
|
out += t.text || ''
|
||||||
if (Object.hasOwn(ends, t.id)) {
|
if (Object.hasOwn(ends, t.id)) {
|
||||||
out += ends[t.id].join('')
|
out += ends[t.id].join('')
|
||||||
|
|||||||
@@ -59,3 +59,19 @@ test('html-implicit', function (t) {
|
|||||||
t.equal(out, `he's cool`, here + 'implict')
|
t.equal(out, `he's cool`, here + 'implict')
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('html-punctuation', function (t) {
|
||||||
|
let doc = nlp(`This is a "test". Hello "World."`)
|
||||||
|
let html = doc.html({ '.red': '(test|world)' })
|
||||||
|
t.equal(html, `This is a "<span class="red">test</span>". Hello "<span class="red">World</span>."`, here + 'quotes')
|
||||||
|
|
||||||
|
doc = nlp(`he said "hello world" twice`)
|
||||||
|
html = doc.html({ '.red': 'hello world' })
|
||||||
|
t.equal(html, `he said "<span class="red">hello world</span>" twice`, here + 'quoted phrase')
|
||||||
|
|
||||||
|
doc = nlp(`my dog (spot) is cute`)
|
||||||
|
html = doc.html({ '.red': 'spot' })
|
||||||
|
t.equal(html, `my dog (<span class="red">spot</span>) is cute`, here + 'parentheses')
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
Reference in new issue
Block a user