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

Decode text nodes before passing to React #18

Merged
merged 32 commits into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
09b9c06
Add editorconfig
aknuds1 Dec 11, 2015
0b28469
Fix React warnings
aknuds1 Dec 11, 2015
93a59d4
Fix rendering
aknuds1 Dec 11, 2015
db4ddb3
Unescape HTML entities in text
aknuds1 Dec 11, 2015
d51b824
Fix regressions
aknuds1 Dec 12, 2015
562ea83
Add tests
aknuds1 Dec 12, 2015
f2cc4ef
Replace lodash with Ramda/underscore.string.fp
aknuds1 Jan 17, 2016
c88ac0f
Update React
aknuds1 Jan 17, 2016
e4e598d
Handle undefineds
aknuds1 Jan 17, 2016
e0aa144
Merge branch 'master' of https://github.com/mikenikles/html-to-react
aknuds1 Feb 3, 2016
6784093
Don't create children for br tags
aknuds1 Feb 3, 2016
5f28222
Merge branch 'br-tags'
aknuds1 Feb 3, 2016
080675f
Clean up
aknuds1 Feb 3, 2016
8e97329
React is not dev dep
aknuds1 Feb 3, 2016
a9987c7
Fix attributes
aknuds1 Feb 3, 2016
3db0abc
Decode text nodes before passing to React
aknuds1 Feb 3, 2016
6d92eaa
Add test
aknuds1 Feb 3, 2016
faf826c
Add semicolon
aknuds1 Feb 3, 2016
63eacf0
Merge branch 'editorconfig'
aknuds1 Feb 3, 2016
87cbb4c
Merge branch 'decode-text'
aknuds1 Feb 3, 2016
71be53f
Add keys to React sequence items
aknuds1 Feb 3, 2016
813dfb4
Add test
aknuds1 Feb 3, 2016
27e7b8a
Apply index
aknuds1 Feb 3, 2016
ae5c28e
Merge branch 'child-keys'
aknuds1 Feb 3, 2016
21cc36e
Make code clearer
aknuds1 Feb 3, 2016
3e66d18
Add test for invalid nodes
aknuds1 Feb 3, 2016
1ac2377
Merge branch 'child-keys'
aknuds1 Feb 3, 2016
6a10d33
Merge branch 'master' into decode-text
aknuds1 Feb 8, 2016
1832c33
Merge branch 'master' of https://github.com/mikenikles/html-to-react
aknuds1 Apr 24, 2016
d39f3be
Merge branch 'master' into decode-text
aknuds1 Apr 24, 2016
72a2ae7
Revert "Merge branch 'master' into decode-text"
aknuds1 Apr 24, 2016
c365291
Merge branch 'master' of https://github.com/mikenikles/html-to-react …
aknuds1 Apr 25, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 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');

// https://github.com/facebook/react/blob/0.14-stable/src/renderers/dom/shared/ReactDOMComponent.js#L457
var voidElementTags = [
Expand Down Expand Up @@ -30,7 +31,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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
}
},
"dependencies": {
"ent": "^2.2.0",
"htmlparser2": "^3.8.3",
"lodash": "^3.9.3"
},
Expand Down
11 changes: 10 additions & 1 deletion test/html-to-react-tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var assert = require("assert");
var assert = require('assert');
var React = require('react');
var ReactDOMServer = require('react-dom/server')

Expand Down Expand Up @@ -131,6 +131,15 @@ describe('Html2React', function() {

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

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