Skip to content

Commit

Permalink
fix: block text elements #242
Browse files Browse the repository at this point in the history
  • Loading branch information
taoqf committed Sep 8, 2023
1 parent f656c7b commit 97e593c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/nodes/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,9 @@ export function base_parse(data: string, options = {} as Partial<Options>) {
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'));

Expand Down
18 changes: 17 additions & 1 deletion test/tests/issues/242.js
Original file line number Diff line number Diff line change
@@ -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 = `<div><a href="/" rel="home">Git Hub</a></div>`;
const root = parse(html);
Expand All @@ -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 = `<pre>
<code>test</code>
</pre>`;
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');
});
});

0 comments on commit 97e593c

Please sign in to comment.