0.2.0 • Published 9 years ago
html2jsx.js v0.2.0
html2jsx.js
Pure-JS HTML to Jsx parser that also works in webworker.
Since html2jsx from React is using the DOM (or jsdom in Node.js) to parse the HTML, it can't be used in webworkers. html2jsx.js is using a pure javascript html parser instead of the dom.
Usage
Install it from NPM using:
$ npm install html2jsx.js
Then simply parse html into Jsx using:
var html2jsx = require('html2jsx.js');
html2jsx('<h1>Hello World</h1>', function(err, jsx) {
// jsx == 'React.createElement("h1", null, [ "Hello World" ])'
console.log(jsx);
});
You can also provide your own components:
html2jsx('<p>This is some math: <TeX>a = b + 1</TeX></p>', {
components: ['TeX']
}, function(err, jsx) {
// jsx == 'React.createElement("p", null, [ "This is some math: ", React.createElement(TeX, null, [ "a = b + 1" ]) ])'
console.log(jsx);
});