Skip to content

Commit 97e593c

Browse files
committed
fix: block text elements #242
1 parent f656c7b commit 97e593c

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/nodes/html.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,9 @@ export function base_parse(data: string, options = {} as Partial<Options>) {
10221022
style: true,
10231023
pre: true,
10241024
};
1025-
const element_names = Object.keys(elements);
1025+
const element_names = Object.keys(elements).filter((name) => {
1026+
return Boolean(elements[name]);
1027+
});
10261028
const kBlockTextElements = element_names.map((it) => new RegExp(`^${it}$`, 'i'));
10271029
const kIgnoreElements = element_names.filter((it) => elements[it]).map((it) => new RegExp(`^${it}$`, 'i'));
10281030

test/tests/issues/242.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { parse } = require('@test/test-target');
22

3-
describe('issue 242', function () {
3+
describe.only('issue 242', function () {
44
it(`a.rawAttrs returns 'href="/" rel="home"' but a.getAttribute("href') returns undefined`, function () {
55
const html = `<div><a href="/" rel="home">Git Hub</a></div>`;
66
const root = parse(html);
@@ -10,4 +10,20 @@ describe('issue 242', function () {
1010
a.rawAttrs.should.eql('href="/" rel="home"');
1111
a.getAttribute('href').should.eql('/');
1212
});
13+
it(`get code`, function () {
14+
const html = `<pre>
15+
<code>test</code>
16+
</pre>`;
17+
const root = parse(html, {
18+
blockTextElements: {
19+
script: true,
20+
noscript: true,
21+
style: true,
22+
pre: false
23+
}
24+
});
25+
const list = root.getElementsByTagName("code");
26+
const [code] = list;
27+
code.text.should.eql('test');
28+
});
1329
});

0 commit comments

Comments
 (0)