From b5069c90afb24bde42dd6c6b69c9636f11dcfca6 Mon Sep 17 00:00:00 2001 From: rcasburn Date: Fri, 5 Jan 2024 10:13:11 -0500 Subject: [PATCH 1/2] add failing test case --- tests/one/output/html.test.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/one/output/html.test.js b/tests/one/output/html.test.js index 2fde7292b..26968eaba 100644 --- a/tests/one/output/html.test.js +++ b/tests/one/output/html.test.js @@ -18,6 +18,15 @@ test('html-match', function (t) { doc = nlp(`one match two.`) html = doc.html({ '.red': 'match+', '.blue': doc.match('two') }) t.equal(html, `one match two.`, 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, my grey dog loves pizza crusts (they are really good).`, + here + 'html pre test' + ) + t.end() }) @@ -25,7 +34,7 @@ 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, `one match two.`, here + 'easy nest') @@ -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() -}) \ No newline at end of file +}) From a84129d0525e23e0a2ff0443a5bb027fd64826f5 Mon Sep 17 00:00:00 2001 From: rcasburn Date: Fri, 5 Jan 2024 10:13:45 -0500 Subject: [PATCH 2/2] implement fix --- src/1-one/output/api/html.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/1-one/output/api/html.js b/src/1-one/output/api/html.js index a44de9d77..f0889c124 100644 --- a/src/1-one/output/api/html.js +++ b/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, '>') str = str.replace(/"/g, '"') - str = str.replace(/'/g, '''); + str = str.replace(/'/g, ''') return str } @@ -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('') } @@ -73,4 +74,4 @@ const html = function (obj) { }) return out } -export default { html } \ No newline at end of file +export default { html }