Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Merge 72a2ae7 into 3bf4bd4
Browse files Browse the repository at this point in the history
  • Loading branch information
aknuds1 committed Apr 24, 2016
2 parents 3bf4bd4 + 72a2ae7 commit 6e9ee15
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/process-node-definitions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var _ = require('lodash');
var ent = require('ent');

function createStyleJsonFromString(styleString) {
if (_.isNull(styleString) || _.isUndefined(styleString) || styleString === '') {
Expand All @@ -24,7 +25,7 @@ var ProcessNodeDefinitions = function(React) {

function processDefaultNode(node, children) {
if (node.type === 'text') {
return node.data;
return ent.decode(node.data);
} else if (node.type === 'comment') {
// FIXME: The following doesn't work as the generated HTML results in "<!-- This is a comment -->"
//return '<!-- ' + node.data + ' -->';
Expand Down Expand Up @@ -60,4 +61,3 @@ var ProcessNodeDefinitions = function(React) {
};

module.exports = ProcessNodeDefinitions;

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
}
},
"dependencies": {
"ent": "^2.2.0",
"htmlparser2": "^3.8.3",
"lodash": "^3.9.3"
},
Expand Down
15 changes: 12 additions & 3 deletions test/html-to-react-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ describe('Html2React', function() {
var parser = new Parser(React);

before(function() {
console.error = function(message) {
throw new Error(message);
};
console.error = function(message) {
throw new Error(message);
};
})

describe('parse valid HTML', function() {
Expand Down Expand Up @@ -101,6 +101,15 @@ describe('Html2React', function() {

assert.equal(reactHtml, htmlExpected);
});

it('should decode character entities in text nodes', function () {
var htmlInput = '<div>1 &lt; 2</div>';

var reactComponent = parser.parse(htmlInput);
var reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent);

assert.equal(reactHtml, htmlInput);
});
});

describe('parse invalid HTML', function() {
Expand Down

0 comments on commit 6e9ee15

Please sign in to comment.