Skip to content

Commit

Permalink
fix: #249
Browse files Browse the repository at this point in the history
  • Loading branch information
taoqf committed Sep 8, 2023
1 parent 4a5f6b4 commit 5a0a795
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/nodes/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ export default class HTMLElement extends Node {
* @return {string} text content
*/
public get rawText() {
// https://github.com/taoqf/node-html-parser/issues/249
if (/br/i.test(this.rawTagName)) {
return '\n';
}
return this.childNodes.reduce((pre, cur) => {
return (pre += cur.rawText);
}, '');
Expand Down
11 changes: 11 additions & 0 deletions test/tests/issues/249.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { parse } = require('@test/test-target');

describe.only('issue 244', function () {
it('br in innertext should turn into \\n', function () {
const html = `<div>Hello<br>World</div>`;
const root = parse(html);
const div = root.querySelector('div');
div.innerText.should.eql(`Hello
World`);
});
});

0 comments on commit 5a0a795

Please sign in to comment.