Skip to content

Commit 5a0a795

Browse files
committed
fix: #249
1 parent 4a5f6b4 commit 5a0a795

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/nodes/html.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ export default class HTMLElement extends Node {
248248
* @return {string} text content
249249
*/
250250
public get rawText() {
251+
// https://github.com/taoqf/node-html-parser/issues/249
252+
if (/br/i.test(this.rawTagName)) {
253+
return '\n';
254+
}
251255
return this.childNodes.reduce((pre, cur) => {
252256
return (pre += cur.rawText);
253257
}, '');

test/tests/issues/249.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { parse } = require('@test/test-target');
2+
3+
describe.only('issue 244', function () {
4+
it('br in innertext should turn into \\n', function () {
5+
const html = `<div>Hello<br>World</div>`;
6+
const root = parse(html);
7+
const div = root.querySelector('div');
8+
div.innerText.should.eql(`Hello
9+
World`);
10+
});
11+
});

0 commit comments

Comments
 (0)