html-to-preact-h

1.0.1 • Public • Published

html-to-preact-h

Generates a string of preact h() function calls for a given HTML string. Designed to make it easier to embed snippets of markup (notably generated SVG files) into JavaScript source listings that use h() to render markup (as opposed to JSX).

Install

npm install html-to-preact-h

API

const htmlToPreactH = require('html-to-preact-h')

const result = htmlToPreactH('<a href="https://example.com">Great example!</a>')

console.log(result)

Will print:

h('a', {href: 'https://example.com'}, 'Great example!')

It handles things like nesting, dropping to 1 or 2 args when appropriate.

CLI

Just pass a file path and it'll print out the h()'s you crave:

$ html-to-preact-h example.svg

Readme

Keywords

Package Sidebar

Install

npm i html-to-preact-h

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

11.2 kB

Total Files

6

Last publish

Collaborators

  • dustin.tinney
  • mike.testdouble
  • searls