Transform HAST to something else through a hyperscript DSL.
npm:
npm install hast-to-hyperscript
var toH = require('hast-to-hyperscript');
var h = require('hyperscript');
var tree = { type: 'element',
tagName: 'p',
properties: { id: 'alpha', className: [ 'bravo' ] },
children:
[ { type: 'text',
value: 'charlie ' },
{ type: 'element',
tagName: 'strong',
properties: { style: 'color: red;' },
children:
[ { type: 'text',
value: 'delta' } ] },
{ type: 'text',
value: ' echo.' } ] }
// Transform (`hyperscript` needs `outerHTML` to stringify):
var doc = toH(h, tree).outerHTML;
Yields:
<p class="bravo" id="alpha">charlie <strong>delta</strong> echo.</p>
Transform HAST to something else through a hyperscript DSL.
h
(Function
);node
(Element
);prefix
(string
orboolean
, optional) — Prefix to use as a prefix for keys passed inattrs
toh()
, this behaviour is turned off by passingfalse
, turned on by passing astring
. By default,h-
is used as a prefix if the givenh
is detected as beingvirtual-dom/h
orReact.createElement
.
*
— Anything returned by invoking h()
.
Transform HAST to something else through a hyperscript DSL.
name
(string
) — Tag-name of element to create.attrs
(Object.<string>
) — Attributes to set.children
(Array.<* | string>
) — List of children and text, where children are the result of invokingh()
previously.
*
— Anything.
Although there are lots of libs mentioning support for this interface,
there are significant differences between them. For example, hyperscript
doesn’t support classes in attrs
, virtual-dom/h
needs an attributes
object inside attrs
most of the time. hast-to-hyperscript
works
around these differences for: