File tree 2 files changed +11
-1
lines changed
2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change 6
6
var domToReact = require ( './lib/dom-to-react' ) ;
7
7
var htmlToDOM = require ( 'html-dom-parser' ) ;
8
8
9
+ // decode HTML entities by default for `htmlparser2`
10
+ var domParserOptions = { decodeEntities : true } ;
11
+
9
12
/**
10
13
* Convert HTML string to React elements.
11
14
*
@@ -18,7 +21,7 @@ function HTMLReactParser(html, options) {
18
21
if ( typeof html !== 'string' ) {
19
22
throw new TypeError ( 'First argument must be a string' ) ;
20
23
}
21
- return domToReact ( htmlToDOM ( html ) , options ) ;
24
+ return domToReact ( htmlToDOM ( html , domParserOptions ) , options ) ;
22
25
}
23
26
24
27
/**
Original file line number Diff line number Diff line change @@ -78,6 +78,13 @@ describe('html-to-react', function() {
78
78
assert . equal ( render ( reactElement ) , svg ) ;
79
79
} ) ;
80
80
81
+ it ( 'decodes HTML entities' , function ( ) {
82
+ var encodedEntities = 'asdf & ÿ ü '' ;
83
+ var decodedEntities = 'asdf & ÿ ü \'' ;
84
+ var reactElement = Parser ( '<i>' + encodedEntities + '</i>' ) ;
85
+ assert . equal ( reactElement . props . children , decodedEntities ) ;
86
+ } ) ;
87
+
81
88
} ) ;
82
89
83
90
/**
You can’t perform that action at this time.
0 commit comments