npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

html-2-jsx

v0.5.1-dev

Published

Converts HTML to JSX for use with React

Readme

HTMLtoJSX

HTMLtoJSX converts HTML to JSX for use with React.

Installation

npm install htmltojsx

Alternatively, a web-based version is available at http://facebook.github.io/react/html-jsx.html

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({
  indent: '\t',
  hideComment: true,
  createClass: true,
  outputClassName: 'AwesomeComponent'
});
var output = converter.convert('<div>Hello world!</div>');

参数说明

  1. indent 缩进填充符, 默认俩空格.
  2. hideComment 传 true 时将不会将原文中的注释生成到译文中.
  3. createClass 传 true 时将会在 jsx 外再创建一层 React.createClass 进行包裹.
  4. outputClassName 仅当 createClasstrue 时有效, 将会在 React.createClass 前再加一个变量 var xxx = 来保存这个组件.

TODO

  1. Complete the CLI tool.
  2. Complete the test cases.

Changelog

0.5.0 - 27th June 2017

  1. Support SVG convert.
  2. Fixed the bug of lost container when there're a DOM element and a comment element both on the root node.

中文说明

  1. 支持 SVG;
  2. 修正了当最外层根节点为一个注释与一个 DOM 节点时不会添加 container 的 bug.

0.3.0 - 11th January 2017

  1. Added hide comment ability to HTMLtoJSX, pass true to parameter hideComment to use it.
  2. Removed the extra spaces while createElement option is false.
  3. Found the no instruction option indent which can set the indent space of output.
  4. Fixed the bugs of the incorrect out put when the <thead> <tr> tags were the outermost layers.
  5. The outputClassName will be capitalized by default.
  6. Updated the React and ReactDOM version of HTMLtoJSX (0.14.x -> 15.x.x).
  7. Added supports of attributes of SVG tags.

中文说明

  1. 参数里 hideCommenttrue 就可以不再把注释也生成到 jsx 里去了;
  2. 去掉了不创建包裹类的时候多余的空格;
  3. 找到了作者没有标注出来的用于修改缩进填充字符的 indent 属性.
  4. <thead> <tr> 放在最外层的时候不会被干掉了.
  5. 输入的 outputClassName 总是会被变成首字母大写.
  6. 更新了 HTMLtoJSX 所依赖的 React 和 ReactDOM 版本 (0.14.x -> 15.x.x).
  7. 支持转换 SVG 标签的属性.

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