diff --git a/src/nodes/html.ts b/src/nodes/html.ts index 853f02c..20a86e0 100644 --- a/src/nodes/html.ts +++ b/src/nodes/html.ts @@ -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); }, ''); diff --git a/test/tests/issues/249.js b/test/tests/issues/249.js new file mode 100644 index 0000000..3c4c1f2 --- /dev/null +++ b/test/tests/issues/249.js @@ -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 = `