File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff 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 ( / b r / i. test ( this . rawTagName ) ) {
253+ return '\n' ;
254+ }
251255 return this . childNodes . reduce ( ( pre , cur ) => {
252256 return ( pre += cur . rawText ) ;
253257 } , '' ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments