Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Html fix #1077

Merged
merged 2 commits into from Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
})
})