Skip to content

Commit 1d6bf11

Browse files
Merge pull request #35 from remarkablemark/decode-entities
Decode HTML entities by default on node
2 parents 99870f3 + 68a5169 commit 1d6bf11

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
var domToReact = require('./lib/dom-to-react');
77
var htmlToDOM = require('html-dom-parser');
88

9+
// decode HTML entities by default for `htmlparser2`
10+
var domParserOptions = { decodeEntities: true };
11+
912
/**
1013
* Convert HTML string to React elements.
1114
*
@@ -18,7 +21,7 @@ function HTMLReactParser(html, options) {
1821
if (typeof html !== 'string') {
1922
throw new TypeError('First argument must be a string');
2023
}
21-
return domToReact(htmlToDOM(html), options);
24+
return domToReact(htmlToDOM(html, domParserOptions), options);
2225
}
2326

2427
/**

test/html-to-react.js

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ describe('html-to-react', function() {
7878
assert.equal(render(reactElement), svg);
7979
});
8080

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+
8188
});
8289

8390
/**

0 commit comments

Comments
 (0)