Convert HTML to HyperScript (both common syntaxes)
npm install html-to-hyperscripthtml-to-hyperscript converts HTML to HyperScript.
Supports both original and
hypescript-helpers syntaxes.
Here and below first syntax is referenced as H, second – as HH.
```
$ npm install html-to-hyperscript
test.js
`js
let {htmlToHs} = require("html-to-hyperscript")
let convert = htmlToHs({tabSize: 4})
console.log(
convert("
$ babel-node test.js
`
div([
foo ,
span([bar])
])
`API
Functions correspond to html-to-hyperscript default export.
Exported function are curried.
$3
Converts HTML string to HyperScript string
according to passed options.
$3
`js
> let convert = htmlToHs({})> convert('
')
'div(".foo")'> convert('public/bundle.css')
'a({\n "attributes": {\n "rel": "stylesheet"\n }\n}, [
public/bundle.css])'> convert('
foo')
'div([\n span([foo])\n])'> let convert = htmlToHs({syntax: "h"})
> convert('
foo')
'h("div", [\n h("span", [foo])\n])'
`$3
Converts HTML string to HyperScript string according to passed options,
keeping a list of used tagnames. Use with HH syntax.
$3
`js
> let [_, usedTagNames] = htmlToHs2({}, "italicbold #1bold #2")> usedTagNames
['b', 'i', 'div']
>
let {${usedTagNames.join(", ")}} = hh(h).
'let {b, i, div} = hh(h)'
`$3
Options to control rendering.
tabSize – number of spaces in "tab". Defaults to 2.syntax – pass "h" for H syntax, "hh" for HH syntax. Defaults to "hh"`.| Feature | Library | ||
|---|---|---|---|
| html2hyperscript | html2hscript | html-to-hyperscript | |
| Parser engine | htmlparser2 | htmlparser2 | parse5 |
| Parsing | async | async | sync |
| H syntax | + | + | + |
| HH syntax | - | - | + |
| Respect whitespace | - | - | + |
This repo is made mostly to power a webservice.
So we don't care much about dependencies.
Use html-to-hyperscript.paqmind.com to convert HTML to HyperScript online.
MIT