planning
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s

This commit is contained in:
2024-10-14 09:15:30 +02:00
parent bcba00a730
commit 6e64e138e2
21059 changed files with 2317811 additions and 1 deletions

2
node_modules/hast-util-to-html/index.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
'use strict'
module.exports = require('./lib')

18
node_modules/hast-util-to-html/lib/all.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
'use strict'
var one = require('./one')
module.exports = all
// Serialize all children of `parent`.
function all(ctx, parent) {
var results = []
var children = (parent && parent.children) || []
var index = -1
while (++index < children.length) {
results[index] = one(ctx, children[index], index, parent)
}
return results.join('')
}

17
node_modules/hast-util-to-html/lib/comment.js generated vendored Normal file
View File

@@ -0,0 +1,17 @@
'use strict'
var xtend = require('xtend')
var entities = require('stringify-entities')
module.exports = serializeComment
function serializeComment(ctx, node) {
// See: <https://html.spec.whatwg.org/multipage/syntax.html#comments>
return ctx.bogusComments
? '<?' + entities(node.value, xtend(ctx.entities, {subset: ['>']})) + '>'
: '<!--' + node.value.replace(/^>|^->|<!--|-->|--!>|<!-$/g, encode) + '-->'
function encode($0) {
return entities($0, xtend(ctx.entities, {subset: ['<', '>']}))
}
}

28
node_modules/hast-util-to-html/lib/constants.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
'use strict'
// Maps of subsets.
// Each value is a matrix of tuples.
// The first value causes parse errors, the second is valid.
// Of both values, the first value is unsafe, and the second is safe.
module.exports = {
// See: <https://html.spec.whatwg.org/#attribute-name-state>.
name: [
['\t\n\f\r &/=>'.split(''), '\t\n\f\r "&\'/=>`'.split('')],
['\0\t\n\f\r "&\'/<=>'.split(''), '\0\t\n\f\r "&\'/<=>`'.split('')]
],
// See: <https://html.spec.whatwg.org/#attribute-value-(unquoted)-state>.
unquoted: [
['\t\n\f\r &>'.split(''), '\0\t\n\f\r "&\'<=>`'.split('')],
['\0\t\n\f\r "&\'<=>`'.split(''), '\0\t\n\f\r "&\'<=>`'.split('')]
],
// See: <https://html.spec.whatwg.org/#attribute-value-(single-quoted)-state>.
single: [
["&'".split(''), '"&\'`'.split('')],
["\0&'".split(''), '\0"&\'`'.split('')]
],
// See: <https://html.spec.whatwg.org/#attribute-value-(double-quoted)-state>.
double: [
['"&'.split(''), '"&\'`'.split('')],
['\0"&'.split(''), '\0"&\'`'.split('')]
]
}

42
node_modules/hast-util-to-html/lib/doctype.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
'use strict'
var xtend = require('xtend')
var ccount = require('ccount')
var entities = require('stringify-entities')
module.exports = serializeDoctype
function serializeDoctype(ctx, node) {
var sep = ctx.tightDoctype ? '' : ' '
var parts = ['<!' + (ctx.upperDoctype ? 'DOCTYPE' : 'doctype')]
if (node.name) {
parts.push(sep, node.name)
if (node.public != null) {
parts.push(' public', sep, quote(ctx, node.public))
} else if (node.system != null) {
parts.push(' system')
}
if (node.system != null) {
parts.push(sep, quote(ctx, node.system))
}
}
return parts.join('') + '>'
}
function quote(ctx, value) {
var string = String(value)
var quote =
ccount(string, ctx.quote) > ccount(string, ctx.alternative)
? ctx.alternative
: ctx.quote
return (
quote +
entities(string, xtend(ctx.entities, {subset: ['<', '&', quote]})) +
quote
)
}

198
node_modules/hast-util-to-html/lib/element.js generated vendored Normal file
View File

@@ -0,0 +1,198 @@
'use strict'
var xtend = require('xtend')
var svg = require('property-information/svg')
var find = require('property-information/find')
var spaces = require('space-separated-tokens')
var commas = require('comma-separated-tokens')
var entities = require('stringify-entities')
var ccount = require('ccount')
var all = require('./all')
var constants = require('./constants')
module.exports = serializeElement
function serializeElement(ctx, node, index, parent) {
var schema = ctx.schema
var omit = schema.space === 'svg' ? false : ctx.omit
var parts = []
var selfClosing =
schema.space === 'svg'
? ctx.closeEmpty
: ctx.voids.indexOf(node.tagName.toLowerCase()) > -1
var attrs
var content
var last
if (schema.space === 'html' && node.tagName === 'svg') {
ctx.schema = svg
}
attrs = serializeAttributes(ctx, node.properties)
content = all(
ctx,
schema.space === 'html' && node.tagName === 'template' ? node.content : node
)
ctx.schema = schema
// If the node is categorised as void, but it has children, remove the
// categorisation.
// This enables for example `menuitem`s, which are void in W3C HTML but not
// void in WHATWG HTML, to be stringified properly.
if (content) selfClosing = false
if (attrs || !omit || !omit.opening(node, index, parent)) {
parts.push('<', node.tagName, attrs ? ' ' + attrs : '')
if (selfClosing && (schema.space === 'svg' || ctx.close)) {
last = attrs.charAt(attrs.length - 1)
if (
!ctx.tightClose ||
last === '/' ||
(schema.space === 'svg' && last && last !== '"' && last !== "'")
) {
parts.push(' ')
}
parts.push('/')
}
parts.push('>')
}
parts.push(content)
if (!selfClosing && (!omit || !omit.closing(node, index, parent))) {
parts.push('</' + node.tagName + '>')
}
return parts.join('')
}
function serializeAttributes(ctx, props) {
var values = []
var index = -1
var key
var value
var last
for (key in props) {
if (props[key] != null) {
value = serializeAttribute(ctx, key, props[key])
if (value) values.push(value)
}
}
while (++index < values.length) {
last = ctx.tight ? values[index].charAt(values[index].length - 1) : null
// In tight mode, dont add a space after quoted attributes.
if (index !== values.length - 1 && last !== '"' && last !== "'") {
values[index] += ' '
}
}
return values.join('')
}
function serializeAttribute(ctx, key, value) {
var info = find(ctx.schema, key)
var quote = ctx.quote
var result
var name
if (info.overloadedBoolean && (value === info.attribute || value === '')) {
value = true
} else if (
info.boolean ||
(info.overloadedBoolean && typeof value !== 'string')
) {
value = Boolean(value)
}
if (
value == null ||
value === false ||
(typeof value === 'number' && value !== value)
) {
return ''
}
name = entities(
info.attribute,
xtend(ctx.entities, {
// Always encode without parse errors in non-HTML.
subset:
constants.name[ctx.schema.space === 'html' ? ctx.valid : 1][ctx.safe]
})
)
// No value.
// There is currently only one boolean property in SVG: `[download]` on
// `<a>`.
// This property does not seem to work in browsers (FF, Sa, Ch), so I cant
// test if dropping the value works.
// But I assume that it should:
//
// ```html
// <!doctype html>
// <svg viewBox="0 0 100 100">
// <a href=https://example.com download>
// <circle cx=50 cy=40 r=35 />
// </a>
// </svg>
// ```
//
// See: <https://github.com/wooorm/property-information/blob/main/lib/svg.js>
if (value === true) return name
value =
typeof value === 'object' && 'length' in value
? // `spaces` doesnt accept a second argument, but its given here just to
// keep the code cleaner.
(info.commaSeparated ? commas.stringify : spaces.stringify)(value, {
padLeft: !ctx.tightLists
})
: String(value)
if (ctx.collapseEmpty && !value) return name
// Check unquoted value.
if (ctx.unquoted) {
result = entities(
value,
xtend(ctx.entities, {
subset: constants.unquoted[ctx.valid][ctx.safe],
attribute: true
})
)
}
// If we dont want unquoted, or if `value` contains character references when
// unquoted…
if (result !== value) {
// If the alternative is less common than `quote`, switch.
if (ctx.smart && ccount(value, quote) > ccount(value, ctx.alternative)) {
quote = ctx.alternative
}
result =
quote +
entities(
value,
xtend(ctx.entities, {
// Always encode without parse errors in non-HTML.
subset: (quote === "'" ? constants.single : constants.double)[
ctx.schema.space === 'html' ? ctx.valid : 1
][ctx.safe],
attribute: true
})
) +
quote
}
// Dont add a `=` for unquoted empties.
return name + (result ? '=' + result : result)
}

56
node_modules/hast-util-to-html/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,56 @@
'use strict'
var html = require('property-information/html')
var svg = require('property-information/svg')
var voids = require('html-void-elements')
var omission = require('./omission')
var one = require('./one')
module.exports = toHtml
var deprecationWarningIssued
function toHtml(node, options) {
var settings = options || {}
var quote = settings.quote || '"'
var alternative = quote === '"' ? "'" : '"'
if (quote !== '"' && quote !== "'") {
throw new Error('Invalid quote `' + quote + '`, expected `\'` or `"`')
}
if ('allowDangerousHTML' in settings && !deprecationWarningIssued) {
deprecationWarningIssued = true
console.warn(
'Deprecation warning: `allowDangerousHTML` is a nonstandard option, use `allowDangerousHtml` instead'
)
}
return one(
{
valid: settings.allowParseErrors ? 0 : 1,
safe: settings.allowDangerousCharacters ? 0 : 1,
schema: settings.space === 'svg' ? svg : html,
omit: settings.omitOptionalTags && omission,
quote: quote,
alternative: alternative,
smart: settings.quoteSmart,
unquoted: settings.preferUnquoted,
tight: settings.tightAttributes,
upperDoctype: settings.upperDoctype,
tightDoctype: settings.tightDoctype,
bogusComments: settings.bogusComments,
tightLists: settings.tightCommaSeparatedLists,
tightClose: settings.tightSelfClosing,
collapseEmpty: settings.collapseEmptyAttributes,
dangerous: settings.allowDangerousHtml || settings.allowDangerousHTML,
voids: settings.voids || voids.concat(),
entities: settings.entities || {},
close: settings.closeSelfClosing,
closeEmpty: settings.closeEmptyElements
},
node && typeof node === 'object' && 'length' in node
? {type: 'root', children: node}
: node
)
}

168
node_modules/hast-util-to-html/lib/omission/closing.js generated vendored Normal file
View File

@@ -0,0 +1,168 @@
'use strict'
var element = require('hast-util-is-element')
var whiteSpaceStart = require('./util/white-space-start')
var comment = require('./util/comment')
var siblings = require('./util/siblings')
var omission = require('./omission')
module.exports = omission({
html: html,
head: headOrColgroupOrCaption,
body: body,
p: p,
li: li,
dt: dt,
dd: dd,
rt: rubyElement,
rp: rubyElement,
optgroup: optgroup,
option: option,
menuitem: menuitem,
colgroup: headOrColgroupOrCaption,
caption: headOrColgroupOrCaption,
thead: thead,
tbody: tbody,
tfoot: tfoot,
tr: tr,
td: cells,
th: cells
})
// Macro for `</head>`, `</colgroup>`, and `</caption>`.
function headOrColgroupOrCaption(node, index, parent) {
var next = siblings.after(parent, index, true)
return !next || (!comment(next) && !whiteSpaceStart(next))
}
// Whether to omit `</html>`.
function html(node, index, parent) {
var next = siblings.after(parent, index)
return !next || !comment(next)
}
// Whether to omit `</body>`.
function body(node, index, parent) {
var next = siblings.after(parent, index)
return !next || !comment(next)
}
// Whether to omit `</p>`.
function p(node, index, parent) {
var next = siblings.after(parent, index)
return next
? element(next, [
'address',
'article',
'aside',
'blockquote',
'details',
'div',
'dl',
'fieldset',
'figcaption',
'figure',
'footer',
'form',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'header',
'hgroup',
'hr',
'main',
'menu',
'nav',
'ol',
'p',
'pre',
'section',
'table',
'ul'
])
: !parent ||
// Confusing parent.
!element(parent, [
'a',
'audio',
'del',
'ins',
'map',
'noscript',
'video'
])
}
// Whether to omit `</li>`.
function li(node, index, parent) {
var next = siblings.after(parent, index)
return !next || element(next, 'li')
}
// Whether to omit `</dt>`.
function dt(node, index, parent) {
var next = siblings.after(parent, index)
return next && element(next, ['dt', 'dd'])
}
// Whether to omit `</dd>`.
function dd(node, index, parent) {
var next = siblings.after(parent, index)
return !next || element(next, ['dt', 'dd'])
}
// Whether to omit `</rt>` or `</rp>`.
function rubyElement(node, index, parent) {
var next = siblings.after(parent, index)
return !next || element(next, ['rp', 'rt'])
}
// Whether to omit `</optgroup>`.
function optgroup(node, index, parent) {
var next = siblings.after(parent, index)
return !next || element(next, 'optgroup')
}
// Whether to omit `</option>`.
function option(node, index, parent) {
var next = siblings.after(parent, index)
return !next || element(next, ['option', 'optgroup'])
}
// Whether to omit `</menuitem>`.
function menuitem(node, index, parent) {
var next = siblings.after(parent, index)
return !next || element(next, ['menuitem', 'hr', 'menu'])
}
// Whether to omit `</thead>`.
function thead(node, index, parent) {
var next = siblings.after(parent, index)
return next && element(next, ['tbody', 'tfoot'])
}
// Whether to omit `</tbody>`.
function tbody(node, index, parent) {
var next = siblings.after(parent, index)
return !next || element(next, ['tbody', 'tfoot'])
}
// Whether to omit `</tfoot>`.
function tfoot(node, index, parent) {
return !siblings.after(parent, index)
}
// Whether to omit `</tr>`.
function tr(node, index, parent) {
var next = siblings.after(parent, index)
return !next || element(next, 'tr')
}
// Whether to omit `</td>` or `</th>`.
function cells(node, index, parent) {
var next = siblings.after(parent, index)
return !next || element(next, ['td', 'th'])
}

3
node_modules/hast-util-to-html/lib/omission/index.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
'use strict'
exports.opening = require('./opening')
exports.closing = require('./closing')

View File

@@ -0,0 +1,18 @@
'use strict'
module.exports = omission
var own = {}.hasOwnProperty
// Factory to check if a given node can have a tag omitted.
function omission(handlers) {
return omit
// Check if a given node can have a tag omitted.
function omit(node, index, parent) {
return (
own.call(handlers, node.tagName) &&
handlers[node.tagName](node, index, parent)
)
}
}

85
node_modules/hast-util-to-html/lib/omission/opening.js generated vendored Normal file
View File

@@ -0,0 +1,85 @@
'use strict'
var element = require('hast-util-is-element')
var siblings = require('./util/siblings')
var whiteSpaceStart = require('./util/white-space-start')
var comment = require('./util/comment')
var closing = require('./closing')
var omission = require('./omission')
module.exports = omission({
html: html,
head: head,
body: body,
colgroup: colgroup,
tbody: tbody
})
// Whether to omit `<html>`.
function html(node) {
var head = siblings.after(node, -1)
return !head || !comment(head)
}
// Whether to omit `<head>`.
function head(node) {
var children = node.children
var seen = []
var index = -1
while (++index < children.length) {
if (element(children[index], ['title', 'base'])) {
if (seen.indexOf(children[index].tagName) > -1) return false
seen.push(children[index].tagName)
}
}
return children.length
}
// Whether to omit `<body>`.
function body(node) {
var head = siblings.after(node, -1, true)
return (
!head ||
(!comment(head) &&
!whiteSpaceStart(head) &&
!element(head, ['meta', 'link', 'script', 'style', 'template']))
)
}
// Whether to omit `<colgroup>`.
// The spec describes some logic for the opening tag, but its easier to
// implement in the closing tag, to the same effect, so we handle it there
// instead.
function colgroup(node, index, parent) {
var previous = siblings.before(parent, index)
var head = siblings.after(node, -1, true)
// Previous colgroup was already omitted.
if (
element(previous, 'colgroup') &&
closing(previous, parent.children.indexOf(previous), parent)
) {
return false
}
return head && element(head, 'col')
}
// Whether to omit `<tbody>`.
function tbody(node, index, parent) {
var previous = siblings.before(parent, index)
var head = siblings.after(node, -1)
// Previous table section was already omitted.
if (
element(previous, ['thead', 'tbody']) &&
closing(previous, parent.children.indexOf(previous), parent)
) {
return false
}
return head && element(head, 'tr')
}

View File

@@ -0,0 +1,5 @@
'use strict'
var convert = require('unist-util-is/convert')
module.exports = convert('comment')

View File

@@ -0,0 +1,27 @@
'use strict'
var whiteSpace = require('hast-util-whitespace')
exports.before = siblings(-1)
exports.after = siblings(1)
// Factory to check siblings in a direction.
function siblings(increment) {
return sibling
// Find applicable siblings in a direction.
function sibling(parent, index, includeWhiteSpace) {
var siblings = parent && parent.children
var offset = index + increment
var next = siblings && siblings[offset]
if (!includeWhiteSpace) {
while (next && whiteSpace(next)) {
offset += increment
next = siblings[offset]
}
}
return next
}
}

View File

@@ -0,0 +1,13 @@
'use strict'
var convert = require('unist-util-is/convert')
var whiteSpace = require('hast-util-whitespace')
module.exports = whiteSpaceStart
var isText = convert('text')
// Check if `node` starts with white-space.
function whiteSpaceStart(node) {
return isText(node) && whiteSpace(node.value.charAt(0))
}

26
node_modules/hast-util-to-html/lib/one.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
'use strict'
module.exports = serialize
var handlers = {
comment: require('./comment'),
doctype: require('./doctype'),
element: require('./element'),
raw: require('./raw'),
root: require('./all'),
text: require('./text')
}
var own = {}.hasOwnProperty
function serialize(ctx, node, index, parent) {
if (!node || !node.type) {
throw new Error('Expected node, not `' + node + '`')
}
if (!own.call(handlers, node.type)) {
throw new Error('Cannot compile unknown node `' + node.type + '`')
}
return handlers[node.type](ctx, node, index, parent)
}

9
node_modules/hast-util-to-html/lib/raw.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
'use strict'
var text = require('./text')
module.exports = serializeRaw
function serializeRaw(ctx, node) {
return ctx.dangerous ? node.value : text(ctx, node)
}

13
node_modules/hast-util-to-html/lib/text.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
'use strict'
var xtend = require('xtend')
var entities = require('stringify-entities')
module.exports = serializeText
function serializeText(ctx, node, index, parent) {
// Check if content of `node` should be escaped.
return parent && (parent.tagName === 'script' || parent.tagName === 'style')
? node.value
: entities(node.value, xtend(ctx.entities, {subset: ['<', '&']}))
}

22
node_modules/hast-util-to-html/license generated vendored Normal file
View File

@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

111
node_modules/hast-util-to-html/package.json generated vendored Normal file
View File

@@ -0,0 +1,111 @@
{
"name": "hast-util-to-html",
"version": "7.1.3",
"description": "hast utility to serialize to HTML",
"license": "MIT",
"keywords": [
"unist",
"hast",
"hast-util",
"util",
"utility",
"html",
"serialize",
"stringify",
"tostring"
],
"repository": "syntax-tree/hast-util-to-html",
"bugs": "https://github.com/syntax-tree/hast-util-to-html/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"files": [
"lib",
"index.js",
"types/index.d.ts"
],
"types": "types/index.d.ts",
"dependencies": {
"ccount": "^1.0.0",
"comma-separated-tokens": "^1.0.0",
"hast-util-is-element": "^1.0.0",
"hast-util-whitespace": "^1.0.0",
"html-void-elements": "^1.0.0",
"property-information": "^5.0.0",
"space-separated-tokens": "^1.0.0",
"stringify-entities": "^3.0.1",
"unist-util-is": "^4.0.0",
"xtend": "^4.0.0"
},
"devDependencies": {
"@types/unist": "^2.0.0",
"browserify": "^17.0.0",
"dtslint": "^4.0.0",
"hastscript": "^6.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"unist-builder": "^2.0.0",
"xo": "^0.38.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify . -s hastUtilToHtml -o hast-util-to-html.js",
"build-mangle": "browserify . -s hastUtilToHtml -o hast-util-to-html.min.js -p tinyify",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test/index.js",
"test-types": "dtslint types",
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"complexity": "off",
"eqeqeq": [
"error",
"always",
{
"null": "ignore"
}
],
"guard-for-in": "off",
"no-eq-null": "off",
"no-self-compare": "off",
"unicorn/no-array-for-each": "off",
"unicorn/prefer-includes": "off",
"unicorn/prefer-number-properties": "off"
},
"ignores": [
"hast-util-to-html.js"
]
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
}
}

262
node_modules/hast-util-to-html/readme.md generated vendored Normal file
View File

@@ -0,0 +1,262 @@
# hast-util-to-html
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[**hast**][hast] utility to serialize to HTML.
## Install
[npm][]:
```sh
npm install hast-util-to-html
```
## Use
```js
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:
```html
<div class="alpha">bravo <b>charlie</b> delta <a class="echo" download>foxtrot</a></div>
```
## API
### `toHtml(tree[, options])`
Serialize the given [**hast**][hast] [*tree*][tree] (or list of nodes).
###### `options.space`
Whether the [*root*][root] of the [*tree*][tree] is in the `'html'` or `'svg'`
space (enum, `'svg'` or `'html'`, default: `'html'`).
If an `svg` element is found in the HTML space, `toHtml` automatically switches
to the SVG space when entering the element, and switches back when exiting.
###### `options.entities`
Configuration for [`stringify-entities`][stringify-entities] (`Object`, default:
`{}`).
Do not use `escapeOnly`, `attribute`, or `subset` (`toHtml` already passes
those, so they wont work).
However, `useNamedReferences`, `useShortestReferences`, and
`omitOptionalSemicolons` are all fine.
###### `options.voids`
Tag names of [*elements*][element] to serialize without closing tag
(`Array.<string>`, default: [`html-void-elements`][html-void-elements]).
Not used in the SVG space.
###### `options.upperDoctype`
Use a `<!DOCTYPE…` instead of `<!doctype…`.
Useless except for XHTML (`boolean`, default: `false`).
###### `options.quote`
Preferred quote to use (`'"'` or `'\''`, default: `'"'`).
###### `options.quoteSmart`
Use the other quote if that results in less bytes (`boolean`, default: `false`).
###### `options.preferUnquoted`
Leave attributes unquoted if that results in less bytes (`boolean`, default:
`false`).
Not used in the SVG space.
###### `options.omitOptionalTags`
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 its followed by another `li`, the last because its followed
by nothing.
Not used in the SVG space.
###### `options.collapseEmptyAttributes`
Collapse empty attributes: get `class` instead of `class=""` (`boolean`,
default: `false`).
**Note**: boolean attributes, such as `hidden`, are always collapsed.
Not used in the SVG space.
###### `options.closeSelfClosing`
Close self-closing nodes with an extra slash (`/`): `<img />` instead of
`<img>` (`boolean`, default: `false`).
See `tightSelfClosing` to control whether a space is used before the slash.
Not used in the SVG space.
###### `options.closeEmptyElements`
Close SVG elements without any content with slash (`/`) on the opening tag
instead of an end tag: `<circle />` instead of `<circle></circle>` (`boolean`,
default: `false`).
See `tightSelfClosing` to control whether a space is used before the slash.
Not used in the HTML space.
###### `options.tightSelfClosing`
Do not use an extra space when closing self-closing elements: `<img/>` instead
of `<img />` (`boolean`, default: `false`).
**Note**: Only used if `closeSelfClosing: true` or `closeEmptyElements: true`.
###### `options.tightCommaSeparatedLists`
Join known comma-separated attribute values with just a comma (`,`), instead of
padding them on the right as well (`,·`, where `·` represents a space)
(`boolean`, default: `false`).
###### `options.tightAttributes`
Join attributes together, without white-space, if possible: get
`class="a b"title="c d"` instead of `class="a b" title="c d"` to save bytes
(`boolean`, default: `false`).
**Note**: creates invalid (but working) markup.
Not used in the SVG space.
###### `options.tightDoctype`
Drop unneeded spaces in doctypes: `<!doctypehtml>` instead of `<!doctype html>`
to save bytes (`boolean`, default: `false`).
**Note**: creates invalid (but working) markup.
###### `options.bogusComments`
Use “bogus comments” instead of comments to save byes: `<?charlie>` instead of
`<!--charlie-->` (`boolean`, default: `false`).
**Note**: creates invalid (but working) markup.
###### `options.allowParseErrors`
Do not encode characters which cause parse errors (even though they work), to
save bytes (`boolean`, default: `false`).
**Note**: creates invalid (but working) markup.
Not used in the SVG space.
###### `options.allowDangerousCharacters`
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.
###### `options.allowDangerousHtml`
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.
## Security
Use of `hast-util-to-html` can open you up to a
[cross-site scripting (XSS)][xss] attack if the hast tree is unsafe.
Use [`hast-util-santize`][sanitize] to make the hast tree safe.
## Related
* [`hast-util-sanitize`][sanitize]
— Sanitize hast nodes
* [`rehype-stringify`](https://github.com/rehypejs/rehype/tree/HEAD/packages/rehype-stringify)
— Wrapper around this project for [**rehype**](https://github.com/wooorm/rehype)
## Contribute
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/syntax-tree/hast-util-to-html/workflows/main/badge.svg
[build]: https://github.com/syntax-tree/hast-util-to-html/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-to-html.svg
[coverage]: https://codecov.io/github/syntax-tree/hast-util-to-html
[downloads-badge]: https://img.shields.io/npm/dm/hast-util-to-html.svg
[downloads]: https://www.npmjs.com/package/hast-util-to-html
[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-to-html.svg
[size]: https://bundlephobia.com/result?p=hast-util-to-html
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/syntax-tree/unist/discussions
[npm]: https://docs.npmjs.com/cli/install
[license]: license
[author]: https://wooorm.com
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
[html-void-elements]: https://github.com/wooorm/html-void-elements
[stringify-entities]: https://github.com/wooorm/stringify-entities
[tree]: https://github.com/syntax-tree/unist#tree
[root]: https://github.com/syntax-tree/unist#root
[hast]: https://github.com/syntax-tree/hast
[element]: https://github.com/syntax-tree/hast#element
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[sanitize]: https://github.com/syntax-tree/hast-util-sanitize

184
node_modules/hast-util-to-html/types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,184 @@
// TypeScript Version: 3.5
import {Node} from 'unist'
import {StringifyEntitiesOptions} from 'stringify-entities'
declare namespace hastUtilToHtml {
interface HastUtilToHtmlOptions {
/**
* Whether the *root* of the *tree* is in the `'html'` or `'svg'` space.
*
* If an `svg` element is found in the HTML space, `toHtml` automatically switches to the SVG space when entering the element, and switches back when exiting.
*
* @defaultValue 'html'
*/
space?: 'html' | 'svg'
/**
* Configuration for `stringify-entities`.
* Do not use `escapeOnly`, `attribute`, or `subset` (`toHtml` already passes those, so they wont work).
* However, `useNamedReferences`, `useShortestReferences`, and `omitOptionalSemicolons` are all fine.
*
* @defaultValue {}
*/
/* eslint-disable-next-line @typescript-eslint/ban-types */
entities?: Omit<
StringifyEntitiesOptions,
'escapeOnly' | 'attribute' | 'subset'
>
/**
* Tag names of *elements* to serialize without closing tag.
*
* Not used in the SVG space.
*
* @defaultValue `require('html-void-elements')`
*/
voids?: string[]
/**
* Use a `<!DOCTYPE…` instead of `<!doctype…`.
* Useless except for XHTML.
*
* @defaultValue false
*/
upperDoctype?: boolean
/**
* Preferred quote to use.
*
* @defaultValue '"'
*/
quote?: '"' | "'"
/**
* Use the other quote if that results in less bytes.
*
* @defaultValue false
*/
quoteSmart?: boolean
/**
* Leave attributes unquoted if that results in less bytes.
*
* Not used in the SVG space.
*
* @defaultValue false
*/
preferUnquoted?: boolean
/**
* Omit optional opening and closing tags.
* For example, in `<ol><li>one</li><li>two</li></ol>`, both `</li>` closing tags can be omitted.
* The first because its followed by another `li`, the last because its followed by nothing.
*
* Not used in the SVG space.
*
* @defaultValue false
*/
omitOptionalTags?: boolean
/**
* Collapse empty attributes: `class=""` is stringified as `class` instead.
* **Note**: boolean attributes, such as `hidden`, are always collapsed.
*
* Not used in the SVG space.
*
* @defaultValue false
*/
collapseEmptyAttributes?: boolean
/**
* Close self-closing nodes with an extra slash (`/`): `<img />` instead of `<img>`.
* See `tightSelfClosing` to control whether a space is used before the slash.
*
* Not used in the SVG space.
*
* @defaultValue false
*/
closeSelfClosing?: boolean
/**
* Close SVG elements without any content with slash (`/`) on the opening tag instead of an end tag: `<circle />` instead of `<circle></circle>`.
* See `tightSelfClosing` to control whether a space is used before the slash.
*
* Not used in the HTML space.
*
* @defaultValue false
*/
closeEmptyElements?: boolean
/**
* Do not use an extra space when closing self-closing elements: `<img/>` instead of `<img />`.
* **Note**: Only used if `closeSelfClosing: true` or `closeEmptyElements: true`.
*
* @defaultValue false
*/
tightSelfClosing?: boolean
/**
* Join known comma-separated attribute values with just a comma (`,`), instead of padding them on the right as well (`,·`, where `·` represents a space).
*
* @defaultValue false
*/
tightCommaSeparatedLists?: boolean
/**
* 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.
* **Note**: creates invalid (but working) markup.
*
* Not used in the SVG space.
*
* @defaultValue false
*/
tightAttributes?: boolean
/**
* Drop unneeded spaces in doctypes: `<!doctypehtml>` instead of `<!doctype html>` to save bytes.
* **Note**: creates invalid (but working) markup.
*
* @defaultValue false
*/
tightDoctype?: boolean
/**
* Do not encode characters which cause parse errors (even though they work), to save bytes.
* **Note**: creates invalid (but working) markup.
*
* Not used in the SVG space.
*
* @defaultValue false
*/
allowParseErrors?: boolean
/**
* Do not encode some characters which cause XSS vulnerabilities in older browsers.
* **Note**: Only set this if you completely trust the content.
*
* @defaultValue false
*/
allowDangerousCharacters?: boolean
/**
* Allow `raw` nodes and insert them as raw HTML.
* When falsey, encodes `raw` nodes.
* **Note**: Only set this if you completely trust the content.
*
* @defaultValue false
*/
allowDangerousHtml?: boolean
}
}
/**
* Serialize the given **hast** *tree*.
*
* @param tree given hast tree
* @param options configuration for stringifier
*/
declare function hastUtilToHtml(
tree: Node | Node[],
options?: hastUtilToHtml.HastUtilToHtmlOptions
): string
export = hastUtilToHtml