🎉 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

4
node_modules/mdast-util-to-hast/complex-types.d.ts generated vendored Normal file
View file

@ -0,0 +1,4 @@
// To do: next major: remove this file.
export type {Raw} from './index.js'
/// <reference types="./index.js" />

48
node_modules/mdast-util-to-hast/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,48 @@
import type {Literal} from 'hast'
import type {State} from './lib/state.js'
// Expose types.
export type {State, Handler, Handlers, Options} from './lib/state.js'
// To do: next major: remove.
/**
* Deprecated: use `State`.
*/
export type H = State
// Expose JS API.
export {handlers as defaultHandlers} from './lib/handlers/index.js'
// To do: next major: remove.
export {one, all} from './lib/state.js'
export {toHast} from './lib/index.js'
// Expose node type.
/**
* Raw string of HTML embedded into HTML AST.
*/
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface Raw extends Literal {
/**
* Node type.
*/
type: 'raw'
}
// Register nodes in content.
declare module 'hast' {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface RootContentMap {
/**
* Raw string of HTML embedded into HTML AST.
*/
raw: Raw
}
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
interface ElementContentMap {
/**
* Raw string of HTML embedded into HTML AST.
*/
raw: Raw
}
}

5
node_modules/mdast-util-to-hast/index.js generated vendored Normal file
View file

@ -0,0 +1,5 @@
// Note: types exposed from `index.d.ts`.
export {handlers as defaultHandlers} from './lib/handlers/index.js'
// To do: next major: remove.
export {one, all} from './lib/state.js'
export {toHast} from './lib/index.js'

12
node_modules/mdast-util-to-hast/lib/footer.d.ts generated vendored Normal file
View file

@ -0,0 +1,12 @@
/**
* Generate a hast footer for called footnote definitions.
*
* @param {State} state
* Info passed around.
* @returns {Element | undefined}
* `section` element or `undefined`.
*/
export function footer(state: State): Element | undefined
export type Element = import('hast').Element
export type ElementContent = import('hast').ElementContent
export type State = import('./state.js').State

128
node_modules/mdast-util-to-hast/lib/footer.js generated vendored Normal file
View file

@ -0,0 +1,128 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').ElementContent} ElementContent
*
* @typedef {import('./state.js').State} State
*/
import {normalizeUri} from 'micromark-util-sanitize-uri'
/**
* Generate a hast footer for called footnote definitions.
*
* @param {State} state
* Info passed around.
* @returns {Element | undefined}
* `section` element or `undefined`.
*/
export function footer(state) {
/** @type {Array<ElementContent>} */
const listItems = []
let index = -1
while (++index < state.footnoteOrder.length) {
const def = state.footnoteById[state.footnoteOrder[index]]
if (!def) {
continue
}
const content = state.all(def)
const id = String(def.identifier).toUpperCase()
const safeId = normalizeUri(id.toLowerCase())
let referenceIndex = 0
/** @type {Array<ElementContent>} */
const backReferences = []
while (++referenceIndex <= state.footnoteCounts[id]) {
/** @type {Element} */
const backReference = {
type: 'element',
tagName: 'a',
properties: {
href:
'#' +
state.clobberPrefix +
'fnref-' +
safeId +
(referenceIndex > 1 ? '-' + referenceIndex : ''),
dataFootnoteBackref: true,
className: ['data-footnote-backref'],
ariaLabel: state.footnoteBackLabel
},
children: [{type: 'text', value: '↩'}]
}
if (referenceIndex > 1) {
backReference.children.push({
type: 'element',
tagName: 'sup',
children: [{type: 'text', value: String(referenceIndex)}]
})
}
if (backReferences.length > 0) {
backReferences.push({type: 'text', value: ' '})
}
backReferences.push(backReference)
}
const tail = content[content.length - 1]
if (tail && tail.type === 'element' && tail.tagName === 'p') {
const tailTail = tail.children[tail.children.length - 1]
if (tailTail && tailTail.type === 'text') {
tailTail.value += ' '
} else {
tail.children.push({type: 'text', value: ' '})
}
tail.children.push(...backReferences)
} else {
content.push(...backReferences)
}
/** @type {Element} */
const listItem = {
type: 'element',
tagName: 'li',
properties: {id: state.clobberPrefix + 'fn-' + safeId},
children: state.wrap(content, true)
}
state.patch(def, listItem)
listItems.push(listItem)
}
if (listItems.length === 0) {
return
}
return {
type: 'element',
tagName: 'section',
properties: {dataFootnotes: true, className: ['footnotes']},
children: [
{
type: 'element',
tagName: state.footnoteLabelTagName,
properties: {
// To do: use structured clone.
...JSON.parse(JSON.stringify(state.footnoteLabelProperties)),
id: 'footnote-label'
},
children: [{type: 'text', value: state.footnoteLabel}]
},
{type: 'text', value: '\n'},
{
type: 'element',
tagName: 'ol',
properties: {},
children: state.wrap(listItems, true)
},
{type: 'text', value: '\n'}
]
}
}

View file

@ -0,0 +1,19 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Blockquote} Blockquote
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `blockquote` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Blockquote} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function blockquote(state: State, node: Blockquote): Element
export type Element = import('hast').Element
export type Blockquote = import('mdast').Blockquote
export type State = import('../state.js').State

View file

@ -0,0 +1,27 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Blockquote} Blockquote
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `blockquote` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Blockquote} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function blockquote(state, node) {
/** @type {Element} */
const result = {
type: 'element',
tagName: 'blockquote',
properties: {},
children: state.wrap(state.all(node), true)
}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,21 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Text} Text
* @typedef {import('mdast').Break} Break
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `break` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Break} node
* mdast node.
* @returns {Array<Element | Text>}
* hast element content.
*/
export function hardBreak(state: State, node: Break): Array<Element | Text>
export type Element = import('hast').Element
export type Text = import('hast').Text
export type Break = import('mdast').Break
export type State = import('../state.js').State

23
node_modules/mdast-util-to-hast/lib/handlers/break.js generated vendored Normal file
View file

@ -0,0 +1,23 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Text} Text
* @typedef {import('mdast').Break} Break
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `break` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Break} node
* mdast node.
* @returns {Array<Element | Text>}
* hast element content.
*/
export function hardBreak(state, node) {
/** @type {Element} */
const result = {type: 'element', tagName: 'br', properties: {}, children: []}
state.patch(node, result)
return [state.applyData(node, result), {type: 'text', value: '\n'}]
}

22
node_modules/mdast-util-to-hast/lib/handlers/code.d.ts generated vendored Normal file
View file

@ -0,0 +1,22 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Properties} Properties
* @typedef {import('mdast').Code} Code
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `code` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Code} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function code(state: State, node: Code): Element
export type Element = import('hast').Element
export type Properties = import('hast').Properties
export type Code = import('mdast').Code
export type State = import('../state.js').State

51
node_modules/mdast-util-to-hast/lib/handlers/code.js generated vendored Normal file
View file

@ -0,0 +1,51 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Properties} Properties
* @typedef {import('mdast').Code} Code
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `code` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Code} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function code(state, node) {
const value = node.value ? node.value + '\n' : ''
// To do: next major, use `node.lang` w/o regex, the splittings been going
// on for years in remark now.
const lang = node.lang ? node.lang.match(/^[^ \t]+(?=[ \t]|$)/) : null
/** @type {Properties} */
const properties = {}
if (lang) {
properties.className = ['language-' + lang]
}
// Create `<code>`.
/** @type {Element} */
let result = {
type: 'element',
tagName: 'code',
properties,
children: [{type: 'text', value}]
}
if (node.meta) {
result.data = {meta: node.meta}
}
state.patch(node, result)
result = state.applyData(node, result)
// Create `<pre>`.
result = {type: 'element', tagName: 'pre', properties: {}, children: [result]}
state.patch(node, result)
return result
}

View file

@ -0,0 +1,20 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Delete} Delete
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `delete` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Delete} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function strikethrough(state: State, node: Delete): Element
export type Element = import('hast').Element
export type Delete = import('mdast').Delete
export type State = import('../state.js').State

28
node_modules/mdast-util-to-hast/lib/handlers/delete.js generated vendored Normal file
View file

@ -0,0 +1,28 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Delete} Delete
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `delete` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Delete} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function strikethrough(state, node) {
/** @type {Element} */
const result = {
type: 'element',
tagName: 'del',
properties: {},
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,19 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Emphasis} Emphasis
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `emphasis` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Emphasis} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function emphasis(state: State, node: Emphasis): Element
export type Element = import('hast').Element
export type Emphasis = import('mdast').Emphasis
export type State = import('../state.js').State

View file

@ -0,0 +1,27 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Emphasis} Emphasis
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `emphasis` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Emphasis} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function emphasis(state, node) {
/** @type {Element} */
const result = {
type: 'element',
tagName: 'em',
properties: {},
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,17 @@
/**
* Turn an mdast `footnoteReference` node into hast.
*
* @param {State} state
* Info passed around.
* @param {FootnoteReference} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function footnoteReference(
state: State,
node: FootnoteReference
): Element
export type FootnoteReference = import('mdast').FootnoteReference
export type Element = import('hast').Element
export type State = import('../state.js').State

View file

@ -0,0 +1,64 @@
/**
* @typedef {import('mdast').FootnoteReference} FootnoteReference
* @typedef {import('hast').Element} Element
* @typedef {import('../state.js').State} State
*/
import {normalizeUri} from 'micromark-util-sanitize-uri'
/**
* Turn an mdast `footnoteReference` node into hast.
*
* @param {State} state
* Info passed around.
* @param {FootnoteReference} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function footnoteReference(state, node) {
const id = String(node.identifier).toUpperCase()
const safeId = normalizeUri(id.toLowerCase())
const index = state.footnoteOrder.indexOf(id)
/** @type {number} */
let counter
if (index === -1) {
state.footnoteOrder.push(id)
state.footnoteCounts[id] = 1
counter = state.footnoteOrder.length
} else {
state.footnoteCounts[id]++
counter = index + 1
}
const reuseCounter = state.footnoteCounts[id]
/** @type {Element} */
const link = {
type: 'element',
tagName: 'a',
properties: {
href: '#' + state.clobberPrefix + 'fn-' + safeId,
id:
state.clobberPrefix +
'fnref-' +
safeId +
(reuseCounter > 1 ? '-' + reuseCounter : ''),
dataFootnoteRef: true,
ariaDescribedBy: ['footnote-label']
},
children: [{type: 'text', value: String(counter)}]
}
state.patch(node, link)
/** @type {Element} */
const sup = {
type: 'element',
tagName: 'sup',
properties: {},
children: [link]
}
state.patch(node, sup)
return state.applyData(node, sup)
}

View file

@ -0,0 +1,14 @@
/**
* Turn an mdast `footnote` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Footnote} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function footnote(state: State, node: Footnote): Element
export type Element = import('hast').Element
export type Footnote = import('mdast').Footnote
export type State = import('../state.js').State

View file

@ -0,0 +1,45 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Footnote} Footnote
* @typedef {import('../state.js').State} State
*/
import {footnoteReference} from './footnote-reference.js'
// To do: when both:
// * <https://github.com/micromark/micromark-extension-footnote>
// * <https://github.com/syntax-tree/mdast-util-footnote>
// …are archived, remove this (also from mdast).
// These inline notes are not used in GFM.
/**
* Turn an mdast `footnote` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Footnote} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function footnote(state, node) {
const footnoteById = state.footnoteById
let no = 1
while (no in footnoteById) no++
const identifier = String(no)
footnoteById[identifier] = {
type: 'footnoteDefinition',
identifier,
children: [{type: 'paragraph', children: node.children}],
position: node.position
}
return footnoteReference(state, {
type: 'footnoteReference',
identifier,
position: node.position
})
}

View file

@ -0,0 +1,19 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Heading} Heading
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `heading` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Heading} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function heading(state: State, node: Heading): Element
export type Element = import('hast').Element
export type Heading = import('mdast').Heading
export type State = import('../state.js').State

View file

@ -0,0 +1,27 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Heading} Heading
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `heading` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Heading} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function heading(state, node) {
/** @type {Element} */
const result = {
type: 'element',
tagName: 'h' + node.depth,
properties: {},
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
}

22
node_modules/mdast-util-to-hast/lib/handlers/html.d.ts generated vendored Normal file
View file

@ -0,0 +1,22 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').HTML} Html
* @typedef {import('../state.js').State} State
* @typedef {import('../../index.js').Raw} Raw
*/
/**
* Turn an mdast `html` node into hast (`raw` node in dangerous mode, otherwise
* nothing).
*
* @param {State} state
* Info passed around.
* @param {Html} node
* mdast node.
* @returns {Raw | Element | null}
* hast node.
*/
export function html(state: State, node: Html): Raw | Element | null
export type Element = import('hast').Element
export type Html = import('mdast').HTML
export type State = import('../state.js').State
export type Raw = import('../../index.js').Raw

29
node_modules/mdast-util-to-hast/lib/handlers/html.js generated vendored Normal file
View file

@ -0,0 +1,29 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').HTML} Html
* @typedef {import('../state.js').State} State
* @typedef {import('../../index.js').Raw} Raw
*/
/**
* Turn an mdast `html` node into hast (`raw` node in dangerous mode, otherwise
* nothing).
*
* @param {State} state
* Info passed around.
* @param {Html} node
* mdast node.
* @returns {Raw | Element | null}
* hast node.
*/
export function html(state, node) {
if (state.dangerous) {
/** @type {Raw} */
const result = {type: 'raw', value: node.value}
state.patch(node, result)
return state.applyData(node, result)
}
// To do: next major: return `undefined`.
return null
}

View file

@ -0,0 +1,19 @@
/**
* Turn an mdast `imageReference` node into hast.
*
* @param {State} state
* Info passed around.
* @param {ImageReference} node
* mdast node.
* @returns {ElementContent | Array<ElementContent>}
* hast node.
*/
export function imageReference(
state: State,
node: ImageReference
): ElementContent | Array<ElementContent>
export type ElementContent = import('hast').ElementContent
export type Element = import('hast').Element
export type Properties = import('hast').Properties
export type ImageReference = import('mdast').ImageReference
export type State = import('../state.js').State

View file

@ -0,0 +1,40 @@
/**
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Properties} Properties
* @typedef {import('mdast').ImageReference} ImageReference
* @typedef {import('../state.js').State} State
*/
import {normalizeUri} from 'micromark-util-sanitize-uri'
import {revert} from '../revert.js'
/**
* Turn an mdast `imageReference` node into hast.
*
* @param {State} state
* Info passed around.
* @param {ImageReference} node
* mdast node.
* @returns {ElementContent | Array<ElementContent>}
* hast node.
*/
export function imageReference(state, node) {
const def = state.definition(node.identifier)
if (!def) {
return revert(state, node)
}
/** @type {Properties} */
const properties = {src: normalizeUri(def.url || ''), alt: node.alt}
if (def.title !== null && def.title !== undefined) {
properties.title = def.title
}
/** @type {Element} */
const result = {type: 'element', tagName: 'img', properties, children: []}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,15 @@
/**
* Turn an mdast `image` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Image} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function image(state: State, node: Image): Element
export type Element = import('hast').Element
export type Properties = import('hast').Properties
export type Image = import('mdast').Image
export type State = import('../state.js').State

36
node_modules/mdast-util-to-hast/lib/handlers/image.js generated vendored Normal file
View file

@ -0,0 +1,36 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Properties} Properties
* @typedef {import('mdast').Image} Image
* @typedef {import('../state.js').State} State
*/
import {normalizeUri} from 'micromark-util-sanitize-uri'
/**
* Turn an mdast `image` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Image} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function image(state, node) {
/** @type {Properties} */
const properties = {src: normalizeUri(node.url)}
if (node.alt !== null && node.alt !== undefined) {
properties.alt = node.alt
}
if (node.title !== null && node.title !== undefined) {
properties.title = node.title
}
/** @type {Element} */
const result = {type: 'element', tagName: 'img', properties, children: []}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,56 @@
export namespace handlers {
export {blockquote}
export {hardBreak as break}
export {code}
export {strikethrough as delete}
export {emphasis}
export {footnoteReference}
export {footnote}
export {heading}
export {html}
export {imageReference}
export {image}
export {inlineCode}
export {linkReference}
export {link}
export {listItem}
export {list}
export {paragraph}
export {root}
export {strong}
export {table}
export {tableCell}
export {tableRow}
export {text}
export {thematicBreak}
export {ignore as toml}
export {ignore as yaml}
export {ignore as definition}
export {ignore as footnoteDefinition}
}
import {blockquote} from './blockquote.js'
import {hardBreak} from './break.js'
import {code} from './code.js'
import {strikethrough} from './delete.js'
import {emphasis} from './emphasis.js'
import {footnoteReference} from './footnote-reference.js'
import {footnote} from './footnote.js'
import {heading} from './heading.js'
import {html} from './html.js'
import {imageReference} from './image-reference.js'
import {image} from './image.js'
import {inlineCode} from './inline-code.js'
import {linkReference} from './link-reference.js'
import {link} from './link.js'
import {listItem} from './list-item.js'
import {list} from './list.js'
import {paragraph} from './paragraph.js'
import {root} from './root.js'
import {strong} from './strong.js'
import {table} from './table.js'
import {tableCell} from './table-cell.js'
import {tableRow} from './table-row.js'
import {text} from './text.js'
import {thematicBreak} from './thematic-break.js'
declare function ignore(): null
export {}

64
node_modules/mdast-util-to-hast/lib/handlers/index.js generated vendored Normal file
View file

@ -0,0 +1,64 @@
import {blockquote} from './blockquote.js'
import {hardBreak} from './break.js'
import {code} from './code.js'
import {strikethrough} from './delete.js'
import {emphasis} from './emphasis.js'
import {footnoteReference} from './footnote-reference.js'
import {footnote} from './footnote.js'
import {heading} from './heading.js'
import {html} from './html.js'
import {imageReference} from './image-reference.js'
import {image} from './image.js'
import {inlineCode} from './inline-code.js'
import {linkReference} from './link-reference.js'
import {link} from './link.js'
import {listItem} from './list-item.js'
import {list} from './list.js'
import {paragraph} from './paragraph.js'
import {root} from './root.js'
import {strong} from './strong.js'
import {table} from './table.js'
import {tableRow} from './table-row.js'
import {tableCell} from './table-cell.js'
import {text} from './text.js'
import {thematicBreak} from './thematic-break.js'
/**
* Default handlers for nodes.
*/
export const handlers = {
blockquote,
break: hardBreak,
code,
delete: strikethrough,
emphasis,
footnoteReference,
footnote,
heading,
html,
imageReference,
image,
inlineCode,
linkReference,
link,
listItem,
list,
paragraph,
root,
strong,
table,
tableCell,
tableRow,
text,
thematicBreak,
toml: ignore,
yaml: ignore,
definition: ignore,
footnoteDefinition: ignore
}
// Return nothing for nodes that are ignored.
function ignore() {
// To do: next major: return `undefined`.
return null
}

View file

@ -0,0 +1,21 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Text} Text
* @typedef {import('mdast').InlineCode} InlineCode
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `inlineCode` node into hast.
*
* @param {State} state
* Info passed around.
* @param {InlineCode} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function inlineCode(state: State, node: InlineCode): Element
export type Element = import('hast').Element
export type Text = import('hast').Text
export type InlineCode = import('mdast').InlineCode
export type State = import('../state.js').State

View file

@ -0,0 +1,32 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Text} Text
* @typedef {import('mdast').InlineCode} InlineCode
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `inlineCode` node into hast.
*
* @param {State} state
* Info passed around.
* @param {InlineCode} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function inlineCode(state, node) {
/** @type {Text} */
const text = {type: 'text', value: node.value.replace(/\r?\n|\r/g, ' ')}
state.patch(node, text)
/** @type {Element} */
const result = {
type: 'element',
tagName: 'code',
properties: {},
children: [text]
}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,19 @@
/**
* Turn an mdast `linkReference` node into hast.
*
* @param {State} state
* Info passed around.
* @param {LinkReference} node
* mdast node.
* @returns {ElementContent | Array<ElementContent>}
* hast node.
*/
export function linkReference(
state: State,
node: LinkReference
): ElementContent | Array<ElementContent>
export type Element = import('hast').Element
export type ElementContent = import('hast').ElementContent
export type Properties = import('hast').Properties
export type LinkReference = import('mdast').LinkReference
export type State = import('../state.js').State

View file

@ -0,0 +1,45 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('hast').Properties} Properties
* @typedef {import('mdast').LinkReference} LinkReference
* @typedef {import('../state.js').State} State
*/
import {normalizeUri} from 'micromark-util-sanitize-uri'
import {revert} from '../revert.js'
/**
* Turn an mdast `linkReference` node into hast.
*
* @param {State} state
* Info passed around.
* @param {LinkReference} node
* mdast node.
* @returns {ElementContent | Array<ElementContent>}
* hast node.
*/
export function linkReference(state, node) {
const def = state.definition(node.identifier)
if (!def) {
return revert(state, node)
}
/** @type {Properties} */
const properties = {href: normalizeUri(def.url || '')}
if (def.title !== null && def.title !== undefined) {
properties.title = def.title
}
/** @type {Element} */
const result = {
type: 'element',
tagName: 'a',
properties,
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
}

15
node_modules/mdast-util-to-hast/lib/handlers/link.d.ts generated vendored Normal file
View file

@ -0,0 +1,15 @@
/**
* Turn an mdast `link` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Link} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function link(state: State, node: Link): Element
export type Element = import('hast').Element
export type Properties = import('hast').Properties
export type Link = import('mdast').Link
export type State = import('../state.js').State

37
node_modules/mdast-util-to-hast/lib/handlers/link.js generated vendored Normal file
View file

@ -0,0 +1,37 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Properties} Properties
* @typedef {import('mdast').Link} Link
* @typedef {import('../state.js').State} State
*/
import {normalizeUri} from 'micromark-util-sanitize-uri'
/**
* Turn an mdast `link` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Link} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function link(state, node) {
/** @type {Properties} */
const properties = {href: normalizeUri(node.url)}
if (node.title !== null && node.title !== undefined) {
properties.title = node.title
}
/** @type {Element} */
const result = {
type: 'element',
tagName: 'a',
properties,
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,41 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('hast').Properties} Properties
* @typedef {import('mdast').Content} Content
* @typedef {import('mdast').ListItem} ListItem
* @typedef {import('mdast').Parent} Parent
* @typedef {import('mdast').Root} Root
* @typedef {import('../state.js').State} State
*/
/**
* @typedef {Root | Content} Nodes
* @typedef {Extract<Nodes, Parent>} Parents
*/
/**
* Turn an mdast `listItem` node into hast.
*
* @param {State} state
* Info passed around.
* @param {ListItem} node
* mdast node.
* @param {Parents | null | undefined} parent
* Parent of `node`.
* @returns {Element}
* hast node.
*/
export function listItem(
state: State,
node: ListItem,
parent: Parents | null | undefined
): Element
export type Element = import('hast').Element
export type ElementContent = import('hast').ElementContent
export type Properties = import('hast').Properties
export type Content = import('mdast').Content
export type ListItem = import('mdast').ListItem
export type Parent = import('mdast').Parent
export type Root = import('mdast').Root
export type State = import('../state.js').State
export type Nodes = Root | Content
export type Parents = Extract<Nodes, Parent>

View file

@ -0,0 +1,129 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('hast').Properties} Properties
* @typedef {import('mdast').Content} Content
* @typedef {import('mdast').ListItem} ListItem
* @typedef {import('mdast').Parent} Parent
* @typedef {import('mdast').Root} Root
* @typedef {import('../state.js').State} State
*/
/**
* @typedef {Root | Content} Nodes
* @typedef {Extract<Nodes, Parent>} Parents
*/
/**
* Turn an mdast `listItem` node into hast.
*
* @param {State} state
* Info passed around.
* @param {ListItem} node
* mdast node.
* @param {Parents | null | undefined} parent
* Parent of `node`.
* @returns {Element}
* hast node.
*/
export function listItem(state, node, parent) {
const results = state.all(node)
const loose = parent ? listLoose(parent) : listItemLoose(node)
/** @type {Properties} */
const properties = {}
/** @type {Array<ElementContent>} */
const children = []
if (typeof node.checked === 'boolean') {
const head = results[0]
/** @type {Element} */
let paragraph
if (head && head.type === 'element' && head.tagName === 'p') {
paragraph = head
} else {
paragraph = {type: 'element', tagName: 'p', properties: {}, children: []}
results.unshift(paragraph)
}
if (paragraph.children.length > 0) {
paragraph.children.unshift({type: 'text', value: ' '})
}
paragraph.children.unshift({
type: 'element',
tagName: 'input',
properties: {type: 'checkbox', checked: node.checked, disabled: true},
children: []
})
// According to github-markdown-css, this class hides bullet.
// See: <https://github.com/sindresorhus/github-markdown-css>.
properties.className = ['task-list-item']
}
let index = -1
while (++index < results.length) {
const child = results[index]
// Add eols before nodes, except if this is a loose, first paragraph.
if (
loose ||
index !== 0 ||
child.type !== 'element' ||
child.tagName !== 'p'
) {
children.push({type: 'text', value: '\n'})
}
if (child.type === 'element' && child.tagName === 'p' && !loose) {
children.push(...child.children)
} else {
children.push(child)
}
}
const tail = results[results.length - 1]
// Add a final eol.
if (tail && (loose || tail.type !== 'element' || tail.tagName !== 'p')) {
children.push({type: 'text', value: '\n'})
}
/** @type {Element} */
const result = {type: 'element', tagName: 'li', properties, children}
state.patch(node, result)
return state.applyData(node, result)
}
/**
* @param {Parents} node
* @return {Boolean}
*/
function listLoose(node) {
let loose = false
if (node.type === 'list') {
loose = node.spread || false
const children = node.children
let index = -1
while (!loose && ++index < children.length) {
loose = listItemLoose(children[index])
}
}
return loose
}
/**
* @param {ListItem} node
* @return {Boolean}
*/
function listItemLoose(node) {
const spread = node.spread
return spread === undefined || spread === null
? node.children.length > 1
: spread
}

21
node_modules/mdast-util-to-hast/lib/handlers/list.d.ts generated vendored Normal file
View file

@ -0,0 +1,21 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Properties} Properties
* @typedef {import('mdast').List} List
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `list` node into hast.
*
* @param {State} state
* Info passed around.
* @param {List} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function list(state: State, node: List): Element
export type Element = import('hast').Element
export type Properties = import('hast').Properties
export type List = import('mdast').List
export type State = import('../state.js').State

53
node_modules/mdast-util-to-hast/lib/handlers/list.js generated vendored Normal file
View file

@ -0,0 +1,53 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Properties} Properties
* @typedef {import('mdast').List} List
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `list` node into hast.
*
* @param {State} state
* Info passed around.
* @param {List} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function list(state, node) {
/** @type {Properties} */
const properties = {}
const results = state.all(node)
let index = -1
if (typeof node.start === 'number' && node.start !== 1) {
properties.start = node.start
}
// Like GitHub, add a class for custom styling.
while (++index < results.length) {
const child = results[index]
if (
child.type === 'element' &&
child.tagName === 'li' &&
child.properties &&
Array.isArray(child.properties.className) &&
child.properties.className.includes('task-list-item')
) {
properties.className = ['contains-task-list']
break
}
}
/** @type {Element} */
const result = {
type: 'element',
tagName: node.ordered ? 'ol' : 'ul',
properties,
children: state.wrap(results, true)
}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,19 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Paragraph} Paragraph
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `paragraph` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Paragraph} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function paragraph(state: State, node: Paragraph): Element
export type Element = import('hast').Element
export type Paragraph = import('mdast').Paragraph
export type State = import('../state.js').State

View file

@ -0,0 +1,27 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Paragraph} Paragraph
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `paragraph` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Paragraph} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function paragraph(state, node) {
/** @type {Element} */
const result = {
type: 'element',
tagName: 'p',
properties: {},
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
}

21
node_modules/mdast-util-to-hast/lib/handlers/root.d.ts generated vendored Normal file
View file

@ -0,0 +1,21 @@
/**
* @typedef {import('hast').Root} HastRoot
* @typedef {import('hast').Element} HastElement
* @typedef {import('mdast').Root} MdastRoot
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `root` node into hast.
*
* @param {State} state
* Info passed around.
* @param {MdastRoot} node
* mdast node.
* @returns {HastRoot | HastElement}
* hast node.
*/
export function root(state: State, node: MdastRoot): HastRoot | HastElement
export type HastRoot = import('hast').Root
export type HastElement = import('hast').Element
export type MdastRoot = import('mdast').Root
export type State = import('../state.js').State

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

@ -0,0 +1,23 @@
/**
* @typedef {import('hast').Root} HastRoot
* @typedef {import('hast').Element} HastElement
* @typedef {import('mdast').Root} MdastRoot
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `root` node into hast.
*
* @param {State} state
* Info passed around.
* @param {MdastRoot} node
* mdast node.
* @returns {HastRoot | HastElement}
* hast node.
*/
export function root(state, node) {
/** @type {HastRoot} */
const result = {type: 'root', children: state.wrap(state.all(node))}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,19 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Strong} Strong
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `strong` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Strong} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function strong(state: State, node: Strong): Element
export type Element = import('hast').Element
export type Strong = import('mdast').Strong
export type State = import('../state.js').State

27
node_modules/mdast-util-to-hast/lib/handlers/strong.js generated vendored Normal file
View file

@ -0,0 +1,27 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Strong} Strong
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `strong` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Strong} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function strong(state, node) {
/** @type {Element} */
const result = {
type: 'element',
tagName: 'strong',
properties: {},
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,19 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').TableCell} TableCell
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `tableCell` node into hast.
*
* @param {State} state
* Info passed around.
* @param {TableCell} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function tableCell(state: State, node: TableCell): Element
export type Element = import('hast').Element
export type TableCell = import('mdast').TableCell
export type State = import('../state.js').State

View file

@ -0,0 +1,29 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').TableCell} TableCell
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `tableCell` node into hast.
*
* @param {State} state
* Info passed around.
* @param {TableCell} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function tableCell(state, node) {
// Note: this function is normally not called: see `table-row` for how rows
// and their cells are compiled.
/** @type {Element} */
const result = {
type: 'element',
tagName: 'td', // Assume body cell.
properties: {},
children: state.all(node)
}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,41 @@
/**
* @typedef {import('hast').Properties} Properties
* @typedef {import('hast').Element} Element
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('mdast').Content} Content
* @typedef {import('mdast').Parent} Parent
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').TableRow} TableRow
* @typedef {import('../state.js').State} State
*/
/**
* @typedef {Root | Content} Nodes
* @typedef {Extract<Nodes, Parent>} Parents
*/
/**
* Turn an mdast `tableRow` node into hast.
*
* @param {State} state
* Info passed around.
* @param {TableRow} node
* mdast node.
* @param {Parents | null | undefined} parent
* Parent of `node`.
* @returns {Element}
* hast node.
*/
export function tableRow(
state: State,
node: TableRow,
parent: Parents | null | undefined
): Element
export type Properties = import('hast').Properties
export type Element = import('hast').Element
export type ElementContent = import('hast').ElementContent
export type Content = import('mdast').Content
export type Parent = import('mdast').Parent
export type Root = import('mdast').Root
export type TableRow = import('mdast').TableRow
export type State = import('../state.js').State
export type Nodes = Root | Content
export type Parents = Extract<Nodes, Parent>

View file

@ -0,0 +1,72 @@
/**
* @typedef {import('hast').Properties} Properties
* @typedef {import('hast').Element} Element
* @typedef {import('hast').ElementContent} ElementContent
* @typedef {import('mdast').Content} Content
* @typedef {import('mdast').Parent} Parent
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').TableRow} TableRow
* @typedef {import('../state.js').State} State
*/
/**
* @typedef {Root | Content} Nodes
* @typedef {Extract<Nodes, Parent>} Parents
*/
/**
* Turn an mdast `tableRow` node into hast.
*
* @param {State} state
* Info passed around.
* @param {TableRow} node
* mdast node.
* @param {Parents | null | undefined} parent
* Parent of `node`.
* @returns {Element}
* hast node.
*/
export function tableRow(state, node, parent) {
const siblings = parent ? parent.children : undefined
// Generate a body row when without parent.
const rowIndex = siblings ? siblings.indexOf(node) : 1
const tagName = rowIndex === 0 ? 'th' : 'td'
const align = parent && parent.type === 'table' ? parent.align : undefined
const length = align ? align.length : node.children.length
let cellIndex = -1
/** @type {Array<ElementContent>} */
const cells = []
while (++cellIndex < length) {
// Note: can also be undefined.
const cell = node.children[cellIndex]
/** @type {Properties} */
const properties = {}
const alignValue = align ? align[cellIndex] : undefined
if (alignValue) {
properties.align = alignValue
}
/** @type {Element} */
let result = {type: 'element', tagName, properties, children: []}
if (cell) {
result.children = state.all(cell)
state.patch(cell, result)
result = state.applyData(node, result)
}
cells.push(result)
}
/** @type {Element} */
const result = {
type: 'element',
tagName: 'tr',
properties: {},
children: state.wrap(cells, true)
}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,14 @@
/**
* Turn an mdast `table` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Table} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function table(state: State, node: Table): Element
export type Element = import('hast').Element
export type Table = import('mdast').Table
export type State = import('../state.js').State

61
node_modules/mdast-util-to-hast/lib/handlers/table.js generated vendored Normal file
View file

@ -0,0 +1,61 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').Table} Table
* @typedef {import('../state.js').State} State
*/
import {pointStart, pointEnd} from 'unist-util-position'
/**
* Turn an mdast `table` node into hast.
*
* @param {State} state
* Info passed around.
* @param {Table} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function table(state, node) {
const rows = state.all(node)
const firstRow = rows.shift()
/** @type {Array<Element>} */
const tableContent = []
if (firstRow) {
/** @type {Element} */
const head = {
type: 'element',
tagName: 'thead',
properties: {},
children: state.wrap([firstRow], true)
}
state.patch(node.children[0], head)
tableContent.push(head)
}
if (rows.length > 0) {
/** @type {Element} */
const body = {
type: 'element',
tagName: 'tbody',
properties: {},
children: state.wrap(rows, true)
}
const start = pointStart(node.children[1])
const end = pointEnd(node.children[node.children.length - 1])
if (start.line && end.line) body.position = {start, end}
tableContent.push(body)
}
/** @type {Element} */
const result = {
type: 'element',
tagName: 'table',
properties: {},
children: state.wrap(tableContent, true)
}
state.patch(node, result)
return state.applyData(node, result)
}

15
node_modules/mdast-util-to-hast/lib/handlers/text.d.ts generated vendored Normal file
View file

@ -0,0 +1,15 @@
/**
* Turn an mdast `text` node into hast.
*
* @param {State} state
* Info passed around.
* @param {MdastText} node
* mdast node.
* @returns {HastText | HastElement}
* hast node.
*/
export function text(state: State, node: MdastText): HastText | HastElement
export type HastElement = import('hast').Element
export type HastText = import('hast').Text
export type MdastText = import('mdast').Text
export type State = import('../state.js').State

25
node_modules/mdast-util-to-hast/lib/handlers/text.js generated vendored Normal file
View file

@ -0,0 +1,25 @@
/**
* @typedef {import('hast').Element} HastElement
* @typedef {import('hast').Text} HastText
* @typedef {import('mdast').Text} MdastText
* @typedef {import('../state.js').State} State
*/
import {trimLines} from 'trim-lines'
/**
* Turn an mdast `text` node into hast.
*
* @param {State} state
* Info passed around.
* @param {MdastText} node
* mdast node.
* @returns {HastText | HastElement}
* hast node.
*/
export function text(state, node) {
/** @type {HastText} */
const result = {type: 'text', value: trimLines(String(node.value))}
state.patch(node, result)
return state.applyData(node, result)
}

View file

@ -0,0 +1,19 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').ThematicBreak} ThematicBreak
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `thematicBreak` node into hast.
*
* @param {State} state
* Info passed around.
* @param {ThematicBreak} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function thematicBreak(state: State, node: ThematicBreak): Element
export type Element = import('hast').Element
export type ThematicBreak = import('mdast').ThematicBreak
export type State = import('../state.js').State

View file

@ -0,0 +1,27 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('mdast').ThematicBreak} ThematicBreak
* @typedef {import('../state.js').State} State
*/
/**
* Turn an mdast `thematicBreak` node into hast.
*
* @param {State} state
* Info passed around.
* @param {ThematicBreak} node
* mdast node.
* @returns {Element}
* hast node.
*/
export function thematicBreak(state, node) {
/** @type {Element} */
const result = {
type: 'element',
tagName: 'hr',
properties: {},
children: []
}
state.patch(node, result)
return state.applyData(node, result)
}

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

@ -0,0 +1,88 @@
/**
* Transform mdast to hast.
*
* ##### Notes
*
* ###### HTML
*
* Raw HTML is available in mdast as `html` nodes and can be embedded in hast
* as semistandard `raw` nodes.
* Most utilities ignore `raw` nodes but two notable ones dont:
*
* * `hast-util-to-html` also has an option `allowDangerousHtml` which will
* output the raw HTML.
* This is typically discouraged as noted by the option name but is useful
* if you completely trust authors
* * `hast-util-raw` can handle the raw embedded HTML strings by parsing them
* into standard hast nodes (`element`, `text`, etc).
* This is a heavy task as it needs a full HTML parser, but it is the only
* way to support untrusted content
*
* ###### Footnotes
*
* Many options supported here relate to footnotes.
* Footnotes are not specified by CommonMark, which we follow by default.
* They are supported by GitHub, so footnotes can be enabled in markdown with
* `mdast-util-gfm`.
*
* The options `footnoteBackLabel` and `footnoteLabel` define natural language
* that explains footnotes, which is hidden for sighted users but shown to
* assistive technology.
* When your page is not in English, you must define translated values.
*
* Back references use ARIA attributes, but the section label itself uses a
* heading that is hidden with an `sr-only` class.
* To show it to sighted users, define different attributes in
* `footnoteLabelProperties`.
*
* ###### Clobbering
*
* Footnotes introduces a problem, as it links footnote calls to footnote
* definitions on the page through `id` attributes generated from user content,
* which results in DOM clobbering.
*
* DOM clobbering is this:
*
* ```html
* <p id=x></p>
* <script>alert(x) // `x` now refers to the DOM `p#x` element</script>
* ```
*
* Elements by their ID are made available by browsers on the `window` object,
* which is a security risk.
* Using a prefix solves this problem.
*
* More information on how to handle clobbering and the prefix is explained in
* Example: headings (DOM clobbering) in `rehype-sanitize`.
*
* ###### Unknown nodes
*
* Unknown nodes are nodes with a type that isnt in `handlers` or `passThrough`.
* The default behavior for unknown nodes is:
*
* * when the node has a `value` (and doesnt have `data.hName`,
* `data.hProperties`, or `data.hChildren`, see later), create a hast `text`
* node
* * otherwise, create a `<div>` element (which could be changed with
* `data.hName`), with its children mapped from mdast to hast as well
*
* This behavior can be changed by passing an `unknownHandler`.
*
* @param {MdastNodes} tree
* mdast tree.
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {HastNodes | null | undefined}
* hast tree.
*/
export function toHast(
tree: MdastNodes,
options?: Options | null | undefined
): HastNodes | null | undefined
export type HastContent = import('hast').Content
export type HastRoot = import('hast').Root
export type MdastContent = import('mdast').Content
export type MdastRoot = import('mdast').Root
export type Options = import('./state.js').Options
export type HastNodes = HastRoot | HastContent
export type MdastNodes = MdastRoot | MdastContent

111
node_modules/mdast-util-to-hast/lib/index.js generated vendored Normal file
View file

@ -0,0 +1,111 @@
/**
* @typedef {import('hast').Content} HastContent
* @typedef {import('hast').Root} HastRoot
*
* @typedef {import('mdast').Content} MdastContent
* @typedef {import('mdast').Root} MdastRoot
*
* @typedef {import('./state.js').Options} Options
*/
/**
* @typedef {HastRoot | HastContent} HastNodes
* @typedef {MdastRoot | MdastContent} MdastNodes
*/
import {footer} from './footer.js'
import {createState} from './state.js'
/**
* Transform mdast to hast.
*
* ##### Notes
*
* ###### HTML
*
* Raw HTML is available in mdast as `html` nodes and can be embedded in hast
* as semistandard `raw` nodes.
* Most utilities ignore `raw` nodes but two notable ones dont:
*
* * `hast-util-to-html` also has an option `allowDangerousHtml` which will
* output the raw HTML.
* This is typically discouraged as noted by the option name but is useful
* if you completely trust authors
* * `hast-util-raw` can handle the raw embedded HTML strings by parsing them
* into standard hast nodes (`element`, `text`, etc).
* This is a heavy task as it needs a full HTML parser, but it is the only
* way to support untrusted content
*
* ###### Footnotes
*
* Many options supported here relate to footnotes.
* Footnotes are not specified by CommonMark, which we follow by default.
* They are supported by GitHub, so footnotes can be enabled in markdown with
* `mdast-util-gfm`.
*
* The options `footnoteBackLabel` and `footnoteLabel` define natural language
* that explains footnotes, which is hidden for sighted users but shown to
* assistive technology.
* When your page is not in English, you must define translated values.
*
* Back references use ARIA attributes, but the section label itself uses a
* heading that is hidden with an `sr-only` class.
* To show it to sighted users, define different attributes in
* `footnoteLabelProperties`.
*
* ###### Clobbering
*
* Footnotes introduces a problem, as it links footnote calls to footnote
* definitions on the page through `id` attributes generated from user content,
* which results in DOM clobbering.
*
* DOM clobbering is this:
*
* ```html
* <p id=x></p>
* <script>alert(x) // `x` now refers to the DOM `p#x` element</script>
* ```
*
* Elements by their ID are made available by browsers on the `window` object,
* which is a security risk.
* Using a prefix solves this problem.
*
* More information on how to handle clobbering and the prefix is explained in
* Example: headings (DOM clobbering) in `rehype-sanitize`.
*
* ###### Unknown nodes
*
* Unknown nodes are nodes with a type that isnt in `handlers` or `passThrough`.
* The default behavior for unknown nodes is:
*
* * when the node has a `value` (and doesnt have `data.hName`,
* `data.hProperties`, or `data.hChildren`, see later), create a hast `text`
* node
* * otherwise, create a `<div>` element (which could be changed with
* `data.hName`), with its children mapped from mdast to hast as well
*
* This behavior can be changed by passing an `unknownHandler`.
*
* @param {MdastNodes} tree
* mdast tree.
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {HastNodes | null | undefined}
* hast tree.
*/
// To do: next major: always return a single `root`.
export function toHast(tree, options) {
const state = createState(tree, options)
const node = state.one(tree, null)
const foot = footer(state)
if (foot) {
// @ts-expect-error If theres a footer, there were definitions, meaning block
// content.
// So assume `node` is a parent node.
node.children.push({type: 'text', value: '\n'}, foot)
}
// To do: next major: always return root?
return Array.isArray(node) ? {type: 'root', children: node} : node
}

34
node_modules/mdast-util-to-hast/lib/revert.d.ts generated vendored Normal file
View file

@ -0,0 +1,34 @@
/**
* @typedef {import('hast').ElementContent} ElementContent
*
* @typedef {import('mdast').Content} Content
* @typedef {import('mdast').Reference} Reference
* @typedef {import('mdast').Root} Root
*
* @typedef {import('./state.js').State} State
*/
/**
* @typedef {Root | Content} Nodes
* @typedef {Extract<Nodes, Reference>} References
*/
/**
* Return the content of a reference without definition as plain text.
*
* @param {State} state
* Info passed around.
* @param {References} node
* Reference node (image, link).
* @returns {ElementContent | Array<ElementContent>}
* hast content.
*/
export function revert(
state: State,
node: References
): ElementContent | Array<ElementContent>
export type ElementContent = import('hast').ElementContent
export type Content = import('mdast').Content
export type Reference = import('mdast').Reference
export type Root = import('mdast').Root
export type State = import('./state.js').State
export type Nodes = Root | Content
export type References = Extract<Nodes, Reference>

60
node_modules/mdast-util-to-hast/lib/revert.js generated vendored Normal file
View file

@ -0,0 +1,60 @@
/**
* @typedef {import('hast').ElementContent} ElementContent
*
* @typedef {import('mdast').Content} Content
* @typedef {import('mdast').Reference} Reference
* @typedef {import('mdast').Root} Root
*
* @typedef {import('./state.js').State} State
*/
/**
* @typedef {Root | Content} Nodes
* @typedef {Extract<Nodes, Reference>} References
*/
// To do: next major: always return array.
/**
* Return the content of a reference without definition as plain text.
*
* @param {State} state
* Info passed around.
* @param {References} node
* Reference node (image, link).
* @returns {ElementContent | Array<ElementContent>}
* hast content.
*/
export function revert(state, node) {
const subtype = node.referenceType
let suffix = ']'
if (subtype === 'collapsed') {
suffix += '[]'
} else if (subtype === 'full') {
suffix += '[' + (node.label || node.identifier) + ']'
}
if (node.type === 'imageReference') {
return {type: 'text', value: '![' + node.alt + suffix}
}
const contents = state.all(node)
const head = contents[0]
if (head && head.type === 'text') {
head.value = '[' + head.value
} else {
contents.unshift({type: 'text', value: '['})
}
const tail = contents[contents.length - 1]
if (tail && tail.type === 'text') {
tail.value += suffix
} else {
contents.push({type: 'text', value: suffix})
}
return contents
}

302
node_modules/mdast-util-to-hast/lib/state.d.ts generated vendored Normal file
View file

@ -0,0 +1,302 @@
/**
* Create `state` from an mdast tree.
*
* @param {MdastNodes} tree
* mdast node to transform.
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {State}
* `state` function.
*/
export function createState(
tree: MdastNodes,
options?: Options | null | undefined
): State
/**
* Transform an mdast node into a hast node.
*
* @param {State} state
* Info passed around.
* @param {MdastNodes} node
* mdast node.
* @param {MdastParents | null | undefined} [parent]
* Parent of `node`.
* @returns {HastElementContent | Array<HastElementContent> | null | undefined}
* Resulting hast node.
*/
export function one(
state: State,
node: MdastNodes,
parent?: MdastParents | null | undefined
): HastElementContent | Array<HastElementContent> | null | undefined
/**
* Transform the children of an mdast node into hast nodes.
*
* @param {State} state
* Info passed around.
* @param {MdastNodes} parent
* mdast node to compile
* @returns {Array<HastElementContent>}
* Resulting hast nodes.
*/
export function all(state: State, parent: MdastNodes): Array<HastElementContent>
/**
* Wrap `nodes` with line endings between each node.
*
* @template {HastContent} Type
* Node type.
* @param {Array<Type>} nodes
* List of nodes to wrap.
* @param {boolean | null | undefined} [loose=false]
* Whether to add line endings at start and end.
* @returns {Array<Type | HastText>}
* Wrapped nodes.
*/
export function wrap<Type extends import('hast').Content>(
nodes: Type[],
loose?: boolean | null | undefined
): (import('hast').Text | Type)[]
export type HastContent = import('hast').Content
export type HastElement = import('hast').Element
export type HastElementContent = import('hast').ElementContent
export type HastProperties = import('hast').Properties
export type HastRoot = import('hast').Root
export type HastText = import('hast').Text
export type MdastContent = import('mdast').Content
export type MdastDefinition = import('mdast').Definition
export type MdastFootnoteDefinition = import('mdast').FootnoteDefinition
export type MdastParent = import('mdast').Parent
export type MdastRoot = import('mdast').Root
export type HastNodes = HastRoot | HastContent
export type MdastNodes = MdastRoot | MdastContent
export type MdastParents = Extract<MdastNodes, MdastParent>
/**
* hast fields.
*/
export type EmbeddedHastFields = {
/**
* Generate a specific element with this tag name instead.
*/
hName?: string | null | undefined
/**
* Generate an element with these properties instead.
*/
hProperties?: HastProperties | null | undefined
/**
* Generate an element with this content instead.
*/
hChildren?: Array<HastElementContent> | null | undefined
}
/**
* mdast data with embedded hast fields.
*/
export type MdastData = Record<string, unknown> & EmbeddedHastFields
/**
* mdast node with embedded hast data.
*/
export type MdastNodeWithData = MdastNodes & {
data?: MdastData | null | undefined
}
/**
* Point-like value.
*/
export type PointLike = {
/**
* Line.
*/
line?: number | null | undefined
/**
* Column.
*/
column?: number | null | undefined
/**
* Offset.
*/
offset?: number | null | undefined
}
/**
* Position-like value.
*/
export type PositionLike = {
/**
* Point-like value.
*/
start?: PointLike | null | undefined
/**
* Point-like value.
*/
end?: PointLike | null | undefined
}
/**
* Handle a node.
*/
export type Handler = (
state: State,
node: any,
parent: MdastParents | null | undefined
) => HastElementContent | Array<HastElementContent> | null | undefined
/**
* Signature of `state` for when props are passed.
*/
export type HFunctionProps = (
node: MdastNodes | PositionLike | null | undefined,
tagName: string,
props: HastProperties,
children?: Array<HastElementContent> | null | undefined
) => HastElement
/**
* Signature of `state` for when no props are passed.
*/
export type HFunctionNoProps = (
node: MdastNodes | PositionLike | null | undefined,
tagName: string,
children?: Array<HastElementContent> | null | undefined
) => HastElement
/**
* Info on `state`.
*/
export type HFields = {
/**
* Whether HTML is allowed.
*/
dangerous: boolean
/**
* Prefix to use to prevent DOM clobbering.
*/
clobberPrefix: string
/**
* Label to use to introduce the footnote section.
*/
footnoteLabel: string
/**
* HTML used for the footnote label.
*/
footnoteLabelTagName: string
/**
* Properties on the HTML tag used for the footnote label.
*/
footnoteLabelProperties: HastProperties
/**
* Label to use from backreferences back to their footnote call.
*/
footnoteBackLabel: string
/**
* Definition cache.
*/
definition: (identifier: string) => MdastDefinition | null
/**
* Footnote definitions by their identifier.
*/
footnoteById: Record<string, MdastFootnoteDefinition>
/**
* Identifiers of order when footnote calls first appear in tree order.
*/
footnoteOrder: Array<string>
/**
* Counts for how often the same footnote was called.
*/
footnoteCounts: Record<string, number>
/**
* Applied handlers.
*/
handlers: Handlers
/**
* Handler for any none not in `passThrough` or otherwise handled.
*/
unknownHandler: Handler
/**
* Copy a nodes positional info.
*/
patch: (from: MdastNodes, node: HastNodes) => void
/**
* Honor the `data` of `from`, and generate an element instead of `node`.
*/
applyData: <Type extends HastNodes>(
from: MdastNodes,
to: Type
) => import('hast').Element | Type
/**
* Transform an mdast node to hast.
*/
one: (
node: MdastNodes,
parent: MdastParents | null | undefined
) => HastElementContent | Array<HastElementContent> | null | undefined
/**
* Transform the children of an mdast parent to hast.
*/
all: (node: MdastNodes) => Array<HastElementContent>
/**
* Wrap `nodes` with line endings between each node, adds initial/final line endings when `loose`.
*/
wrap: <Type_1 extends import('hast').Content>(
nodes: Type_1[],
loose?: boolean | null | undefined
) => (Type_1 | import('hast').Text)[]
/**
* Like `state` but lower-level and usable on non-elements.
* Deprecated: use `patch` and `applyData`.
*/
augment: (
left: MdastNodeWithData | PositionLike | null | undefined,
right: HastElementContent
) => HastElementContent
/**
* List of node types to pass through untouched (except for their children).
*/
passThrough: Array<string>
}
/**
* Configuration (optional).
*/
export type Options = {
/**
* Whether to persist raw HTML in markdown in the hast tree.
*/
allowDangerousHtml?: boolean | null | undefined
/**
* Prefix to use before the `id` attribute on footnotes to prevent it from
* *clobbering*.
*/
clobberPrefix?: string | null | undefined
/**
* Label to use from backreferences back to their footnote call (affects
* screen readers).
*/
footnoteBackLabel?: string | null | undefined
/**
* Label to use for the footnotes section (affects screen readers).
*/
footnoteLabel?: string | null | undefined
/**
* Properties to use on the footnote label (note that `id: 'footnote-label'`
* is always added as footnote calls use it with `aria-describedby` to
* provide an accessible label).
*/
footnoteLabelProperties?: HastProperties | null | undefined
/**
* Tag name to use for the footnote label.
*/
footnoteLabelTagName?: string | null | undefined
/**
* Extra handlers for nodes.
*/
handlers?: Handlers | null | undefined
/**
* List of custom mdast node types to pass through (keep) in hast (note that
* the node itself is passed, but eventual children are transformed).
*/
passThrough?: Array<string> | null | undefined
/**
* Handler for all unknown nodes.
*/
unknownHandler?: Handler | null | undefined
}
/**
* Handle nodes.
*/
export type Handlers = Record<string, Handler>
/**
* Info passed around.
*/
export type State = HFunctionProps & HFunctionNoProps & HFields

577
node_modules/mdast-util-to-hast/lib/state.js generated vendored Normal file
View file

@ -0,0 +1,577 @@
/**
* @typedef {import('hast').Content} HastContent
* @typedef {import('hast').Element} HastElement
* @typedef {import('hast').ElementContent} HastElementContent
* @typedef {import('hast').Properties} HastProperties
* @typedef {import('hast').Root} HastRoot
* @typedef {import('hast').Text} HastText
*
* @typedef {import('mdast').Content} MdastContent
* @typedef {import('mdast').Definition} MdastDefinition
* @typedef {import('mdast').FootnoteDefinition} MdastFootnoteDefinition
* @typedef {import('mdast').Parent} MdastParent
* @typedef {import('mdast').Root} MdastRoot
*/
/**
* @typedef {HastRoot | HastContent} HastNodes
* @typedef {MdastRoot | MdastContent} MdastNodes
* @typedef {Extract<MdastNodes, MdastParent>} MdastParents
*
* @typedef EmbeddedHastFields
* hast fields.
* @property {string | null | undefined} [hName]
* Generate a specific element with this tag name instead.
* @property {HastProperties | null | undefined} [hProperties]
* Generate an element with these properties instead.
* @property {Array<HastElementContent> | null | undefined} [hChildren]
* Generate an element with this content instead.
*
* @typedef {Record<string, unknown> & EmbeddedHastFields} MdastData
* mdast data with embedded hast fields.
*
* @typedef {MdastNodes & {data?: MdastData | null | undefined}} MdastNodeWithData
* mdast node with embedded hast data.
*
* @typedef PointLike
* Point-like value.
* @property {number | null | undefined} [line]
* Line.
* @property {number | null | undefined} [column]
* Column.
* @property {number | null | undefined} [offset]
* Offset.
*
* @typedef PositionLike
* Position-like value.
* @property {PointLike | null | undefined} [start]
* Point-like value.
* @property {PointLike | null | undefined} [end]
* Point-like value.
*
* @callback Handler
* Handle a node.
* @param {State} state
* Info passed around.
* @param {any} node
* mdast node to handle.
* @param {MdastParents | null | undefined} parent
* Parent of `node`.
* @returns {HastElementContent | Array<HastElementContent> | null | undefined}
* hast node.
*
* @callback HFunctionProps
* Signature of `state` for when props are passed.
* @param {MdastNodes | PositionLike | null | undefined} node
* mdast node or unist position.
* @param {string} tagName
* HTML tag name.
* @param {HastProperties} props
* Properties.
* @param {Array<HastElementContent> | null | undefined} [children]
* hast content.
* @returns {HastElement}
* Compiled element.
*
* @callback HFunctionNoProps
* Signature of `state` for when no props are passed.
* @param {MdastNodes | PositionLike | null | undefined} node
* mdast node or unist position.
* @param {string} tagName
* HTML tag name.
* @param {Array<HastElementContent> | null | undefined} [children]
* hast content.
* @returns {HastElement}
* Compiled element.
*
* @typedef HFields
* Info on `state`.
* @property {boolean} dangerous
* Whether HTML is allowed.
* @property {string} clobberPrefix
* Prefix to use to prevent DOM clobbering.
* @property {string} footnoteLabel
* Label to use to introduce the footnote section.
* @property {string} footnoteLabelTagName
* HTML used for the footnote label.
* @property {HastProperties} footnoteLabelProperties
* Properties on the HTML tag used for the footnote label.
* @property {string} footnoteBackLabel
* Label to use from backreferences back to their footnote call.
* @property {(identifier: string) => MdastDefinition | null} definition
* Definition cache.
* @property {Record<string, MdastFootnoteDefinition>} footnoteById
* Footnote definitions by their identifier.
* @property {Array<string>} footnoteOrder
* Identifiers of order when footnote calls first appear in tree order.
* @property {Record<string, number>} footnoteCounts
* Counts for how often the same footnote was called.
* @property {Handlers} handlers
* Applied handlers.
* @property {Handler} unknownHandler
* Handler for any none not in `passThrough` or otherwise handled.
* @property {(from: MdastNodes, node: HastNodes) => void} patch
* Copy a nodes positional info.
* @property {<Type extends HastNodes>(from: MdastNodes, to: Type) => Type | HastElement} applyData
* Honor the `data` of `from`, and generate an element instead of `node`.
* @property {(node: MdastNodes, parent: MdastParents | null | undefined) => HastElementContent | Array<HastElementContent> | null | undefined} one
* Transform an mdast node to hast.
* @property {(node: MdastNodes) => Array<HastElementContent>} all
* Transform the children of an mdast parent to hast.
* @property {<Type extends HastContent>(nodes: Array<Type>, loose?: boolean | null | undefined) => Array<Type | HastText>} wrap
* Wrap `nodes` with line endings between each node, adds initial/final line endings when `loose`.
* @property {(left: MdastNodeWithData | PositionLike | null | undefined, right: HastElementContent) => HastElementContent} augment
* Like `state` but lower-level and usable on non-elements.
* Deprecated: use `patch` and `applyData`.
* @property {Array<string>} passThrough
* List of node types to pass through untouched (except for their children).
*
* @typedef Options
* Configuration (optional).
* @property {boolean | null | undefined} [allowDangerousHtml=false]
* Whether to persist raw HTML in markdown in the hast tree.
* @property {string | null | undefined} [clobberPrefix='user-content-']
* Prefix to use before the `id` attribute on footnotes to prevent it from
* *clobbering*.
* @property {string | null | undefined} [footnoteBackLabel='Back to content']
* Label to use from backreferences back to their footnote call (affects
* screen readers).
* @property {string | null | undefined} [footnoteLabel='Footnotes']
* Label to use for the footnotes section (affects screen readers).
* @property {HastProperties | null | undefined} [footnoteLabelProperties={className: ['sr-only']}]
* Properties to use on the footnote label (note that `id: 'footnote-label'`
* is always added as footnote calls use it with `aria-describedby` to
* provide an accessible label).
* @property {string | null | undefined} [footnoteLabelTagName='h2']
* Tag name to use for the footnote label.
* @property {Handlers | null | undefined} [handlers]
* Extra handlers for nodes.
* @property {Array<string> | null | undefined} [passThrough]
* List of custom mdast node types to pass through (keep) in hast (note that
* the node itself is passed, but eventual children are transformed).
* @property {Handler | null | undefined} [unknownHandler]
* Handler for all unknown nodes.
*
* @typedef {Record<string, Handler>} Handlers
* Handle nodes.
*
* @typedef {HFunctionProps & HFunctionNoProps & HFields} State
* Info passed around.
*/
import {visit} from 'unist-util-visit'
import {position, pointStart, pointEnd} from 'unist-util-position'
import {generated} from 'unist-util-generated'
import {definitions} from 'mdast-util-definitions'
import {handlers} from './handlers/index.js'
const own = {}.hasOwnProperty
/**
* Create `state` from an mdast tree.
*
* @param {MdastNodes} tree
* mdast node to transform.
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {State}
* `state` function.
*/
export function createState(tree, options) {
const settings = options || {}
const dangerous = settings.allowDangerousHtml || false
/** @type {Record<string, MdastFootnoteDefinition>} */
const footnoteById = {}
// To do: next major: add `options` to state, remove:
// `dangerous`, `clobberPrefix`, `footnoteLabel`, `footnoteLabelTagName`,
// `footnoteLabelProperties`, `footnoteBackLabel`, `passThrough`,
// `unknownHandler`.
// To do: next major: move to `state.options.allowDangerousHtml`.
state.dangerous = dangerous
// To do: next major: move to `state.options`.
state.clobberPrefix =
settings.clobberPrefix === undefined || settings.clobberPrefix === null
? 'user-content-'
: settings.clobberPrefix
// To do: next major: move to `state.options`.
state.footnoteLabel = settings.footnoteLabel || 'Footnotes'
// To do: next major: move to `state.options`.
state.footnoteLabelTagName = settings.footnoteLabelTagName || 'h2'
// To do: next major: move to `state.options`.
state.footnoteLabelProperties = settings.footnoteLabelProperties || {
className: ['sr-only']
}
// To do: next major: move to `state.options`.
state.footnoteBackLabel = settings.footnoteBackLabel || 'Back to content'
// To do: next major: move to `state.options`.
state.unknownHandler = settings.unknownHandler
// To do: next major: move to `state.options`.
state.passThrough = settings.passThrough
state.handlers = {...handlers, ...settings.handlers}
// To do: next major: replace utility with `definitionById` object, so we
// only walk once (as we need footnotes too).
state.definition = definitions(tree)
state.footnoteById = footnoteById
/** @type {Array<string>} */
state.footnoteOrder = []
/** @type {Record<string, number>} */
state.footnoteCounts = {}
state.patch = patch
state.applyData = applyData
state.one = oneBound
state.all = allBound
state.wrap = wrap
// To do: next major: remove `augment`.
state.augment = augment
visit(tree, 'footnoteDefinition', (definition) => {
const id = String(definition.identifier).toUpperCase()
// Mimick CM behavior of link definitions.
// See: <https://github.com/syntax-tree/mdast-util-definitions/blob/8290999/index.js#L26>.
if (!own.call(footnoteById, id)) {
footnoteById[id] = definition
}
})
// @ts-expect-error Hush, its fine!
return state
/**
* Finalise the created `right`, a hast node, from `left`, an mdast node.
*
* @param {MdastNodeWithData | PositionLike | null | undefined} left
* @param {HastElementContent} right
* @returns {HastElementContent}
*/
/* c8 ignore start */
// To do: next major: remove.
function augment(left, right) {
// Handle `data.hName`, `data.hProperties, `data.hChildren`.
if (left && 'data' in left && left.data) {
/** @type {MdastData} */
const data = left.data
if (data.hName) {
if (right.type !== 'element') {
right = {
type: 'element',
tagName: '',
properties: {},
children: []
}
}
right.tagName = data.hName
}
if (right.type === 'element' && data.hProperties) {
right.properties = {...right.properties, ...data.hProperties}
}
if ('children' in right && right.children && data.hChildren) {
right.children = data.hChildren
}
}
if (left) {
const ctx = 'type' in left ? left : {position: left}
if (!generated(ctx)) {
// @ts-expect-error: fine.
right.position = {start: pointStart(ctx), end: pointEnd(ctx)}
}
}
return right
}
/* c8 ignore stop */
/**
* Create an element for `node`.
*
* @type {HFunctionProps}
*/
/* c8 ignore start */
// To do: next major: remove.
function state(node, tagName, props, children) {
if (Array.isArray(props)) {
children = props
props = {}
}
// @ts-expect-error augmenting an element yields an element.
return augment(node, {
type: 'element',
tagName,
properties: props || {},
children: children || []
})
}
/* c8 ignore stop */
/**
* Transform an mdast node into a hast node.
*
* @param {MdastNodes} node
* mdast node.
* @param {MdastParents | null | undefined} [parent]
* Parent of `node`.
* @returns {HastElementContent | Array<HastElementContent> | null | undefined}
* Resulting hast node.
*/
function oneBound(node, parent) {
// @ts-expect-error: thats a state :)
return one(state, node, parent)
}
/**
* Transform the children of an mdast node into hast nodes.
*
* @param {MdastNodes} parent
* mdast node to compile
* @returns {Array<HastElementContent>}
* Resulting hast nodes.
*/
function allBound(parent) {
// @ts-expect-error: thats a state :)
return all(state, parent)
}
}
/**
* Copy a nodes positional info.
*
* @param {MdastNodes} from
* mdast node to copy from.
* @param {HastNodes} to
* hast node to copy into.
* @returns {void}
* Nothing.
*/
function patch(from, to) {
if (from.position) to.position = position(from)
}
/**
* Honor the `data` of `from` and maybe generate an element instead of `to`.
*
* @template {HastNodes} Type
* Node type.
* @param {MdastNodes} from
* mdast node to use data from.
* @param {Type} to
* hast node to change.
* @returns {Type | HastElement}
* Nothing.
*/
function applyData(from, to) {
/** @type {Type | HastElement} */
let result = to
// Handle `data.hName`, `data.hProperties, `data.hChildren`.
if (from && from.data) {
const hName = from.data.hName
const hChildren = from.data.hChildren
const hProperties = from.data.hProperties
if (typeof hName === 'string') {
// Transforming the node resulted in an element with a different name
// than wanted:
if (result.type === 'element') {
result.tagName = hName
}
// Transforming the node resulted in a non-element, which happens for
// raw, text, and root nodes (unless custom handlers are passed).
// The intent is likely to keep the content around (otherwise: pass
// `hChildren`).
else {
result = {
type: 'element',
tagName: hName,
properties: {},
children: []
}
// To do: next major: take the children from the `root`, or inject the
// raw/text/comment or so into the element?
// if ('children' in node) {
// // @ts-expect-error: assume `children` are allowed in elements.
// result.children = node.children
// } else {
// // @ts-expect-error: assume `node` is allowed in elements.
// result.children.push(node)
// }
}
}
if (result.type === 'element' && hProperties) {
result.properties = {...result.properties, ...hProperties}
}
if (
'children' in result &&
result.children &&
hChildren !== null &&
hChildren !== undefined
) {
// @ts-expect-error: assume valid children are defined.
result.children = hChildren
}
}
return result
}
/**
* Transform an mdast node into a hast node.
*
* @param {State} state
* Info passed around.
* @param {MdastNodes} node
* mdast node.
* @param {MdastParents | null | undefined} [parent]
* Parent of `node`.
* @returns {HastElementContent | Array<HastElementContent> | null | undefined}
* Resulting hast node.
*/
// To do: next major: do not expose, keep bound.
export function one(state, node, parent) {
const type = node && node.type
// Fail on non-nodes.
if (!type) {
throw new Error('Expected node, got `' + node + '`')
}
if (own.call(state.handlers, type)) {
return state.handlers[type](state, node, parent)
}
if (state.passThrough && state.passThrough.includes(type)) {
// To do: next major: deep clone.
// @ts-expect-error: types of passed through nodes are expected to be added manually.
return 'children' in node ? {...node, children: all(state, node)} : node
}
if (state.unknownHandler) {
return state.unknownHandler(state, node, parent)
}
return defaultUnknownHandler(state, node)
}
/**
* Transform the children of an mdast node into hast nodes.
*
* @param {State} state
* Info passed around.
* @param {MdastNodes} parent
* mdast node to compile
* @returns {Array<HastElementContent>}
* Resulting hast nodes.
*/
// To do: next major: do not expose, keep bound.
export function all(state, parent) {
/** @type {Array<HastElementContent>} */
const values = []
if ('children' in parent) {
const nodes = parent.children
let index = -1
while (++index < nodes.length) {
const result = one(state, nodes[index], parent)
// To do: see if we van clean this? Can we merge texts?
if (result) {
if (index && nodes[index - 1].type === 'break') {
if (!Array.isArray(result) && result.type === 'text') {
result.value = result.value.replace(/^\s+/, '')
}
if (!Array.isArray(result) && result.type === 'element') {
const head = result.children[0]
if (head && head.type === 'text') {
head.value = head.value.replace(/^\s+/, '')
}
}
}
if (Array.isArray(result)) {
values.push(...result)
} else {
values.push(result)
}
}
}
}
return values
}
/**
* Transform an unknown node.
*
* @param {State} state
* Info passed around.
* @param {MdastNodes} node
* Unknown mdast node.
* @returns {HastText | HastElement}
* Resulting hast node.
*/
function defaultUnknownHandler(state, node) {
const data = node.data || {}
/** @type {HastText | HastElement} */
const result =
'value' in node &&
!(own.call(data, 'hProperties') || own.call(data, 'hChildren'))
? {type: 'text', value: node.value}
: {
type: 'element',
tagName: 'div',
properties: {},
children: all(state, node)
}
state.patch(node, result)
return state.applyData(node, result)
}
/**
* Wrap `nodes` with line endings between each node.
*
* @template {HastContent} Type
* Node type.
* @param {Array<Type>} nodes
* List of nodes to wrap.
* @param {boolean | null | undefined} [loose=false]
* Whether to add line endings at start and end.
* @returns {Array<Type | HastText>}
* Wrapped nodes.
*/
export function wrap(nodes, loose) {
/** @type {Array<Type | HastText>} */
const result = []
let index = -1
if (loose) {
result.push({type: 'text', value: '\n'})
}
while (++index < nodes.length) {
if (index) result.push({type: 'text', value: '\n'})
result.push(nodes[index])
}
if (loose && nodes.length > 0) {
result.push({type: 'text', value: '\n'})
}
return result
}

37
node_modules/mdast-util-to-hast/lib/traverse.d.ts generated vendored Normal file
View file

@ -0,0 +1,37 @@
/**
* Transform an mdast node into a hast node.
*
* @param {State} state
* Info passed around.
* @param {MdastNodes} node
* mdast node.
* @param {MdastParents | null | undefined} [parent]
* Parent of `node`.
* @returns {HastElementContent | Array<HastElementContent> | null | undefined}
* Resulting hast node.
*/
export function one(
state: State,
node: MdastNodes,
parent?: MdastParents | null | undefined
): HastElementContent | Array<HastElementContent> | null | undefined
/**
* Transform the children of an mdast node into hast nodes.
*
* @param {State} state
* Info passed around.
* @param {MdastNodes} parent
* mdast node to compile
* @returns {Array<HastElementContent>}
* Resulting hast nodes.
*/
export function all(state: State, parent: MdastNodes): Array<HastElementContent>
export type HastElementContent = import('hast').ElementContent
export type HastElement = import('hast').Element
export type HastText = import('hast').Text
export type MdastContent = import('mdast').Content
export type MdastParent = import('mdast').Parent
export type MdastRoot = import('mdast').Root
export type State = import('./state.js').State
export type MdastNodes = MdastRoot | MdastContent
export type MdastParents = Extract<MdastNodes, MdastParent>

22
node_modules/mdast-util-to-hast/lib/wrap.d.ts generated vendored Normal file
View file

@ -0,0 +1,22 @@
/**
* @typedef {import('hast').Content} Content
* @typedef {import('hast').Text} Text
*/
/**
* Wrap `nodes` with line endings between each node.
*
* @template {Content} Type
* Node type.
* @param {Array<Type>} nodes
* List of nodes to wrap.
* @param {boolean | null | undefined} [loose=false]
* Whether to add line endings at start and end.
* @returns {Array<Type | Text>}
* Wrapped nodes.
*/
export function wrap<Type extends import('hast').Content>(
nodes: Type[],
loose?: boolean | null | undefined
): (import('hast').Text | Type)[]
export type Content = import('hast').Content
export type Text = import('hast').Text

22
node_modules/mdast-util-to-hast/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.

103
node_modules/mdast-util-to-hast/package.json generated vendored Normal file
View file

@ -0,0 +1,103 @@
{
"name": "mdast-util-to-hast",
"version": "12.3.0",
"description": "mdast utility to transform to hast",
"license": "MIT",
"keywords": [
"unist",
"mdast",
"mdast-util",
"hast",
"hast-util",
"util",
"utility",
"markdown",
"html"
],
"repository": "syntax-tree/mdast-util-to-hast",
"bugs": "https://github.com/syntax-tree/mdast-util-to-hast/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/",
"complex-types.d.ts",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/hast": "^2.0.0",
"@types/mdast": "^3.0.0",
"mdast-util-definitions": "^5.0.0",
"micromark-util-sanitize-uri": "^1.1.0",
"trim-lines": "^3.0.0",
"unist-util-generated": "^2.0.0",
"unist-util-position": "^4.0.0",
"unist-util-visit": "^4.0.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"hast-util-to-html": "^8.0.4",
"hastscript": "^7.0.0",
"mdast-util-from-markdown": "^1.0.0",
"mdast-util-gfm": "^2.0.0",
"micromark-extension-gfm": "^2.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",
"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,
"rules": {
"max-depth": "off",
"import/no-cycle": "error"
}
},
"remarkConfig": {
"plugins": [
"preset-wooorm",
[
"lint-no-html",
false
]
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"#": "needed `any`s",
"ignoreFiles": [
"lib/state.d.ts"
]
}
}

1557
node_modules/mdast-util-to-hast/readme.md generated vendored Normal file

File diff suppressed because it is too large Load diff