Socket
Socket
Sign inDemoInstall

@mapbox/hast-util-to-jsx

Package Overview
Dependencies
17
Maintainers
28
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @mapbox/hast-util-to-jsx

Transform HAST to JSX


Version published
Weekly downloads
3.7K
increased by3.75%
Maintainers
28
Created
Weekly downloads
 

Readme

Source

@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.

  • hast-util-to-html — Transform HAST to HTML.
  • rehype — Process HTML as HAST.

Keywords

FAQs

Last updated on 13 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc