Skip to content

Commit

Permalink
Merge pull request #1077 from ryancasburn-KAI/html-fix
Browse files Browse the repository at this point in the history
Html fix
  • Loading branch information
spencermountain committed Jan 5, 2024
2 parents f92b993 + a84129d commit f483252
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/1-one/output/api/html.js
@@ -1,12 +1,12 @@
const isClass = /^\../
const isId = /^#./

const escapeXml = (str) => {
const escapeXml = str => {
str = str.replace(/&/g, '&')
str = str.replace(/</g, '&lt;')
str = str.replace(/>/g, '&gt;')
str = str.replace(/"/g, '&quot;')
str = str.replace(/'/g, '&apos;');
str = str.replace(/'/g, '&apos;')
return str
}

Expand Down Expand Up @@ -64,7 +64,8 @@ const html = function (obj) {
if (starts.hasOwnProperty(t.id)) {
out += starts[t.id].join('')
}
out += t.pre || '' + t.text || ''
out += t.pre || ''
out += t.text || ''
if (ends.hasOwnProperty(t.id)) {
out += ends[t.id].join('')
}
Expand All @@ -73,4 +74,4 @@ const html = function (obj) {
})
return out
}
export default { html }
export default { html }
13 changes: 11 additions & 2 deletions tests/one/output/html.test.js
Expand Up @@ -18,14 +18,23 @@ test('html-match', function (t) {
doc = nlp(`one match two.`)
html = doc.html({ '.red': 'match+', '.blue': doc.match('two') })
t.equal(html, `one <span class="red">match</span> <span class="blue">two</span>.`, here + 'html two classes')

doc = nlp(`if i can recall, my grey dog loves pizza crusts (they are really good).`)
html = doc.html({ '.red': 'my grey dog', '.blue': doc.match('loves') })
t.equal(
html,
`if i can recall, <span class="red">my grey dog</span> <span class="blue">loves</span> pizza crusts (they are really good).`,
here + 'html pre test'
)

t.end()
})

test('html-nest', function (t) {
let doc = nlp(`one match two.`)
let html = doc.html({
i: 'match',
b: 'one match two'
b: 'one match two',
})
t.equal(html, `<b>one <i>match</i> two</b>.`, here + 'easy nest')

Expand All @@ -49,4 +58,4 @@ test('html-implicit', function (t) {
let out = doc.html({ '.foo': '#Verb' })
t.equal(out, `he's cool`, here + 'implict')
t.end()
})
})

0 comments on commit f483252

Please sign in to comment.