Transform HAST to HTML.
npm:
npm install hast-util-to-html
var h = require('hastscript');
var toHTML = require('hast-util-to-html');
var tree = h('.alpha', [
'bravo ',
h('b', 'charlie'),
' delta ',
h('a.echo', {
download: true
}, 'foxtrot')
]);
console.log(toHTML(tree));
Yields:
<div class="alpha">bravo <b>charlie</b> delta <a class="echo" download>foxtrot</a></div>
Stringify the given HAST node.
Configuration for stringify-entities
(Object
, default: {}
). Do not use escapeOnly
, attribute
, or
subset
(toHTML
already passes those). However, useNamedReferences
,
useShortestReferences
, and omitOptionalSemicolons
are all fine.
Tag-names of elements to stringify without closing tag (Array.<string>
,
default: html-void-elements
).
Preferred quote to use ('"'
or '\''
, default: '"'
).
Use the other quote if that results in less bytes (boolean
, default:
false
).
Leave attributes unquoted if that results in less bytes (boolean
,
default: false
).
Omit optional opening and closing tags (boolean
, default: false
).
For example, in <ol><li>one</li><li>two</li></ol>
, both </li>
closing tags can be omitted. The first because it’s followed by
another li
, the last because it’s followed by nothing.
Collapse empty attributes: class=""
is stringified as class
instead
(boolean
, default: false
). Note: boolean attributes, such as
hidden
, are always collapsed.
Close self-closing nodes with an extra slash (/
): <img />
instead of
<img>
(boolean
, default: false
).
Do not use an extra space when closing self-closing elements: <img/>
instead of <img />
(boolean
, default: false
). Note: Only used
if closeSelfClosing: true
.
Join known comma-separated attribute values with just a comma (,
),
instead of padding them on the right as well (,
) (boolean
,
default: false
).
Join attributes together, without white-space, if possible:
class="a b" title="c d"
is stringified as class="a b"title="c d"
instead to save bytes (boolean
, default: false
). Note: creates
invalid (but working) markup.
Do not encode characters which trigger parse errors (even though they
work), to save bytes (boolean
, default: false
). Note: creates
invalid (but working) markup.
Do not encode some characters which cause XSS vulnerabilities in older
browsers (boolean
, default: false
). Note: Only set this if you
completely trust the content.
Allow raw
nodes and insert them as raw HTML. When falsey, encodes
raw
nodes (boolean
, default: false
). Note: Only set this if
you completely trust the content.
hast-util-sanitize
— Sanitize HAST nodesrehype-stringify
— Wrapper around this project for rehype
See contribute.md
in syntax-tree/hast
for ways to get
started.
This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.