🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
13
node_modules/hast-util-to-html/lib/constants.d.ts
generated
vendored
Normal file
13
node_modules/hast-util-to-html/lib/constants.d.ts
generated
vendored
Normal 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
23
node_modules/hast-util-to-html/lib/handle/comment.d.ts
generated
vendored
Normal 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
45
node_modules/hast-util-to-html/lib/handle/comment.js
generated
vendored
Normal 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
28
node_modules/hast-util-to-html/lib/handle/doctype.d.ts
generated
vendored
Normal 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
28
node_modules/hast-util-to-html/lib/handle/doctype.js
generated
vendored
Normal 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
25
node_modules/hast-util-to-html/lib/handle/element.d.ts
generated
vendored
Normal 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
268
node_modules/hast-util-to-html/lib/handle/element.js
generated
vendored
Normal 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, don’t 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 can’t 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` doesn’t accept a second argument, but it’s 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 don’t 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
|
||||
}
|
||||
|
||||
// Don’t 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
13
node_modules/hast-util-to-html/lib/handle/handle.d.ts
generated
vendored
Normal 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
12
node_modules/hast-util-to-html/lib/handle/index.d.ts
generated
vendored
Normal 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
47
node_modules/hast-util-to-html/lib/handle/index.js
generated
vendored
Normal 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
23
node_modules/hast-util-to-html/lib/handle/raw.d.ts
generated
vendored
Normal 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
27
node_modules/hast-util-to-html/lib/handle/raw.js
generated
vendored
Normal 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
28
node_modules/hast-util-to-html/lib/handle/root.d.ts
generated
vendored
Normal 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
23
node_modules/hast-util-to-html/lib/handle/root.js
generated
vendored
Normal 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
24
node_modules/hast-util-to-html/lib/handle/text.d.ts
generated
vendored
Normal 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
36
node_modules/hast-util-to-html/lib/handle/text.js
generated
vendored
Normal 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
32
node_modules/hast-util-to-html/lib/index.d.ts
generated
vendored
Normal 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
107
node_modules/hast-util-to-html/lib/index.js
generated
vendored
Normal 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('')
|
||||
}
|
3
node_modules/hast-util-to-html/lib/omission/closing.d.ts
generated
vendored
Normal file
3
node_modules/hast-util-to-html/lib/omission/closing.d.ts
generated
vendored
Normal 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
384
node_modules/hast-util-to-html/lib/omission/closing.js
generated
vendored
Normal 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'))
|
||||
)
|
||||
}
|
11
node_modules/hast-util-to-html/lib/omission/omission.d.ts
generated
vendored
Normal file
11
node_modules/hast-util-to-html/lib/omission/omission.d.ts
generated
vendored
Normal 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
|
30
node_modules/hast-util-to-html/lib/omission/omission.js
generated
vendored
Normal file
30
node_modules/hast-util-to-html/lib/omission/omission.js
generated
vendored
Normal 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)
|
||||
)
|
||||
}
|
||||
}
|
4
node_modules/hast-util-to-html/lib/omission/opening.d.ts
generated
vendored
Normal file
4
node_modules/hast-util-to-html/lib/omission/opening.d.ts
generated
vendored
Normal 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
148
node_modules/hast-util-to-html/lib/omission/opening.js
generated
vendored
Normal 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 it’s 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'
|
||||
}
|
11
node_modules/hast-util-to-html/lib/omission/util/comment.d.ts
generated
vendored
Normal file
11
node_modules/hast-util-to-html/lib/omission/util/comment.d.ts
generated
vendored
Normal 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
|
28
node_modules/hast-util-to-html/lib/omission/util/siblings.d.ts
generated
vendored
Normal file
28
node_modules/hast-util-to-html/lib/omission/util/siblings.d.ts
generated
vendored
Normal 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
|
41
node_modules/hast-util-to-html/lib/omission/util/siblings.js
generated
vendored
Normal file
41
node_modules/hast-util-to-html/lib/omission/util/siblings.js
generated
vendored
Normal 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
363
node_modules/hast-util-to-html/lib/types.d.ts
generated
vendored
Normal 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 isn’t 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 isn’t 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 it’s followed by another `li`, the last because it’s
|
||||
* 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 isn’t 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 isn’t 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**: It’s 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 isn’t 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 isn’t 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 it’s followed by another `li`, the last because it’s
|
||||
* 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 isn’t 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 isn’t 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**: It’s 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
175
node_modules/hast-util-to-html/lib/types.js
generated
vendored
Normal 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 isn’t 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 isn’t 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 it’s followed by another `li`, the last because it’s
|
||||
* 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 isn’t 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 isn’t 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**: It’s 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 {}
|
Loading…
Add table
Add a link
Reference in a new issue