Skip to content

SamyPesse/html2jsx.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

html2jsx.js Build Status

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);
});

About

Pure javascript HTML to Jsx parser (works in webworker)

Resources

License

Stars

Watchers

Forks

Packages

No packages published