@mapbox/hast-util-to-jsx
Transform HAST to JSX
Last updated 2 years ago by mapbox-npm-03 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @mapbox/hast-util-to-jsx 
SYNC missed versions from official npm registry.

@mapbox/hast-util-to-jsx

Transform HAST to JSX.

Installation

npm install @mapbox/hast-util-to-jsx

Usage

const h = require('hyperscript');
const toJsx = require('@mapbox/hast-util-to-jsx');

const tree = h('div.one.two', id: 'bar' }, [
  h('p.hidden', { ariaHidden: true }, ['hidden text']),
  h('p', { style: 'color: pink; font-size: 2em;' }, ['fancy text'])
]);

console.log(toJsx(tree));

Yields (with whitespace collapsed):

<div className="one two" id="bar">
  <p className="hidden" aria-hidden={true}>hidden text</p>
  <p style={{color: "pink", fontSize: "2em"}}>fancy text</p>
</div>

A few libraries exist to transform HTML to JSX. Using this util, you can perform that transformation entirely within the ecosystem of unified syntax trees, using rehype to parse HTML and this util to stringify the tree into JSX.

Related

Current Tags

  • 2.1.0                                ...           latest (2 years ago)

5 Versions

  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           6 years ago
  • 0.1.0                                ...           8 years ago

Copyright 2013 - present © cnpmjs.org | Home |