diff --git a/src/nodes/html.ts b/src/nodes/html.ts index c6d222a..a9b6b2e 100644 --- a/src/nodes/html.ts +++ b/src/nodes/html.ts @@ -249,7 +249,7 @@ export default class HTMLElement extends Node { */ public get rawText() { // https://github.com/taoqf/node-html-parser/issues/249 - if (/br/i.test(this.rawTagName)) { + if (/^br$/i.test(this.rawTagName)) { return '\n'; } return this.childNodes.reduce((pre, cur) => { diff --git a/test/tests/issues/254.js b/test/tests/issues/254.js new file mode 100644 index 0000000..de0226b --- /dev/null +++ b/test/tests/issues/254.js @@ -0,0 +1,10 @@ +const { parse } = require('@test/test-target'); + +describe('issue 254', function () { + it('abbr in innertext should not turn into \\n', function () { + const html = `
Hello World
`; + const root = parse(html); + const div = root.querySelector('div'); + div.innerText.should.eql(`Hello World`); + }); +});