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 {
248
248
* @return {string } text content
249
249
*/
250
250
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
+ }
251
255
return this . childNodes . reduce ( ( pre , cur ) => {
252
256
return ( pre += cur . rawText ) ;
253
257
} , '' ) ;
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