├── .editorconfig ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── index.js ├── lib ├── camel-case-attribute-names.js ├── is-valid-node-definitions.js ├── parser.js ├── process-node-definitions.js ├── processing-instructions.js └── should-process-node-definitions.js ├── package.json └── test └── html-to-react-tests.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | insert_final_newline = true 7 | max_line_length = 100 8 | 9 | [*.js] 10 | indent_size = 4 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | .idea 4 | coverage 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 4 4 | - 5 5 | - 6 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [v1.0.0](https://github.com/mikenikles/html-to-react/tree/v1.0.0) 4 | 5 | [Full Changelog](https://github.com/mikenikles/html-to-react/compare/v0.1.0...v1.0.0) 6 | 7 | **Fixed bugs:** 8 | 9 | - Travis build fails due to a ReferenceError [\#11](https://github.com/mikenikles/html-to-react/issues/11) 10 | 11 | **Closed issues:** 12 | 13 | - Should not insert spans into tables even if there is white space [\#30](https://github.com/mikenikles/html-to-react/issues/30) 14 | - Img, br and hr tags produce warnings [\#29](https://github.com/mikenikles/html-to-react/issues/29) 15 | - using import instead of require [\#26](https://github.com/mikenikles/html-to-react/issues/26) 16 | - Cherry pick lodash [\#22](https://github.com/mikenikles/html-to-react/issues/22) 17 | - problem with textarea [\#9](https://github.com/mikenikles/html-to-react/issues/9) 18 | - Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method [\#7](https://github.com/mikenikles/html-to-react/issues/7) 19 | - State of the library? [\#6](https://github.com/mikenikles/html-to-react/issues/6) 20 | - best way to pass callbacks? [\#5](https://github.com/mikenikles/html-to-react/issues/5) 21 | 22 | **Merged pull requests:** 23 | 24 | - Treat textarea as a void element [\#33](https://github.com/mikenikles/html-to-react/pull/33) ([mikenikles](https://github.com/mikenikles)) 25 | - Clean up NPM scripts [\#32](https://github.com/mikenikles/html-to-react/pull/32) ([mikenikles](https://github.com/mikenikles)) 26 | - Pass through options to parser [\#27](https://github.com/mikenikles/html-to-react/pull/27) ([benjeffery](https://github.com/benjeffery)) 27 | - Use modularized lodash [\#25](https://github.com/mikenikles/html-to-react/pull/25) ([no23reason](https://github.com/no23reason)) 28 | - Test with node 4 and 5 on travis [\#24](https://github.com/mikenikles/html-to-react/pull/24) ([thangngoc89](https://github.com/thangngoc89)) 29 | - Fix npm test [\#21](https://github.com/mikenikles/html-to-react/pull/21) ([mikenikles](https://github.com/mikenikles)) 30 | - Create element keys per sequence [\#20](https://github.com/mikenikles/html-to-react/pull/20) ([aknuds1](https://github.com/aknuds1)) 31 | - Add editorconfig [\#19](https://github.com/mikenikles/html-to-react/pull/19) ([aknuds1](https://github.com/aknuds1)) 32 | - Decode text nodes before passing to React [\#18](https://github.com/mikenikles/html-to-react/pull/18) ([aknuds1](https://github.com/aknuds1)) 33 | - Deal with void element tags [\#17](https://github.com/mikenikles/html-to-react/pull/17) ([mikenikles](https://github.com/mikenikles)) 34 | - Make sure tests fail on console warnings [\#16](https://github.com/mikenikles/html-to-react/pull/16) ([mikenikles](https://github.com/mikenikles)) 35 | - Upgrade React to the latest version [\#15](https://github.com/mikenikles/html-to-react/pull/15) ([mikenikles](https://github.com/mikenikles)) 36 | - Fix the blanket dependency for now [\#12](https://github.com/mikenikles/html-to-react/pull/12) ([mikenikles](https://github.com/mikenikles)) 37 | - Fix key warning [\#10](https://github.com/mikenikles/html-to-react/pull/10) ([lithin](https://github.com/lithin)) 38 | - Fixing parser's error message when multiple roots are found [\#1](https://github.com/mikenikles/html-to-react/pull/1) ([Yomguithereal](https://github.com/Yomguithereal)) 39 | 40 | ## [v0.1.0](https://github.com/mikenikles/html-to-react/tree/v0.1.0) (2015-06-20) 41 | [Full Changelog](https://github.com/mikenikles/html-to-react/compare/v0.0.6...v0.1.0) 42 | 43 | ## [v0.0.6](https://github.com/mikenikles/html-to-react/tree/v0.0.6) (2015-06-20) 44 | [Full Changelog](https://github.com/mikenikles/html-to-react/compare/v0.0.5...v0.0.6) 45 | 46 | ## [v0.0.5](https://github.com/mikenikles/html-to-react/tree/v0.0.5) (2015-06-20) 47 | [Full Changelog](https://github.com/mikenikles/html-to-react/compare/v0.0.4...v0.0.5) 48 | 49 | ## [v0.0.4](https://github.com/mikenikles/html-to-react/tree/v0.0.4) (2015-06-20) 50 | [Full Changelog](https://github.com/mikenikles/html-to-react/compare/v0.0.3...v0.0.4) 51 | 52 | ## [v0.0.3](https://github.com/mikenikles/html-to-react/tree/v0.0.3) (2015-06-20) 53 | [Full Changelog](https://github.com/mikenikles/html-to-react/compare/v0.0.2...v0.0.3) 54 | 55 | ## [v0.0.2](https://github.com/mikenikles/html-to-react/tree/v0.0.2) (2015-06-20) 56 | 57 | 58 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Mike Nikles 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # html-to-react [](https://travis-ci.org/mikenikles/html-to-react) [](http://badge.fury.io/js/html-to-react) [](https://david-dm.org/mikenikles/html-to-react) [](https://coveralls.io/r/mikenikles/html-to-react?branch=master) 2 | A lightweight library that converts raw HTML to a React DOM structure. 3 | 4 | ## Project Moved 5 | 6 | As part of [#43](https://github.com/mikenikles/html-to-react/issues/43), this project moved to https://github.com/aknuds1/html-to-react. Please file any issues or PRs at the new location. 7 | 8 | ## Why? 9 | I had a scenario where an HTML template was generated by a different team, yet I wanted to leverage React for the parts 10 | I did have control over. The template basically contains something like: 11 | 12 | ``` 13 |
A paragraph
Paragraph
Paragraph
Does this work?
'; 17 | 18 | var reactComponent = parser.parse(htmlInput); 19 | var reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent); 20 | 21 | assert.equal(reactHtml, htmlInput); 22 | }); 23 | 24 | it('should return a valid HTML string with nested elements', function() { 25 | var htmlInput = 'Line one
Line two
Line three
Line one
Line two
Line three
element', function() { 207 | var htmlInput = '
Does this work?
'; 208 | var isValidNode = function() { 209 | return true; 210 | }; 211 | var processingInstructions = [{ 212 | shouldProcessNode: function(node) { 213 | return node.name && node.name !== 'p'; 214 | }, 215 | processNode: processNodeDefinitions.processDefaultNode, 216 | },]; 217 | var reactComponent = parser.parseWithInstructions(htmlInput, isValidNode, processingInstructions); 218 | 219 | // With only 1element, nothing is rendered 220 | assert.equal(reactComponent, false); 221 | }); 222 | 223 | it('should return a single
as siblings', function() { 224 | var htmlInput = '
Paragraph
Paragraph
Paragraph