Skip to content

Commit

Permalink
Merge pull request #35 from remarkablemark/decode-entities
Browse files Browse the repository at this point in the history
Decode HTML entities by default on node
  • Loading branch information
remarkablemark authored Jan 26, 2017
2 parents 99870f3 + 68a5169 commit 1d6bf11
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
var domToReact = require('./lib/dom-to-react');
var htmlToDOM = require('html-dom-parser');

// decode HTML entities by default for `htmlparser2`
var domParserOptions = { decodeEntities: true };

/**
* Convert HTML string to React elements.
*
Expand All @@ -18,7 +21,7 @@ function HTMLReactParser(html, options) {
if (typeof html !== 'string') {
throw new TypeError('First argument must be a string');
}
return domToReact(htmlToDOM(html), options);
return domToReact(htmlToDOM(html, domParserOptions), options);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions test/html-to-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ describe('html-to-react', function() {
assert.equal(render(reactElement), svg);
});

it('decodes HTML entities', function() {
var encodedEntities = 'asdf & ÿ ü '';
var decodedEntities = 'asdf & ÿ ü \'';
var reactElement = Parser('<i>' + encodedEntities + '</i>');
assert.equal(reactElement.props.children, decodedEntities);
});

});

/**
Expand Down

0 comments on commit 1d6bf11

Please sign in to comment.