Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/searls/html-to-preact-h
Converts an HTML string to a string of preact hyperscript h() calls
https://github.com/searls/html-to-preact-h
hyperscript preact react
Last synced: about 2 months ago
JSON representation
Converts an HTML string to a string of preact hyperscript h() calls
- Host: GitHub
- URL: https://github.com/searls/html-to-preact-h
- Owner: searls
- Created: 2019-07-04T02:19:41.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-28T22:37:48.000Z (over 2 years ago)
- Last Synced: 2024-10-19T23:51:55.626Z (2 months ago)
- Topics: hyperscript, preact, react
- Language: JavaScript
- Homepage:
- Size: 148 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# html-to-preact-h
Generates a string of [preact](https://preactjs.com) hyperscript `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
```js
const htmlToPreactH = require('html-to-preact-h')const result = htmlToPreactH('Great example!')
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
```