diff --git a/src/nodes/html.ts b/src/nodes/html.ts index 6d60587..6a814a2 100644 --- a/src/nodes/html.ts +++ b/src/nodes/html.ts @@ -1022,7 +1022,9 @@ export function base_parse(data: string, options = {} as Partial) { style: true, pre: true, }; - const element_names = Object.keys(elements); + const element_names = Object.keys(elements).filter((name) => { + return Boolean(elements[name]); + }); const kBlockTextElements = element_names.map((it) => new RegExp(`^${it}$`, 'i')); const kIgnoreElements = element_names.filter((it) => elements[it]).map((it) => new RegExp(`^${it}$`, 'i')); diff --git a/test/tests/issues/242.js b/test/tests/issues/242.js index 231ee98..21065fd 100644 --- a/test/tests/issues/242.js +++ b/test/tests/issues/242.js @@ -1,6 +1,6 @@ const { parse } = require('@test/test-target'); -describe('issue 242', function () { +describe.only('issue 242', function () { it(`a.rawAttrs returns 'href="/" rel="home"' but a.getAttribute("href') returns undefined`, function () { const html = `
Git Hub
`; const root = parse(html); @@ -10,4 +10,20 @@ describe('issue 242', function () { a.rawAttrs.should.eql('href="/" rel="home"'); a.getAttribute('href').should.eql('/'); }); + it(`get code`, function () { + const html = `
+  test
+
`; + const root = parse(html, { + blockTextElements: { + script: true, + noscript: true, + style: true, + pre: false + } + }); + const list = root.getElementsByTagName("code"); + const [code] = list; + code.text.should.eql('test'); + }); });