🎉 initiate project *astro_rewrite*

This commit is contained in:
sindrekjelsrud 2023-07-19 21:31:30 +02:00
parent ffd4d5e86c
commit 2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions

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

@ -0,0 +1,5 @@
export {toHtml} from './lib/index.js'
export type CharacterReferences = import('./lib/types.js').CharacterReferences
export type Options = import('./lib/types.js').Options
export type Quote = import('./lib/types.js').Quote
export type Space = import('./lib/types.js').Space

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

@ -0,0 +1,8 @@
/**
* @typedef {import('./lib/types.js').CharacterReferences} CharacterReferences
* @typedef {import('./lib/types.js').Options} Options
* @typedef {import('./lib/types.js').Quote} Quote
* @typedef {import('./lib/types.js').Space} Space
*/
export {toHtml} from './lib/index.js'

13
node_modules/hast-util-to-html/lib/constants.d.ts generated vendored Normal file
View file

@ -0,0 +1,13 @@
/**
* 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.
*
* @type {Record<'name' | 'unquoted' | 'single' | 'double', Array<[Array<string>, Array<string>]>>}
*/
export const constants: Record<
'name' | 'unquoted' | 'single' | 'double',
Array<[Array<string>, Array<string>]>
>

23
node_modules/hast-util-to-html/lib/handle/comment.d.ts generated vendored Normal file
View file

@ -0,0 +1,23 @@
/**
* Serialize a comment.
*
* @param {Comment} node
* Node to handle.
* @param {number | undefined} _1
* Index of `node` in `parent.
* @param {Parent | undefined} _2
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function comment(
node: Comment,
_1: number | undefined,
_2: Parent | undefined,
state: State
): string
export type Comment = import('../types.js').Comment
export type Parent = import('../types.js').Parent
export type State = import('../types.js').State

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

@ -0,0 +1,45 @@
/**
* @typedef {import('../types.js').Comment} Comment
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').State} State
*/
import {stringifyEntities} from 'stringify-entities'
/**
* Serialize a comment.
*
* @param {Comment} node
* Node to handle.
* @param {number | undefined} _1
* Index of `node` in `parent.
* @param {Parent | undefined} _2
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function comment(node, _1, _2, state) {
// See: <https://html.spec.whatwg.org/multipage/syntax.html#comments>
return state.settings.bogusComments
? '<?' +
stringifyEntities(
node.value,
Object.assign({}, state.settings.characterReferences, {subset: ['>']})
) +
'>'
: '<!--' + node.value.replace(/^>|^->|<!--|-->|--!>|<!-$/g, encode) + '-->'
/**
* @param {string} $0
*/
function encode($0) {
return stringifyEntities(
$0,
Object.assign({}, state.settings.characterReferences, {
subset: ['<', '>']
})
)
}
}

28
node_modules/hast-util-to-html/lib/handle/doctype.d.ts generated vendored Normal file
View file

@ -0,0 +1,28 @@
/**
* @typedef {import('../types.js').DocType} DocType
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').State} State
*/
/**
* Serialize a doctype.
*
* @param {DocType} _1
* Node to handle.
* @param {number | undefined} _2
* Index of `node` in `parent.
* @param {Parent | undefined} _3
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function doctype(
_1: DocType,
_2: number | undefined,
_3: Parent | undefined,
state: State
): string
export type DocType = import('../types.js').DocType
export type Parent = import('../types.js').Parent
export type State = import('../types.js').State

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

@ -0,0 +1,28 @@
/**
* @typedef {import('../types.js').DocType} DocType
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').State} State
*/
/**
* Serialize a doctype.
*
* @param {DocType} _1
* Node to handle.
* @param {number | undefined} _2
* Index of `node` in `parent.
* @param {Parent | undefined} _3
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function doctype(_1, _2, _3, state) {
return (
'<!' +
(state.settings.upperDoctype ? 'DOCTYPE' : 'doctype') +
(state.settings.tightDoctype ? '' : ' ') +
'html>'
)
}

25
node_modules/hast-util-to-html/lib/handle/element.d.ts generated vendored Normal file
View file

@ -0,0 +1,25 @@
/**
* Serialize an element node.
*
* @param {Element} node
* Node to handle.
* @param {number | undefined} index
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function element(
node: Element,
index: number | undefined,
parent: Parent | undefined,
state: State
): string
export type State = import('../types.js').State
export type Parent = import('../types.js').Parent
export type Element = import('../types.js').Element
export type Properties = import('../types.js').Properties
export type PropertyValue = import('../types.js').PropertyValue

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

@ -0,0 +1,268 @@
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Element} Element
* @typedef {import('../types.js').Properties} Properties
* @typedef {import('../types.js').PropertyValue} PropertyValue
*/
import {ccount} from 'ccount'
import {stringify as commas} from 'comma-separated-tokens'
import {svg, find} from 'property-information'
import {stringify as spaces} from 'space-separated-tokens'
import {stringifyEntities} from 'stringify-entities'
import {opening} from '../omission/opening.js'
import {closing} from '../omission/closing.js'
/**
* Maps of subsets.
*
* Each value is a matrix of tuples.
* The value at `0` causes parse errors, the value at `1` is valid.
* Of both, the value at `0` is unsafe, and the value at `1` is safe.
*
* @type {Record<'name' | 'unquoted' | 'single' | 'double', Array<[Array<string>, Array<string>]>>}
*/
const constants = {
// 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('')]
]
}
/**
* Serialize an element node.
*
* @param {Element} node
* Node to handle.
* @param {number | undefined} index
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
// eslint-disable-next-line complexity
export function element(node, index, parent, state) {
const schema = state.schema
const omit = schema.space === 'svg' ? false : state.settings.omitOptionalTags
let selfClosing =
schema.space === 'svg'
? state.settings.closeEmptyElements
: state.settings.voids.includes(node.tagName.toLowerCase())
/** @type {Array<string>} */
const parts = []
/** @type {string} */
let last
if (schema.space === 'html' && node.tagName === 'svg') {
state.schema = svg
}
const attrs = serializeAttributes(state, node.properties)
const content = state.all(
schema.space === 'html' && node.tagName === 'template' ? node.content : node
)
state.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 || !opening(node, index, parent)) {
parts.push('<', node.tagName, attrs ? ' ' + attrs : '')
if (
selfClosing &&
(schema.space === 'svg' || state.settings.closeSelfClosing)
) {
last = attrs.charAt(attrs.length - 1)
if (
!state.settings.tightSelfClosing ||
last === '/' ||
(last && last !== '"' && last !== "'")
) {
parts.push(' ')
}
parts.push('/')
}
parts.push('>')
}
parts.push(content)
if (!selfClosing && (!omit || !closing(node, index, parent))) {
parts.push('</' + node.tagName + '>')
}
return parts.join('')
}
/**
* @param {State} state
* @param {Properties | null | undefined} props
* @returns {string}
*/
function serializeAttributes(state, props) {
/** @type {Array<string>} */
const values = []
let index = -1
/** @type {string} */
let key
if (props) {
for (key in props) {
if (props[key] !== undefined && props[key] !== null) {
const value = serializeAttribute(state, key, props[key])
if (value) values.push(value)
}
}
}
while (++index < values.length) {
const last = state.settings.tightAttributes
? 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('')
}
/**
* @param {State} state
* @param {string} key
* @param {PropertyValue} value
* @returns {string}
*/
// eslint-disable-next-line complexity
function serializeAttribute(state, key, value) {
const info = find(state.schema, key)
const x =
state.settings.allowParseErrors && state.schema.space === 'html' ? 0 : 1
const y = state.settings.allowDangerousCharacters ? 0 : 1
let quote = state.quote
/** @type {string | undefined} */
let result
if (info.overloadedBoolean && (value === info.attribute || value === '')) {
value = true
} else if (
info.boolean ||
(info.overloadedBoolean && typeof value !== 'string')
) {
value = Boolean(value)
}
if (
value === undefined ||
value === null ||
value === false ||
(typeof value === 'number' && Number.isNaN(value))
) {
return ''
}
const name = stringifyEntities(
info.attribute,
Object.assign({}, state.settings.characterReferences, {
// Always encode without parse errors in non-HTML.
subset: constants.name[x][y]
})
)
// No value.
// There is currently only one boolean property in SVG: `[download]` on
// `<a>`.
// This property does not seem to work in browsers (Firefox, Safari, Chrome),
// 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
// `spaces` doesnt accept a second argument, but its given here just to
// keep the code cleaner.
value = Array.isArray(value)
? (info.commaSeparated ? commas : spaces)(value, {
padLeft: !state.settings.tightCommaSeparatedLists
})
: String(value)
if (state.settings.collapseEmptyAttributes && !value) return name
// Check unquoted value.
if (state.settings.preferUnquoted) {
result = stringifyEntities(
value,
Object.assign({}, state.settings.characterReferences, {
subset: constants.unquoted[x][y],
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 (
state.settings.quoteSmart &&
ccount(value, quote) > ccount(value, state.alternative)
) {
quote = state.alternative
}
result =
quote +
stringifyEntities(
value,
Object.assign({}, state.settings.characterReferences, {
// Always encode without parse errors in non-HTML.
subset: (quote === "'" ? constants.single : constants.double)[x][y],
attribute: true
})
) +
quote
}
// Dont add a `=` for unquoted empties.
return name + (result ? '=' + result : result)
}

13
node_modules/hast-util-to-html/lib/handle/handle.d.ts generated vendored Normal file
View file

@ -0,0 +1,13 @@
/**
* @type {(node: Node, index: number | undefined, parent: Parent | undefined, state: State) => string}
*/
export const handle: (
node: Node,
index: number | undefined,
parent: Parent | undefined,
state: State
) => string
export type Handle = import('./types.js').Handle
export type State = import('./types.js').State
export type Node = import('./types.js').Node
export type Parent = import('./types.js').Parent

12
node_modules/hast-util-to-html/lib/handle/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,12 @@
/**
* @type {(node: Node, index: number | undefined, parent: Parent | undefined, state: State) => string}
*/
export const handle: (
node: Node,
index: number | undefined,
parent: Parent | undefined,
state: State
) => string
export type State = import('../types.js').State
export type Node = import('../types.js').Node
export type Parent = import('../types.js').Parent

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

@ -0,0 +1,47 @@
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Node} Node
* @typedef {import('../types.js').Parent} Parent
*/
import {zwitch} from 'zwitch'
import {comment} from './comment.js'
import {doctype} from './doctype.js'
import {element} from './element.js'
import {raw} from './raw.js'
import {root} from './root.js'
import {text} from './text.js'
/**
* @type {(node: Node, index: number | undefined, parent: Parent | undefined, state: State) => string}
*/
export const handle = zwitch('type', {
invalid,
unknown,
handlers: {comment, doctype, element, raw, root, text}
})
/**
* Fail when a non-node is found in the tree.
*
* @param {unknown} node
* Unknown value.
* @returns {never}
* Never.
*/
function invalid(node) {
throw new Error('Expected node, not `' + node + '`')
}
/**
* Fail when a node with an unknown type is found in the tree.
*
* @param {unknown} node
* Unknown node.
* @returns {never}
* Never.
*/
function unknown(node) {
// @ts-expect-error: `type` is defined.
throw new Error('Cannot compile unknown node `' + node.type + '`')
}

23
node_modules/hast-util-to-html/lib/handle/raw.d.ts generated vendored Normal file
View file

@ -0,0 +1,23 @@
/**
* Serialize a raw node.
*
* @param {Raw} node
* Node to handle.
* @param {number | undefined} index
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function raw(
node: Raw,
index: number | undefined,
parent: Parent | undefined,
state: State
): string
export type State = import('../types.js').State
export type Parent = import('../types.js').Parent
export type Raw = import('../types.js').Raw

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

@ -0,0 +1,27 @@
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Raw} Raw
*/
import {text} from './text.js'
/**
* Serialize a raw node.
*
* @param {Raw} node
* Node to handle.
* @param {number | undefined} index
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function raw(node, index, parent, state) {
return state.settings.allowDangerousHtml
? node.value
: text(node, index, parent, state)
}

28
node_modules/hast-util-to-html/lib/handle/root.d.ts generated vendored Normal file
View file

@ -0,0 +1,28 @@
/**
* @typedef {import('../types.js').Root} Root
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').State} State
*/
/**
* Serialize a root.
*
* @param {Root} node
* Node to handle.
* @param {number | undefined} _1
* Index of `node` in `parent.
* @param {Parent | undefined} _2
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function root(
node: Root,
_1: number | undefined,
_2: Parent | undefined,
state: State
): string
export type Root = import('../types.js').Root
export type Parent = import('../types.js').Parent
export type State = import('../types.js').State

23
node_modules/hast-util-to-html/lib/handle/root.js generated vendored Normal file
View file

@ -0,0 +1,23 @@
/**
* @typedef {import('../types.js').Root} Root
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').State} State
*/
/**
* Serialize a root.
*
* @param {Root} node
* Node to handle.
* @param {number | undefined} _1
* Index of `node` in `parent.
* @param {Parent | undefined} _2
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function root(node, _1, _2, state) {
return state.all(node)
}

24
node_modules/hast-util-to-html/lib/handle/text.d.ts generated vendored Normal file
View file

@ -0,0 +1,24 @@
/**
* Serialize a text node.
*
* @param {Text | Raw} node
* Node to handle.
* @param {number | undefined} _
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function text(
node: Text | Raw,
_: number | undefined,
parent: Parent | undefined,
state: State
): string
export type State = import('../types.js').State
export type Parent = import('../types.js').Parent
export type Raw = import('../types.js').Raw
export type Text = import('../types.js').Text

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

@ -0,0 +1,36 @@
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Raw} Raw
* @typedef {import('../types.js').Text} Text
*/
import {stringifyEntities} from 'stringify-entities'
/**
* Serialize a text node.
*
* @param {Text | Raw} node
* Node to handle.
* @param {number | undefined} _
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function text(node, _, parent, state) {
// Check if content of `node` should be escaped.
return parent &&
parent.type === 'element' &&
(parent.tagName === 'script' || parent.tagName === 'style')
? node.value
: stringifyEntities(
node.value,
Object.assign({}, state.settings.characterReferences, {
subset: ['<', '&']
})
)
}

32
node_modules/hast-util-to-html/lib/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,32 @@
/**
* Serialize hast as HTML.
*
* @param {Node | Array<Content>} tree
* Tree to serialize.
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {string}
* Serialized HTML.
*/
export function toHtml(
tree: Node | Array<Content>,
options?: Options | null | undefined
): string
/**
* Serialize all children of `parent`.
*
* @this {State}
* Info passed around about the current state.
* @param {Parent | undefined} parent
* Parent whose children to serialize.
* @returns {string}
*/
export function all(
this: import('./types.js').State,
parent: Parent | undefined
): string
export type Node = import('./types.js').Node
export type Parent = import('./types.js').Parent
export type Content = import('./types.js').Content
export type Options = import('./types.js').Options
export type State = import('./types.js').State

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

@ -0,0 +1,107 @@
/**
* @typedef {import('./types.js').Node} Node
* @typedef {import('./types.js').Parent} Parent
* @typedef {import('./types.js').Content} Content
* @typedef {import('./types.js').Options} Options
* @typedef {import('./types.js').State} State
*/
import {html, svg} from 'property-information'
import {htmlVoidElements} from 'html-void-elements'
import {handle} from './handle/index.js'
/**
* Serialize hast as HTML.
*
* @param {Node | Array<Content>} tree
* Tree to serialize.
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {string}
* Serialized HTML.
*/
// eslint-disable-next-line complexity
export function toHtml(tree, options) {
const options_ = options || {}
const quote = options_.quote || '"'
const alternative = quote === '"' ? "'" : '"'
if (quote !== '"' && quote !== "'") {
throw new Error('Invalid quote `' + quote + '`, expected `\'` or `"`')
}
/** @type {State} */
const state = {
one,
all,
settings: {
omitOptionalTags: options_.omitOptionalTags || false,
allowParseErrors: options_.allowParseErrors || false,
allowDangerousCharacters: options_.allowDangerousCharacters || false,
quoteSmart: options_.quoteSmart || false,
preferUnquoted: options_.preferUnquoted || false,
tightAttributes: options_.tightAttributes || false,
upperDoctype: options_.upperDoctype || false,
tightDoctype: options_.tightDoctype || false,
bogusComments: options_.bogusComments || false,
tightCommaSeparatedLists: options_.tightCommaSeparatedLists || false,
tightSelfClosing: options_.tightSelfClosing || false,
collapseEmptyAttributes: options_.collapseEmptyAttributes || false,
allowDangerousHtml: options_.allowDangerousHtml || false,
voids: options_.voids || htmlVoidElements,
characterReferences:
options_.characterReferences || options_.entities || {},
closeSelfClosing: options_.closeSelfClosing || false,
closeEmptyElements: options_.closeEmptyElements || false
},
schema: options_.space === 'svg' ? svg : html,
quote,
alternative
}
return state.one(
Array.isArray(tree) ? {type: 'root', children: tree} : tree,
undefined,
undefined
)
}
/**
* Serialize a node.
*
* @this {State}
* Info passed around about the current state.
* @param {Node} node
* Node to handle.
* @param {number | undefined} index
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @returns {string}
* Serialized node.
*/
function one(node, index, parent) {
return handle(node, index, parent, this)
}
/**
* Serialize all children of `parent`.
*
* @this {State}
* Info passed around about the current state.
* @param {Parent | undefined} parent
* Parent whose children to serialize.
* @returns {string}
*/
export function all(parent) {
/** @type {Array<string>} */
const results = []
const children = (parent && parent.children) || []
let index = -1
while (++index < children.length) {
results[index] = this.one(children[index], index, parent)
}
return results.join('')
}

View file

@ -0,0 +1,3 @@
export const closing: import('../types.js').OmitHandle
export type Element = import('../types.js').Element
export type Parent = import('../types.js').Parent

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

@ -0,0 +1,384 @@
/**
* @typedef {import('../types.js').Element} Element
* @typedef {import('../types.js').Parent} Parent
*/
import {whitespace} from 'hast-util-whitespace'
import {siblingAfter} from './util/siblings.js'
import {omission} from './omission.js'
export const closing = omission({
html,
head: headOrColgroupOrCaption,
body,
p,
li,
dt,
dd,
rt: rubyElement,
rp: rubyElement,
optgroup,
option,
menuitem,
colgroup: headOrColgroupOrCaption,
caption: headOrColgroupOrCaption,
thead,
tbody,
tfoot,
tr,
td: cells,
th: cells
})
/**
* Macro for `</head>`, `</colgroup>`, and `</caption>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function headOrColgroupOrCaption(_, index, parent) {
const next = siblingAfter(parent, index, true)
return (
!next ||
(next.type !== 'comment' &&
!(next.type === 'text' && whitespace(next.value.charAt(0))))
)
}
/**
* Whether to omit `</html>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function html(_, index, parent) {
const next = siblingAfter(parent, index)
return !next || next.type !== 'comment'
}
/**
* Whether to omit `</body>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function body(_, index, parent) {
const next = siblingAfter(parent, index)
return !next || next.type !== 'comment'
}
/**
* Whether to omit `</p>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
// eslint-disable-next-line complexity
function p(_, index, parent) {
const next = siblingAfter(parent, index)
return next
? next.type === 'element' &&
(next.tagName === 'address' ||
next.tagName === 'article' ||
next.tagName === 'aside' ||
next.tagName === 'blockquote' ||
next.tagName === 'details' ||
next.tagName === 'div' ||
next.tagName === 'dl' ||
next.tagName === 'fieldset' ||
next.tagName === 'figcaption' ||
next.tagName === 'figure' ||
next.tagName === 'footer' ||
next.tagName === 'form' ||
next.tagName === 'h1' ||
next.tagName === 'h2' ||
next.tagName === 'h3' ||
next.tagName === 'h4' ||
next.tagName === 'h5' ||
next.tagName === 'h6' ||
next.tagName === 'header' ||
next.tagName === 'hgroup' ||
next.tagName === 'hr' ||
next.tagName === 'main' ||
next.tagName === 'menu' ||
next.tagName === 'nav' ||
next.tagName === 'ol' ||
next.tagName === 'p' ||
next.tagName === 'pre' ||
next.tagName === 'section' ||
next.tagName === 'table' ||
next.tagName === 'ul')
: !parent ||
// Confusing parent.
!(
parent.type === 'element' &&
(parent.tagName === 'a' ||
parent.tagName === 'audio' ||
parent.tagName === 'del' ||
parent.tagName === 'ins' ||
parent.tagName === 'map' ||
parent.tagName === 'noscript' ||
parent.tagName === 'video')
)
}
/**
* Whether to omit `</li>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function li(_, index, parent) {
const next = siblingAfter(parent, index)
return !next || (next.type === 'element' && next.tagName === 'li')
}
/**
* Whether to omit `</dt>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function dt(_, index, parent) {
const next = siblingAfter(parent, index)
return (
next &&
next.type === 'element' &&
(next.tagName === 'dt' || next.tagName === 'dd')
)
}
/**
* Whether to omit `</dd>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function dd(_, index, parent) {
const next = siblingAfter(parent, index)
return (
!next ||
(next.type === 'element' &&
(next.tagName === 'dt' || next.tagName === 'dd'))
)
}
/**
* Whether to omit `</rt>` or `</rp>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function rubyElement(_, index, parent) {
const next = siblingAfter(parent, index)
return (
!next ||
(next.type === 'element' &&
(next.tagName === 'rp' || next.tagName === 'rt'))
)
}
/**
* Whether to omit `</optgroup>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function optgroup(_, index, parent) {
const next = siblingAfter(parent, index)
return !next || (next.type === 'element' && next.tagName === 'optgroup')
}
/**
* Whether to omit `</option>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function option(_, index, parent) {
const next = siblingAfter(parent, index)
return (
!next ||
(next.type === 'element' &&
(next.tagName === 'option' || next.tagName === 'optgroup'))
)
}
/**
* Whether to omit `</menuitem>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function menuitem(_, index, parent) {
const next = siblingAfter(parent, index)
return (
!next ||
(next.type === 'element' &&
(next.tagName === 'menuitem' ||
next.tagName === 'hr' ||
next.tagName === 'menu'))
)
}
/**
* Whether to omit `</thead>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function thead(_, index, parent) {
const next = siblingAfter(parent, index)
return (
next &&
next.type === 'element' &&
(next.tagName === 'tbody' || next.tagName === 'tfoot')
)
}
/**
* Whether to omit `</tbody>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function tbody(_, index, parent) {
const next = siblingAfter(parent, index)
return (
!next ||
(next.type === 'element' &&
(next.tagName === 'tbody' || next.tagName === 'tfoot'))
)
}
/**
* Whether to omit `</tfoot>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function tfoot(_, index, parent) {
return !siblingAfter(parent, index)
}
/**
* Whether to omit `</tr>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function tr(_, index, parent) {
const next = siblingAfter(parent, index)
return !next || (next.type === 'element' && next.tagName === 'tr')
}
/**
* Whether to omit `</td>` or `</th>`.
*
* @param {Element} _
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the closing tag can be omitted.
*/
function cells(_, index, parent) {
const next = siblingAfter(parent, index)
return (
!next ||
(next.type === 'element' &&
(next.tagName === 'td' || next.tagName === 'th'))
)
}

View file

@ -0,0 +1,11 @@
/**
* Factory to check if a given node can have a tag omitted.
*
* @param {Record<string, OmitHandle>} handlers
* Omission handlers, where each key is a tag name, and each value is the
* corresponding handler.
* @returns {OmitHandle}
* Whether to omit a tag of an element.
*/
export function omission(handlers: Record<string, OmitHandle>): OmitHandle
export type OmitHandle = import('../types.js').OmitHandle

View file

@ -0,0 +1,30 @@
/**
* @typedef {import('../types.js').OmitHandle} OmitHandle
*/
const own = {}.hasOwnProperty
/**
* Factory to check if a given node can have a tag omitted.
*
* @param {Record<string, OmitHandle>} handlers
* Omission handlers, where each key is a tag name, and each value is the
* corresponding handler.
* @returns {OmitHandle}
* Whether to omit a tag of an element.
*/
export function omission(handlers) {
return omit
/**
* Check if a given node can have a tag omitted.
*
* @type {OmitHandle}
*/
function omit(node, index, parent) {
return (
own.call(handlers, node.tagName) &&
handlers[node.tagName](node, index, parent)
)
}
}

View file

@ -0,0 +1,4 @@
export const opening: import('../types.js').OmitHandle
export type Element = import('../types.js').Element
export type Parent = import('../types.js').Parent
export type Content = import('../types.js').Content

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

@ -0,0 +1,148 @@
/**
* @typedef {import('../types.js').Element} Element
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Content} Content
*/
import {whitespace} from 'hast-util-whitespace'
import {siblingBefore, siblingAfter} from './util/siblings.js'
import {closing} from './closing.js'
import {omission} from './omission.js'
export const opening = omission({
html,
head,
body,
colgroup,
tbody
})
/**
* Whether to omit `<html>`.
*
* @param {Element} node
* Element.
* @returns {boolean}
* Whether the opening tag can be omitted.
*/
function html(node) {
const head = siblingAfter(node, -1)
return !head || head.type !== 'comment'
}
/**
* Whether to omit `<head>`.
*
* @param {Element} node
* Element.
* @returns {boolean}
* Whether the opening tag can be omitted.
*/
function head(node) {
const children = node.children
/** @type {Array<string>} */
const seen = []
let index = -1
while (++index < children.length) {
const child = children[index]
if (
child.type === 'element' &&
(child.tagName === 'title' || child.tagName === 'base')
) {
if (seen.includes(child.tagName)) return false
seen.push(child.tagName)
}
}
return children.length > 0
}
/**
* Whether to omit `<body>`.
*
* @param {Element} node
* Element.
* @returns {boolean}
* Whether the opening tag can be omitted.
*/
function body(node) {
const head = siblingAfter(node, -1, true)
return (
!head ||
(head.type !== 'comment' &&
!(head.type === 'text' && whitespace(head.value.charAt(0))) &&
!(
head.type === 'element' &&
(head.tagName === 'meta' ||
head.tagName === 'link' ||
head.tagName === 'script' ||
head.tagName === 'style' ||
head.tagName === '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.
*
* @param {Element} node
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the opening tag can be omitted.
*/
function colgroup(node, index, parent) {
const previous = siblingBefore(parent, index)
const head = siblingAfter(node, -1, true)
// Previous colgroup was already omitted.
if (
parent &&
previous &&
previous.type === 'element' &&
previous.tagName === 'colgroup' &&
closing(previous, parent.children.indexOf(previous), parent)
) {
return false
}
return head && head.type === 'element' && head.tagName === 'col'
}
/**
* Whether to omit `<tbody>`.
*
* @param {Element} node
* Element.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether the opening tag can be omitted.
*/
function tbody(node, index, parent) {
const previous = siblingBefore(parent, index)
const head = siblingAfter(node, -1)
// Previous table section was already omitted.
if (
parent &&
previous &&
previous.type === 'element' &&
(previous.tagName === 'thead' || previous.tagName === 'tbody') &&
closing(previous, parent.children.indexOf(previous), parent)
) {
return false
}
return head && head.type === 'element' && head.tagName === 'tr'
}

View file

@ -0,0 +1,11 @@
/**
* @typedef {import('../../types.js').Node} Node
* @typedef {import('../../types.js').Comment} Comment
*/
/**
* @param {Node} node
* @returns {node is Comment}
*/
export function comment(node: Node): node is import('hast').Comment
export type Node = import('../../types.js').Node
export type Comment = import('../../types.js').Comment

View file

@ -0,0 +1,28 @@
/**
* Find applicable siblings in a direction.
*
* @param {Parent | null | undefined} parent
* @param {number | null | undefined} index
* @param {boolean | null | undefined} [includeWhitespace=false]
* @returns {Content}
*/
export function siblingAfter(
parent: Parent | null | undefined,
index: number | null | undefined,
includeWhitespace?: boolean | null | undefined
): Content
/**
* Find applicable siblings in a direction.
*
* @param {Parent | null | undefined} parent
* @param {number | null | undefined} index
* @param {boolean | null | undefined} [includeWhitespace=false]
* @returns {Content}
*/
export function siblingBefore(
parent: Parent | null | undefined,
index: number | null | undefined,
includeWhitespace?: boolean | null | undefined
): Content
export type Parent = import('../../types.js').Parent
export type Content = import('../../types.js').Content

View file

@ -0,0 +1,41 @@
/**
* @typedef {import('../../types.js').Parent} Parent
* @typedef {import('../../types.js').Content} Content
*/
import {whitespace} from 'hast-util-whitespace'
export const siblingAfter = siblings(1)
export const siblingBefore = siblings(-1)
/**
* Factory to check siblings in a direction.
*
* @param {number} increment
*/
function siblings(increment) {
return sibling
/**
* Find applicable siblings in a direction.
*
* @param {Parent | null | undefined} parent
* @param {number | null | undefined} index
* @param {boolean | null | undefined} [includeWhitespace=false]
* @returns {Content}
*/
function sibling(parent, index, includeWhitespace) {
const siblings = parent ? parent.children : []
let offset = (index || 0) + increment
let next = siblings && siblings[offset]
if (!includeWhitespace) {
while (next && whitespace(next)) {
offset += increment
next = siblings[offset]
}
}
return next
}
}

363
node_modules/hast-util-to-html/lib/types.d.ts generated vendored Normal file
View file

@ -0,0 +1,363 @@
export type UnistParent = import('unist').Parent
export type UnistLiteral = import('unist').Literal
export type Root = import('hast').Root
export type Comment = import('hast').Comment
export type DocType = import('hast').DocType
export type Element = import('hast').Element
export type Text = import('hast').Text
export type Content = import('hast').Content
export type Properties = import('hast').Properties
export type Raw = import('hast-util-raw/complex-types.js').Raw
export type StringifyEntitiesOptions = import('stringify-entities').Options
export type Schema = import('property-information').Schema
export type Node = Content | Root
export type Parent = Extract<Node, UnistParent>
export type PropertyValue = Properties[keyof Properties]
/**
* Check if a tag can be omitted.
*/
export type OmitHandle = (
element: Element,
index: number | undefined,
parent: Parent | undefined
) => boolean
/**
* Namespace.
*/
export type Space = 'html' | 'svg'
export type CharacterReferences = Omit<
StringifyEntitiesOptions,
'escapeOnly' | 'attribute' | 'subset'
>
/**
* HTML quotes for attribute values.
*/
export type Quote = '"' | "'"
/**
* Configuration.
*/
export type Options = {
/**
* Do not encode some characters which cause XSS vulnerabilities in older
* browsers.
*
* > **Danger**: only set this if you completely trust the content.
*/
allowDangerousCharacters?: boolean | null | undefined
/**
* Allow `raw` nodes and insert them as raw HTML.
*
* When `false`, `Raw` nodes are encoded.
*
* > **Danger**: only set this if you completely trust the content.
*/
allowDangerousHtml?: boolean | null | undefined
/**
* Do not encode characters which cause parse errors (even though they work),
* to save bytes.
*
* Not used in the SVG space.
*
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
* > errors are handled is well defined, so this works but isnt pretty).
*/
allowParseErrors?: boolean | null | undefined
/**
* Use bogus comments instead of comments to save byes: `<?charlie>`
* instead of `<!--charlie-->`.
*
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
* > errors are handled is well defined, so this works but isnt pretty).
*/
bogusComments?: boolean | null | undefined
/**
* Configure how to serialize character references.
*/
characterReferences?: CharacterReferences | null | undefined
/**
* 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.
*/
closeEmptyElements?: boolean | null | undefined
/**
* 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.
*/
closeSelfClosing?: boolean | null | undefined
/**
* Collapse empty attributes: get `class` instead of `class=""`.
*
* Not used in the SVG space.
*
* > 👉 **Note**: boolean attributes (such as `hidden`) are always collapsed.
*/
collapseEmptyAttributes?: boolean | null | undefined
/**
* Deprecated: please use `characterReferences`.
*/
entities?: CharacterReferences | null | undefined
/**
* 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.
*/
omitOptionalTags?: boolean | null | undefined
/**
* Leave attributes unquoted if that results in less bytes.
*
* Not used in the SVG space.
*/
preferUnquoted?: boolean | null | undefined
/**
* Preferred quote to use.
*/
quote?: Quote | null | undefined
/**
* Use the other quote if that results in less bytes.
*/
quoteSmart?: boolean | null | undefined
/**
* When an `<svg>` element is found in the HTML space, this package already
* automatically switches to and from the SVG space when entering and exiting
* it.
*
* > 👉 **Note**: hast is not XML.
* > It supports SVG as embedded in HTML.
* > It does not support the features available in XML.
* > Passing SVG might break but fragments of modern SVG should be fine.
* > Use [`xast`][xast] if you need to support SVG as XML.
*/
space?: Space | null | undefined
/**
* Join attributes together, without whitespace, if possible: get
* `class="a b"title="c d"` instead of `class="a b" title="c d"` to save
* bytes.
*
* Not used in the SVG space.
*
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
* > errors are handled is well defined, so this works but isnt pretty).
*/
tightAttributes?: boolean | null | undefined
/**
* Join known comma-separated attribute values with just a comma (`,`),
* instead of padding them on the right as well (`,␠`, where `` represents a
* space).
*/
tightCommaSeparatedLists?: boolean | null | undefined
/**
* Drop unneeded spaces in doctypes: `<!doctypehtml>` instead of
* `<!doctype html>` to save bytes.
*
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
* > errors are handled is well defined, so this works but isnt pretty).
*/
tightDoctype?: boolean | null | undefined
/**
* Do not use an extra space when closing self-closing elements: `<img/>`
* instead of `<img />`.
*
* > 👉 **Note**: only used if `closeSelfClosing: true` or
* > `closeEmptyElements: true`.
*/
tightSelfClosing?: boolean | null | undefined
/**
* Use a `<!DOCTYPE…` instead of `<!doctype…`.
*
* Useless except for XHTML.
*/
upperDoctype?: boolean | null | undefined
/**
* Tag names of elements to serialize without closing tag.
*
* Not used in the SVG space.
*
* > 👉 **Note**: Its highly unlikely that you want to pass this, because
* > hast is not for XML, and HTML will not add more void elements.
*/
voids?: ReadonlyArray<string> | null | undefined
}
export type Settings = {
/**
* Do not encode some characters which cause XSS vulnerabilities in older
* browsers.
*
* > **Danger**: only set this if you completely trust the content.
*/
allowDangerousCharacters: boolean
/**
* Allow `raw` nodes and insert them as raw HTML.
*
* When `false`, `Raw` nodes are encoded.
*
* > **Danger**: only set this if you completely trust the content.
*/
allowDangerousHtml: boolean
/**
* Do not encode characters which cause parse errors (even though they work),
* to save bytes.
*
* Not used in the SVG space.
*
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
* > errors are handled is well defined, so this works but isnt pretty).
*/
allowParseErrors: boolean
/**
* Use bogus comments instead of comments to save byes: `<?charlie>`
* instead of `<!--charlie-->`.
*
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
* > errors are handled is well defined, so this works but isnt pretty).
*/
bogusComments: boolean
/**
* Configure how to serialize character references.
*/
characterReferences: CharacterReferences
/**
* 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.
*/
closeEmptyElements: 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.
*/
closeSelfClosing: boolean
/**
* Collapse empty attributes: get `class` instead of `class=""`.
*
* Not used in the SVG space.
*
* > 👉 **Note**: boolean attributes (such as `hidden`) are always collapsed.
*/
collapseEmptyAttributes: 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.
*/
omitOptionalTags: boolean
/**
* Leave attributes unquoted if that results in less bytes.
*
* Not used in the SVG space.
*/
preferUnquoted: boolean
/**
* Use the other quote if that results in less bytes.
*/
quoteSmart: boolean
/**
* Join attributes together, without whitespace, if possible: get
* `class="a b"title="c d"` instead of `class="a b" title="c d"` to save
* bytes.
*
* Not used in the SVG space.
*
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
* > errors are handled is well defined, so this works but isnt pretty).
*/
tightAttributes: boolean
/**
* Join known comma-separated attribute values with just a comma (`,`),
* instead of padding them on the right as well (`,␠`, where `` represents a
* space).
*/
tightCommaSeparatedLists: boolean
/**
* Drop unneeded spaces in doctypes: `<!doctypehtml>` instead of
* `<!doctype html>` to save bytes.
*
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
* > errors are handled is well defined, so this works but isnt pretty).
*/
tightDoctype: 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`.
*/
tightSelfClosing: boolean
/**
* Use a `<!DOCTYPE…` instead of `<!doctype…`.
*
* Useless except for XHTML.
*/
upperDoctype: boolean
/**
* Tag names of elements to serialize without closing tag.
*
* Not used in the SVG space.
*
* > 👉 **Note**: Its highly unlikely that you want to pass this, because
* > hast is not for XML, and HTML will not add more void elements.
*/
voids: readonly string[]
}
/**
* Info passed around about the current state.
*/
export type State = {
/**
* Serialize one node.
*/
one: (
node: Node,
index: number | undefined,
parent: Parent | undefined
) => string
/**
* Serialize the children of a parent node.
*/
all: (node: Parent | undefined) => string
/**
* User configuration.
*/
settings: Settings
/**
* Current schema.
*/
schema: Schema
/**
* Preferred quote.
*/
quote: Quote
/**
* Alternative quote.
*/
alternative: Quote
}

175
node_modules/hast-util-to-html/lib/types.js generated vendored Normal file
View file

@ -0,0 +1,175 @@
/**
* @typedef {import('unist').Parent} UnistParent
* @typedef {import('unist').Literal} UnistLiteral
* @typedef {import('hast').Root} Root
* @typedef {import('hast').Comment} Comment
* @typedef {import('hast').DocType} DocType
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Text} Text
* @typedef {import('hast').Content} Content
* @typedef {import('hast').Properties} Properties
* @typedef {import('hast-util-raw/complex-types.js').Raw} Raw
* @typedef {import('stringify-entities').Options} StringifyEntitiesOptions
* @typedef {import('property-information').Schema} Schema
*/
/**
* @typedef {Content | Root} Node
* @typedef {Extract<Node, UnistParent>} Parent
* @typedef {Properties[keyof Properties]} PropertyValue
*
* @callback OmitHandle
* Check if a tag can be omitted.
* @param {Element} element
* Element to check.
* @param {number | undefined} index
* Index of element in parent.
* @param {Parent | undefined} parent
* Parent of element.
* @returns {boolean}
* Whether to omit a tag.
*
* @typedef {'html' | 'svg'} Space
* Namespace.
*
* @typedef {Omit<StringifyEntitiesOptions, 'escapeOnly' | 'attribute' | 'subset'>} CharacterReferences
*
* @typedef {'"' | "'"} Quote
* HTML quotes for attribute values.
*
* @typedef Options
* Configuration.
* @property {boolean | null | undefined} [allowDangerousCharacters=false]
* Do not encode some characters which cause XSS vulnerabilities in older
* browsers.
*
* > **Danger**: only set this if you completely trust the content.
* @property {boolean | null | undefined} [allowDangerousHtml=false]
* Allow `raw` nodes and insert them as raw HTML.
*
* When `false`, `Raw` nodes are encoded.
*
* > **Danger**: only set this if you completely trust the content.
* @property {boolean | null | undefined} [allowParseErrors=false]
* Do not encode characters which cause parse errors (even though they work),
* to save bytes.
*
* Not used in the SVG space.
*
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
* > errors are handled is well defined, so this works but isnt pretty).
* @property {boolean | null | undefined} [bogusComments=false]
* Use bogus comments instead of comments to save byes: `<?charlie>`
* instead of `<!--charlie-->`.
*
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
* > errors are handled is well defined, so this works but isnt pretty).
* @property {CharacterReferences | null | undefined} [characterReferences]
* Configure how to serialize character references.
* @property {boolean | null | undefined} [closeEmptyElements=false]
* 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.
* @property {boolean | null | undefined} [closeSelfClosing=false]
* 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.
* @property {boolean | null | undefined} [collapseEmptyAttributes=false]
* Collapse empty attributes: get `class` instead of `class=""`.
*
* Not used in the SVG space.
*
* > 👉 **Note**: boolean attributes (such as `hidden`) are always collapsed.
* @property {CharacterReferences | null | undefined} [entities]
* Deprecated: please use `characterReferences`.
* @property {boolean | null | undefined} [omitOptionalTags=false]
* 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.
* @property {boolean | null | undefined} [preferUnquoted=false]
* Leave attributes unquoted if that results in less bytes.
*
* Not used in the SVG space.
* @property {Quote | null | undefined} [quote='"']
* Preferred quote to use.
* @property {boolean | null | undefined} [quoteSmart=false]
* Use the other quote if that results in less bytes.
* @property {Space | null | undefined} [space='html']
* When an `<svg>` element is found in the HTML space, this package already
* automatically switches to and from the SVG space when entering and exiting
* it.
*
* > 👉 **Note**: hast is not XML.
* > It supports SVG as embedded in HTML.
* > It does not support the features available in XML.
* > Passing SVG might break but fragments of modern SVG should be fine.
* > Use [`xast`][xast] if you need to support SVG as XML.
* @property {boolean | null | undefined} [tightAttributes=false]
* Join attributes together, without whitespace, if possible: get
* `class="a b"title="c d"` instead of `class="a b" title="c d"` to save
* bytes.
*
* Not used in the SVG space.
*
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
* > errors are handled is well defined, so this works but isnt pretty).
* @property {boolean | null | undefined} [tightCommaSeparatedLists=false]
* Join known comma-separated attribute values with just a comma (`,`),
* instead of padding them on the right as well (`,␠`, where `` represents a
* space).
* @property {boolean | null | undefined} [tightDoctype=false]
* Drop unneeded spaces in doctypes: `<!doctypehtml>` instead of
* `<!doctype html>` to save bytes.
*
* > 👉 **Note**: intentionally creates parse errors in markup (how parse
* > errors are handled is well defined, so this works but isnt pretty).
* @property {boolean | null | undefined} [tightSelfClosing=false]
* Do not use an extra space when closing self-closing elements: `<img/>`
* instead of `<img />`.
*
* > 👉 **Note**: only used if `closeSelfClosing: true` or
* > `closeEmptyElements: true`.
* @property {boolean | null | undefined} [upperDoctype=false]
* Use a `<!DOCTYPE…` instead of `<!doctype…`.
*
* Useless except for XHTML.
* @property {ReadonlyArray<string> | null | undefined} [voids]
* Tag names of elements to serialize without closing tag.
*
* Not used in the SVG space.
*
* > 👉 **Note**: Its highly unlikely that you want to pass this, because
* > hast is not for XML, and HTML will not add more void elements.
*
* @typedef {Omit<Required<{[key in keyof Options]: Exclude<Options[key], null | undefined>}>, 'quote' | 'entities' | 'space'>} Settings
*
* @typedef State
* Info passed around about the current state.
* @property {(node: Node, index: number | undefined, parent: Parent | undefined) => string} one
* Serialize one node.
* @property {(node: Parent | undefined) => string} all
* Serialize the children of a parent node.
* @property {Settings} settings
* User configuration.
* @property {Schema} schema
* Current schema.
* @property {Quote} quote
* Preferred quote.
* @property {Quote} alternative
* Alternative quote.
*/
export {}

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.

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

@ -0,0 +1,94 @@
{
"name": "hast-util-to-html",
"version": "8.0.4",
"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)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/hast": "^2.0.0",
"@types/unist": "^2.0.0",
"ccount": "^2.0.0",
"comma-separated-tokens": "^2.0.0",
"hast-util-raw": "^7.0.0",
"hast-util-whitespace": "^2.0.0",
"html-void-elements": "^2.0.0",
"property-information": "^6.0.0",
"space-separated-tokens": "^2.0.0",
"stringify-entities": "^4.0.0",
"zwitch": "^2.0.4"
},
"devDependencies": {
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"hastscript": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-builder": "^3.0.0",
"xo": "^0.53.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true
},
"remarkConfig": {
"plugins": [
"preset-wooorm",
[
"remark-lint-no-html",
false
]
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}

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

@ -0,0 +1,451 @@
# 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][] utility to serialize hast as HTML.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`toHtml(tree[, options])`](#tohtmltree-options)
* [`CharacterReferences`](#characterreferences)
* [`Options`](#options)
* [`Quote`](#quote-1)
* [`Space`](#space-1)
* [Syntax](#syntax)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a utility that turns a hast tree into a string of HTML.
## When should I use this?
You can use this utility when you want to get the serialized HTML that is
represented by the syntax tree, either because youre done with the syntax
tree, or because youre integrating with another tool that does not support
syntax trees.
This utility has many options to configure how the HTML is serialized.
These options help when building tools that make output pretty (such as
formatters) or ugly (such as minifiers).
The utility [`hast-util-from-html`][hast-util-from-html] does the inverse of
this utility.
It turns HTML into hast.
The rehype plugin [`rehype-stringify`][rehype-stringify] wraps this utility to
also serialize HTML at a higher-level (easier) abstraction.
## Install
This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
```sh
npm install hast-util-to-html
```
In Deno with [`esm.sh`][esmsh]:
```js
import {toHtml} from "https://esm.sh/hast-util-to-html@8"
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {toHtml} from "https://esm.sh/hast-util-to-html@8?bundle"
</script>
```
## Use
<details><summary>Show install command for this example</summary>
```sh
npm install hastscript hast-util-to-html
```
</details>
```js
import {h} from 'hastscript'
import {toHtml} from '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
This package exports the identifier [`toHtml`][tohtml].
There is no default export.
### `toHtml(tree[, options])`
Serialize hast as HTML.
###### Parameters
* `tree` ([`Node`][node] or `Array<Node>`)
— tree to serialize
* `options` ([`Options`][options], optional)
— configuration
###### Returns
Serialized HTML (`string`).
### `CharacterReferences`
How to serialize character references (TypeScript type).
##### Fields
###### `useNamedReferences`
Prefer named character references (`&amp;`) where possible (`boolean`, default:
`false`).
###### `useShortestReferences`
Prefer the shortest possible reference, if that results in less bytes
(`boolean`, default: `false`).
> ⚠️ **Note**: `useNamedReferences` can be omitted when using
> `useShortestReferences`.
###### `omitOptionalSemicolons`
Whether to omit semicolons when possible (`boolean`, default: `false`).
> ⚠️ **Note**: this creates what HTML calls “parse errors” but is otherwise
> still valid HTML — dont use this except when building a minifier.
> Omitting semicolons is possible for certain named and numeric references in
> some cases.
### `Options`
Configuration (TypeScript type).
##### Fields
###### `allowDangerousCharacters`
Do not encode some characters which cause XSS vulnerabilities in older browsers
(`boolean`, default: `false`).
> ⚠️ **Danger**: only set this if you completely trust the content.
###### `allowDangerousHtml`
Allow `raw` nodes and insert them as raw HTML (`boolean`, default: `false`).
When `false`, `Raw` nodes are encoded.
> ⚠️ **Danger**: only set this if you completely trust the content.
###### `allowParseErrors`
Do not encode characters which cause parse errors (even though they work), to
save bytes (`boolean`, default: `false`).
Not used in the SVG space.
> 👉 **Note**: intentionally creates parse errors in markup (how parse errors
> are handled is well defined, so this works but isnt pretty).
###### `bogusComments`
Use “bogus comments” instead of comments to save byes: `<?charlie>` instead of
`<!--charlie-->` (`boolean`, default: `false`).
> 👉 **Note**: intentionally creates parse errors in markup (how parse errors
> are handled is well defined, so this works but isnt pretty).
###### `characterReferences`
Configure how to serialize character references
([`CharacterReferences`][characterreferences], optional).
###### `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.
###### `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.
###### `collapseEmptyAttributes`
Collapse empty attributes: get `class` instead of `class=""` (`boolean`,
default: `false`).
Not used in the SVG space.
> 👉 **Note**: boolean attributes (such as `hidden`) are always collapsed.
###### `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.
###### `preferUnquoted`
Leave attributes unquoted if that results in less bytes (`boolean`, default:
`false`).
Not used in the SVG space.
###### `quote`
Preferred quote to use ([`Quote`][quote], default: `'"'`).
###### `quoteSmart`
Use the other quote if that results in less bytes (`boolean`, default: `false`).
###### `space`
Which space the document is in ([`Space`][space], default: `'html'`).
When an `<svg>` element is found in the HTML space, this package already
automatically switches to and from the SVG space when entering and exiting it.
> 👉 **Note**: hast is not XML.
> It supports SVG as embedded in HTML.
> It does not support the features available in XML.
> Passing SVG might break but fragments of modern SVG should be fine.
> Use [`xast`][xast] if you need to support SVG as XML.
###### `tightAttributes`
Join attributes together, without whitespace, if possible: get
`class="a b"title="c d"` instead of `class="a b" title="c d"` to save bytes
(`boolean`, default: `false`).
Not used in the SVG space.
> 👉 **Note**: intentionally creates parse errors in markup (how parse errors
> are handled is well defined, so this works but isnt pretty).
###### `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`).
###### `tightDoctype`
Drop unneeded spaces in doctypes: `<!doctypehtml>` instead of `<!doctype html>`
to save bytes (`boolean`, default: `false`).
> 👉 **Note**: intentionally creates parse errors in markup (how parse errors
> are handled is well defined, so this works but isnt pretty).
###### `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`.
###### `upperDoctype`
Use a `<!DOCTYPE…` instead of `<!doctype…` (`boolean`, default: `false`).
Useless except for XHTML.
###### `voids`
Tag names of elements to serialize without closing tag (`Array<string>`,
default: [`html-void-elements`][html-void-elements]).
Not used in the SVG space.
> 👉 **Note**: Its highly unlikely that you want to pass this, because hast is
> not for XML, and HTML will not add more void elements.
### `Quote`
HTML quotes for attribute values (TypeScript type).
###### Type
```ts
type Quote = '"' | "'"
```
### `Space`
Namespace (TypeScript type).
###### Type
```ts
type Space = 'html' | 'svg'
```
## Syntax
HTML is serialized according to WHATWG HTML (the living standard), which is also
followed by browsers such as Chrome and Firefox.
## Types
This package is fully typed with [TypeScript][].
It exports the additional types [`CharacterReferences`][characterreferences],
[`Options`][options], [`Quote`][quote], and [`Space`][space].
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
## 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`][hast-util-sanitize] to make the hast tree safe.
## Related
* [`hast-util-sanitize`](https://github.com/syntax-tree/hast-util-sanitize)
— sanitize hast
## Contribute
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] 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
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[typescript]: https://www.typescriptlang.org
[license]: license
[author]: https://wooorm.com
[health]: https://github.com/syntax-tree/.github
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[hast]: https://github.com/syntax-tree/hast
[node]: https://github.com/syntax-tree/hast#nodes
[html-void-elements]: https://github.com/wooorm/html-void-elements
[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize
[hast-util-from-html]: https://github.com/syntax-tree/hast-util-from-html
[rehype-stringify]: https://github.com/rehypejs/rehype/tree/main/packages/rehype-stringify#readme
[xast]: https://github.com/syntax-tree/xast
[tohtml]: #tohtmltree-options
[characterreferences]: #characterreferences
[options]: #options
[space]: #space
[quote]: #quote