react-magic

Automatically AJAXify plain HTML with the power of React. It's magic!

OTHER License

Downloads
13.3K
Stars
939
Committers
20

HTMLtoJSX

HTMLtoJSX converts HTML to JSX for use with React.

Installation

npm install htmltojsx

Alternatively, a web-based version is available at http://magic.reactjs.net/htmltojsx.htm

Usage

HTMLtoJSX can be used either as a command-line application or as a Node.js module. To use the command-line version, invoke the htmltojsx command:

$ htmltojsx --help
Converts HTML to JSX for use with React.
Usage: htmltojsx [-c ComponentName] file.htm

Examples:
  htmltojsx -c AwesomeComponent awesome.htm    Creates React component "AwesomeComponent" based on awesome.htm


Options:
  --className, -c  Create a React component (wraps JSX in React.createClass call)
  --help           Show help

To use the Node.js module, require('htmltojsx') and create a new instance. This is the same interface as the web-based version:

var HTMLtoJSX = require('htmltojsx');
var converter = new HTMLtoJSX({
  createClass: true,
  outputClassName: 'AwesomeComponent'
});
var output = converter.convert('<div>Hello world!</div>');

Changelog

0.3.0 - 4th September 2017

  • #97 - Update to React 15
  • #100 - Remove JSX class-level indention when transforming HTML into JSX
  • #136 and #138 - Handle SVG attributes
    0.2.6 - 28th November 2016

0.2.5 - 26th October 2015

  • #33 - Correctly handle <textarea>s and <pre>s
  • #35 - Handle internal stylesheets (<style> tags). Thanks to Trevor Copeland

0.2.4 - 6th August 2015

  • #31 - Fixed jsdom
    dependency

0.2.3 - 5th August 2015

  • #8 - Handle
    case-insensitive attributes and style names
  • #29 - Switch to
    jsdom-no-contextify to support older versions of Node.js

0.2.2 - 4th May 2015

  • #21 - Allow output of
    React classes without class name
  • #25 - Update version of
    JSDOM

0.2.1 - 1st February 2015

  • #10 - Handle inline CSS
    shorthand style values
  • #13 - Maintain valueless
    attributes handled by JSX
  • #15 - Use uncontrolled
    input fields so they can still be edited
  • #11 - Ensure HTML
    entities are handled correctly

0.2.0 - 7th September 2014

  • Initial release