🎉 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

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)
}