This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

16
node_modules/micromark/dev/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
export function micromark(
value: Value,
encoding: Encoding | null | undefined,
options?: Options | null | undefined
): string
export function micromark(
value: Value,
options?: Options | null | undefined
): string
export {compile} from './lib/compile.js'
export {parse} from './lib/parse.js'
export {postprocess} from './lib/postprocess.js'
export {preprocess} from './lib/preprocess.js'
export type Encoding = import('micromark-util-types').Encoding
export type Options = import('micromark-util-types').Options
export type Value = import('micromark-util-types').Value

64
node_modules/micromark/dev/index.js generated vendored Normal file
View File

@@ -0,0 +1,64 @@
/**
* @typedef {import('micromark-util-types').Encoding} Encoding
* @typedef {import('micromark-util-types').Options} Options
* @typedef {import('micromark-util-types').Value} Value
*/
import {compile} from './lib/compile.js'
import {parse} from './lib/parse.js'
import {postprocess} from './lib/postprocess.js'
import {preprocess} from './lib/preprocess.js'
export {compile} from './lib/compile.js'
export {parse} from './lib/parse.js'
export {postprocess} from './lib/postprocess.js'
export {preprocess} from './lib/preprocess.js'
/**
* Compile markdown to HTML.
*
* > Note: which encodings are supported depends on the engine.
* > For info on Node.js, see:
* > <https://nodejs.org/api/util.html#whatwg-supported-encodings>.
*
* @overload
* @param {Value} value
* Markdown to parse (`string` or `Uint8Array`).
* @param {Encoding | null | undefined} encoding
* Character encoding to understand `value` as when its a `Uint8Array`
* (`string`, default: `'utf8'`).
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {string}
* Compiled HTML.
*
* @overload
* @param {Value} value
* Markdown to parse (`string` or `Uint8Array`).
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {string}
* Compiled HTML.
*
* @param {Value} value
* Markdown to parse (`string` or `Uint8Array`).
* @param {Encoding | Options | null | undefined} [encoding]
* Character encoding to understand `value` as when its a `Uint8Array`
* (`string`, default: `'utf8'`).
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {string}
* Compiled HTML.
*/
export function micromark(value, encoding, options) {
if (typeof encoding !== 'string') {
options = encoding
encoding = undefined
}
return compile(options)(
postprocess(
parse(options).document().write(preprocess()(value, encoding, true))
)
)
}

24
node_modules/micromark/dev/lib/compile.d.ts generated vendored Normal file
View File

@@ -0,0 +1,24 @@
/**
* @param {CompileOptions | null | undefined} [options]
* @returns {Compile}
*/
export function compile(options?: CompileOptions | null | undefined): Compile
export type Compile = import('micromark-util-types').Compile
export type CompileContext = import('micromark-util-types').CompileContext
export type CompileData = import('micromark-util-types').CompileData
export type CompileOptions = import('micromark-util-types').CompileOptions
export type Definition = import('micromark-util-types').Definition
export type Event = import('micromark-util-types').Event
export type Handle = import('micromark-util-types').Handle
export type HtmlExtension = import('micromark-util-types').HtmlExtension
export type NormalizedHtmlExtension =
import('micromark-util-types').NormalizedHtmlExtension
export type Token = import('micromark-util-types').Token
export type Media = {
image?: boolean | undefined
labelId?: string | undefined
label?: string | undefined
referenceId?: string | undefined
destination?: string | undefined
title?: string | undefined
}

1154
node_modules/micromark/dev/lib/compile.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

76
node_modules/micromark/dev/lib/constructs.d.ts generated vendored Normal file
View File

@@ -0,0 +1,76 @@
/** @satisfies {Extension['document']} */
export const document: {
42: import('micromark-util-types').Construct
43: import('micromark-util-types').Construct
45: import('micromark-util-types').Construct
48: import('micromark-util-types').Construct
49: import('micromark-util-types').Construct
50: import('micromark-util-types').Construct
51: import('micromark-util-types').Construct
52: import('micromark-util-types').Construct
53: import('micromark-util-types').Construct
54: import('micromark-util-types').Construct
55: import('micromark-util-types').Construct
56: import('micromark-util-types').Construct
57: import('micromark-util-types').Construct
62: import('micromark-util-types').Construct
}
/** @satisfies {Extension['contentInitial']} */
export const contentInitial: {
91: import('micromark-util-types').Construct
}
/** @satisfies {Extension['flowInitial']} */
export const flowInitial: {
[-2]: import('micromark-util-types').Construct
[-1]: import('micromark-util-types').Construct
32: import('micromark-util-types').Construct
}
/** @satisfies {Extension['flow']} */
export const flow: {
35: import('micromark-util-types').Construct
42: import('micromark-util-types').Construct
45: import('micromark-util-types').Construct[]
60: import('micromark-util-types').Construct
61: import('micromark-util-types').Construct
95: import('micromark-util-types').Construct
96: import('micromark-util-types').Construct
126: import('micromark-util-types').Construct
}
/** @satisfies {Extension['string']} */
export const string: {
38: import('micromark-util-types').Construct
92: import('micromark-util-types').Construct
}
/** @satisfies {Extension['text']} */
export const text: {
[-5]: import('micromark-util-types').Construct
[-4]: import('micromark-util-types').Construct
[-3]: import('micromark-util-types').Construct
33: import('micromark-util-types').Construct
38: import('micromark-util-types').Construct
42: import('micromark-util-types').Construct
60: import('micromark-util-types').Construct[]
91: import('micromark-util-types').Construct
92: import('micromark-util-types').Construct[]
93: import('micromark-util-types').Construct
95: import('micromark-util-types').Construct
96: import('micromark-util-types').Construct
}
export namespace insideSpan {
let _null: (
| import('micromark-util-types').Construct
| {
resolveAll: import('micromark-util-types').Resolver
}
)[]
export {_null as null}
}
export namespace attentionMarkers {
let _null_1: (42 | 95)[]
export {_null_1 as null}
}
export namespace disable {
let _null_2: never[]
export {_null_2 as null}
}
export type Extension = import('micromark-util-types').Extension

101
node_modules/micromark/dev/lib/constructs.js generated vendored Normal file
View File

@@ -0,0 +1,101 @@
/**
* @typedef {import('micromark-util-types').Extension} Extension
*/
import {
attention,
autolink,
blockQuote,
characterEscape,
characterReference,
codeFenced,
codeIndented,
codeText,
definition,
hardBreakEscape,
headingAtx,
htmlFlow,
htmlText,
labelEnd,
labelStartImage,
labelStartLink,
lineEnding,
list,
setextUnderline,
thematicBreak
} from 'micromark-core-commonmark'
import {codes} from 'micromark-util-symbol'
import {resolver as resolveText} from './initialize/text.js'
/** @satisfies {Extension['document']} */
export const document = {
[codes.asterisk]: list,
[codes.plusSign]: list,
[codes.dash]: list,
[codes.digit0]: list,
[codes.digit1]: list,
[codes.digit2]: list,
[codes.digit3]: list,
[codes.digit4]: list,
[codes.digit5]: list,
[codes.digit6]: list,
[codes.digit7]: list,
[codes.digit8]: list,
[codes.digit9]: list,
[codes.greaterThan]: blockQuote
}
/** @satisfies {Extension['contentInitial']} */
export const contentInitial = {
[codes.leftSquareBracket]: definition
}
/** @satisfies {Extension['flowInitial']} */
export const flowInitial = {
[codes.horizontalTab]: codeIndented,
[codes.virtualSpace]: codeIndented,
[codes.space]: codeIndented
}
/** @satisfies {Extension['flow']} */
export const flow = {
[codes.numberSign]: headingAtx,
[codes.asterisk]: thematicBreak,
[codes.dash]: [setextUnderline, thematicBreak],
[codes.lessThan]: htmlFlow,
[codes.equalsTo]: setextUnderline,
[codes.underscore]: thematicBreak,
[codes.graveAccent]: codeFenced,
[codes.tilde]: codeFenced
}
/** @satisfies {Extension['string']} */
export const string = {
[codes.ampersand]: characterReference,
[codes.backslash]: characterEscape
}
/** @satisfies {Extension['text']} */
export const text = {
[codes.carriageReturn]: lineEnding,
[codes.lineFeed]: lineEnding,
[codes.carriageReturnLineFeed]: lineEnding,
[codes.exclamationMark]: labelStartImage,
[codes.ampersand]: characterReference,
[codes.asterisk]: attention,
[codes.lessThan]: [autolink, htmlText],
[codes.leftSquareBracket]: labelStartLink,
[codes.backslash]: [hardBreakEscape, characterEscape],
[codes.rightSquareBracket]: labelEnd,
[codes.underscore]: attention,
[codes.graveAccent]: codeText
}
/** @satisfies {Extension['insideSpan']} */
export const insideSpan = {null: [attention, resolveText]}
/** @satisfies {Extension['attentionMarkers']} */
export const attentionMarkers = {null: [codes.asterisk, codes.underscore]}
/** @satisfies {Extension['disable']} */
export const disable = {null: []}

40
node_modules/micromark/dev/lib/create-tokenizer.d.ts generated vendored Normal file
View File

@@ -0,0 +1,40 @@
/**
* Create a tokenizer.
* Tokenizers deal with one type of data (e.g., containers, flow, text).
* The parser is the object dealing with it all.
* `initialize` works like other constructs, except that only its `tokenize`
* function is used, in which case it doesnt receive an `ok` or `nok`.
* `from` can be given to set the point before the first character, although
* when further lines are indented, they must be set with `defineSkip`.
*
* @param {ParseContext} parser
* @param {InitialConstruct} initialize
* @param {Omit<Point, '_bufferIndex' | '_index'> | undefined} [from]
* @returns {TokenizeContext}
*/
export function createTokenizer(
parser: ParseContext,
initialize: InitialConstruct,
from?: Omit<Point, '_bufferIndex' | '_index'> | undefined
): TokenizeContext
export type Chunk = import('micromark-util-types').Chunk
export type Code = import('micromark-util-types').Code
export type Construct = import('micromark-util-types').Construct
export type ConstructRecord = import('micromark-util-types').ConstructRecord
export type Effects = import('micromark-util-types').Effects
export type InitialConstruct = import('micromark-util-types').InitialConstruct
export type ParseContext = import('micromark-util-types').ParseContext
export type Point = import('micromark-util-types').Point
export type State = import('micromark-util-types').State
export type Token = import('micromark-util-types').Token
export type TokenType = import('micromark-util-types').TokenType
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Restore = () => undefined
export type Info = {
restore: Restore
from: number
}
/**
* Handle a successful run.
*/
export type ReturnHandle = (construct: Construct, info: Info) => undefined

670
node_modules/micromark/dev/lib/create-tokenizer.js generated vendored Normal file
View File

@@ -0,0 +1,670 @@
/**
* @typedef {import('micromark-util-types').Chunk} Chunk
* @typedef {import('micromark-util-types').Code} Code
* @typedef {import('micromark-util-types').Construct} Construct
* @typedef {import('micromark-util-types').ConstructRecord} ConstructRecord
* @typedef {import('micromark-util-types').Effects} Effects
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').ParseContext} ParseContext
* @typedef {import('micromark-util-types').Point} Point
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').TokenType} TokenType
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
*/
/**
* @callback Restore
* @returns {undefined}
*
* @typedef Info
* @property {Restore} restore
* @property {number} from
*
* @callback ReturnHandle
* Handle a successful run.
* @param {Construct} construct
* @param {Info} info
* @returns {undefined}
*/
import createDebug from 'debug'
import {markdownLineEnding} from 'micromark-util-character'
import {push, splice} from 'micromark-util-chunked'
import {resolveAll} from 'micromark-util-resolve-all'
import {codes, values} from 'micromark-util-symbol'
import {ok as assert} from 'devlop'
const debug = createDebug('micromark')
/**
* Create a tokenizer.
* Tokenizers deal with one type of data (e.g., containers, flow, text).
* The parser is the object dealing with it all.
* `initialize` works like other constructs, except that only its `tokenize`
* function is used, in which case it doesnt receive an `ok` or `nok`.
* `from` can be given to set the point before the first character, although
* when further lines are indented, they must be set with `defineSkip`.
*
* @param {ParseContext} parser
* @param {InitialConstruct} initialize
* @param {Omit<Point, '_bufferIndex' | '_index'> | undefined} [from]
* @returns {TokenizeContext}
*/
export function createTokenizer(parser, initialize, from) {
/** @type {Point} */
let point = Object.assign(
from ? Object.assign({}, from) : {line: 1, column: 1, offset: 0},
{_index: 0, _bufferIndex: -1}
)
/** @type {Record<string, number>} */
const columnStart = {}
/** @type {Array<Construct>} */
const resolveAllConstructs = []
/** @type {Array<Chunk>} */
let chunks = []
/** @type {Array<Token>} */
let stack = []
/** @type {boolean | undefined} */
let consumed = true
/**
* Tools used for tokenizing.
*
* @type {Effects}
*/
const effects = {
consume,
enter,
exit,
attempt: constructFactory(onsuccessfulconstruct),
check: constructFactory(onsuccessfulcheck),
interrupt: constructFactory(onsuccessfulcheck, {interrupt: true})
}
/**
* State and tools for resolving and serializing.
*
* @type {TokenizeContext}
*/
const context = {
previous: codes.eof,
code: codes.eof,
containerState: {},
events: [],
parser,
sliceStream,
sliceSerialize,
now,
defineSkip,
write
}
/**
* The state function.
*
* @type {State | undefined}
*/
let state = initialize.tokenize.call(context, effects)
/**
* Track which character we expect to be consumed, to catch bugs.
*
* @type {Code}
*/
let expectedCode
if (initialize.resolveAll) {
resolveAllConstructs.push(initialize)
}
return context
/** @type {TokenizeContext['write']} */
function write(slice) {
chunks = push(chunks, slice)
main()
// Exit if were not done, resolve might change stuff.
if (chunks[chunks.length - 1] !== codes.eof) {
return []
}
addResult(initialize, 0)
// Otherwise, resolve, and exit.
context.events = resolveAll(resolveAllConstructs, context.events, context)
return context.events
}
//
// Tools.
//
/** @type {TokenizeContext['sliceSerialize']} */
function sliceSerialize(token, expandTabs) {
return serializeChunks(sliceStream(token), expandTabs)
}
/** @type {TokenizeContext['sliceStream']} */
function sliceStream(token) {
return sliceChunks(chunks, token)
}
/** @type {TokenizeContext['now']} */
function now() {
// This is a hot path, so we clone manually instead of `Object.assign({}, point)`
const {line, column, offset, _index, _bufferIndex} = point
return {line, column, offset, _index, _bufferIndex}
}
/** @type {TokenizeContext['defineSkip']} */
function defineSkip(value) {
columnStart[value.line] = value.column
accountForPotentialSkip()
debug('position: define skip: `%j`', point)
}
//
// State management.
//
/**
* Main loop (note that `_index` and `_bufferIndex` in `point` are modified by
* `consume`).
* Here is where we walk through the chunks, which either include strings of
* several characters, or numerical character codes.
* The reason to do this in a loop instead of a call is so the stack can
* drain.
*
* @returns {undefined}
*/
function main() {
/** @type {number} */
let chunkIndex
while (point._index < chunks.length) {
const chunk = chunks[point._index]
// If were in a buffer chunk, loop through it.
if (typeof chunk === 'string') {
chunkIndex = point._index
if (point._bufferIndex < 0) {
point._bufferIndex = 0
}
while (
point._index === chunkIndex &&
point._bufferIndex < chunk.length
) {
go(chunk.charCodeAt(point._bufferIndex))
}
} else {
go(chunk)
}
}
}
/**
* Deal with one code.
*
* @param {Code} code
* @returns {undefined}
*/
function go(code) {
assert(consumed === true, 'expected character to be consumed')
consumed = undefined
debug('main: passing `%s` to %s', code, state && state.name)
expectedCode = code
assert(typeof state === 'function', 'expected state')
state = state(code)
}
/** @type {Effects['consume']} */
function consume(code) {
assert(code === expectedCode, 'expected given code to equal expected code')
debug('consume: `%s`', code)
assert(
consumed === undefined,
'expected code to not have been consumed: this might be because `return x(code)` instead of `return x` was used'
)
assert(
code === null
? context.events.length === 0 ||
context.events[context.events.length - 1][0] === 'exit'
: context.events[context.events.length - 1][0] === 'enter',
'expected last token to be open'
)
if (markdownLineEnding(code)) {
point.line++
point.column = 1
point.offset += code === codes.carriageReturnLineFeed ? 2 : 1
accountForPotentialSkip()
debug('position: after eol: `%j`', point)
} else if (code !== codes.virtualSpace) {
point.column++
point.offset++
}
// Not in a string chunk.
if (point._bufferIndex < 0) {
point._index++
} else {
point._bufferIndex++
// At end of string chunk.
// @ts-expect-error Points w/ non-negative `_bufferIndex` reference
// strings.
if (point._bufferIndex === chunks[point._index].length) {
point._bufferIndex = -1
point._index++
}
}
// Expose the previous character.
context.previous = code
// Mark as consumed.
consumed = true
}
/** @type {Effects['enter']} */
function enter(type, fields) {
/** @type {Token} */
// @ts-expect-error Patch instead of assign required fields to help GC.
const token = fields || {}
token.type = type
token.start = now()
assert(typeof type === 'string', 'expected string type')
assert(type.length > 0, 'expected non-empty string')
debug('enter: `%s`', type)
context.events.push(['enter', token, context])
stack.push(token)
return token
}
/** @type {Effects['exit']} */
function exit(type) {
assert(typeof type === 'string', 'expected string type')
assert(type.length > 0, 'expected non-empty string')
const token = stack.pop()
assert(token, 'cannot close w/o open tokens')
token.end = now()
assert(type === token.type, 'expected exit token to match current token')
assert(
!(
token.start._index === token.end._index &&
token.start._bufferIndex === token.end._bufferIndex
),
'expected non-empty token (`' + type + '`)'
)
debug('exit: `%s`', token.type)
context.events.push(['exit', token, context])
return token
}
/**
* Use results.
*
* @type {ReturnHandle}
*/
function onsuccessfulconstruct(construct, info) {
addResult(construct, info.from)
}
/**
* Discard results.
*
* @type {ReturnHandle}
*/
function onsuccessfulcheck(_, info) {
info.restore()
}
/**
* Factory to attempt/check/interrupt.
*
* @param {ReturnHandle} onreturn
* @param {{interrupt?: boolean | undefined} | undefined} [fields]
*/
function constructFactory(onreturn, fields) {
return hook
/**
* Handle either an object mapping codes to constructs, a list of
* constructs, or a single construct.
*
* @param {Array<Construct> | Construct | ConstructRecord} constructs
* @param {State} returnState
* @param {State | undefined} [bogusState]
* @returns {State}
*/
function hook(constructs, returnState, bogusState) {
/** @type {Array<Construct>} */
let listOfConstructs
/** @type {number} */
let constructIndex
/** @type {Construct} */
let currentConstruct
/** @type {Info} */
let info
return Array.isArray(constructs)
? /* c8 ignore next 1 */
handleListOfConstructs(constructs)
: 'tokenize' in constructs
? // @ts-expect-error Looks like a construct.
handleListOfConstructs([constructs])
: handleMapOfConstructs(constructs)
/**
* Handle a list of construct.
*
* @param {ConstructRecord} map
* @returns {State}
*/
function handleMapOfConstructs(map) {
return start
/** @type {State} */
function start(code) {
const def = code !== null && map[code]
const all = code !== null && map.null
const list = [
// To do: add more extension tests.
/* c8 ignore next 2 */
...(Array.isArray(def) ? def : def ? [def] : []),
...(Array.isArray(all) ? all : all ? [all] : [])
]
return handleListOfConstructs(list)(code)
}
}
/**
* Handle a list of construct.
*
* @param {Array<Construct>} list
* @returns {State}
*/
function handleListOfConstructs(list) {
listOfConstructs = list
constructIndex = 0
if (list.length === 0) {
assert(bogusState, 'expected `bogusState` to be given')
return bogusState
}
return handleConstruct(list[constructIndex])
}
/**
* Handle a single construct.
*
* @param {Construct} construct
* @returns {State}
*/
function handleConstruct(construct) {
return start
/** @type {State} */
function start(code) {
// To do: not needed to store if there is no bogus state, probably?
// Currently doesnt work because `inspect` in document does a check
// w/o a bogus, which doesnt make sense. But it does seem to help perf
// by not storing.
info = store()
currentConstruct = construct
if (!construct.partial) {
context.currentConstruct = construct
}
// Always populated by defaults.
assert(
context.parser.constructs.disable.null,
'expected `disable.null` to be populated'
)
if (
construct.name &&
context.parser.constructs.disable.null.includes(construct.name)
) {
return nok(code)
}
return construct.tokenize.call(
// If we do have fields, create an object w/ `context` as its
// prototype.
// This allows a “live binding”, which is needed for `interrupt`.
fields ? Object.assign(Object.create(context), fields) : context,
effects,
ok,
nok
)(code)
}
}
/** @type {State} */
function ok(code) {
assert(code === expectedCode, 'expected code')
consumed = true
onreturn(currentConstruct, info)
return returnState
}
/** @type {State} */
function nok(code) {
assert(code === expectedCode, 'expected code')
consumed = true
info.restore()
if (++constructIndex < listOfConstructs.length) {
return handleConstruct(listOfConstructs[constructIndex])
}
return bogusState
}
}
}
/**
* @param {Construct} construct
* @param {number} from
* @returns {undefined}
*/
function addResult(construct, from) {
if (construct.resolveAll && !resolveAllConstructs.includes(construct)) {
resolveAllConstructs.push(construct)
}
if (construct.resolve) {
splice(
context.events,
from,
context.events.length - from,
construct.resolve(context.events.slice(from), context)
)
}
if (construct.resolveTo) {
context.events = construct.resolveTo(context.events, context)
}
assert(
construct.partial ||
context.events.length === 0 ||
context.events[context.events.length - 1][0] === 'exit',
'expected last token to end'
)
}
/**
* Store state.
*
* @returns {Info}
*/
function store() {
const startPoint = now()
const startPrevious = context.previous
const startCurrentConstruct = context.currentConstruct
const startEventsIndex = context.events.length
const startStack = Array.from(stack)
return {restore, from: startEventsIndex}
/**
* Restore state.
*
* @returns {undefined}
*/
function restore() {
point = startPoint
context.previous = startPrevious
context.currentConstruct = startCurrentConstruct
context.events.length = startEventsIndex
stack = startStack
accountForPotentialSkip()
debug('position: restore: `%j`', point)
}
}
/**
* Move the current point a bit forward in the line when its on a column
* skip.
*
* @returns {undefined}
*/
function accountForPotentialSkip() {
if (point.line in columnStart && point.column < 2) {
point.column = columnStart[point.line]
point.offset += columnStart[point.line] - 1
}
}
}
/**
* Get the chunks from a slice of chunks in the range of a token.
*
* @param {Array<Chunk>} chunks
* @param {Pick<Token, 'end' | 'start'>} token
* @returns {Array<Chunk>}
*/
function sliceChunks(chunks, token) {
const startIndex = token.start._index
const startBufferIndex = token.start._bufferIndex
const endIndex = token.end._index
const endBufferIndex = token.end._bufferIndex
/** @type {Array<Chunk>} */
let view
if (startIndex === endIndex) {
assert(endBufferIndex > -1, 'expected non-negative end buffer index')
assert(startBufferIndex > -1, 'expected non-negative start buffer index')
// @ts-expect-error `_bufferIndex` is used on string chunks.
view = [chunks[startIndex].slice(startBufferIndex, endBufferIndex)]
} else {
view = chunks.slice(startIndex, endIndex)
if (startBufferIndex > -1) {
const head = view[0]
if (typeof head === 'string') {
view[0] = head.slice(startBufferIndex)
} else {
assert(startBufferIndex === 0, 'expected `startBufferIndex` to be `0`')
view.shift()
}
}
if (endBufferIndex > 0) {
// @ts-expect-error `_bufferIndex` is used on string chunks.
view.push(chunks[endIndex].slice(0, endBufferIndex))
}
}
return view
}
/**
* Get the string value of a slice of chunks.
*
* @param {Array<Chunk>} chunks
* @param {boolean | undefined} [expandTabs=false]
* @returns {string}
*/
function serializeChunks(chunks, expandTabs) {
let index = -1
/** @type {Array<string>} */
const result = []
/** @type {boolean | undefined} */
let atTab
while (++index < chunks.length) {
const chunk = chunks[index]
/** @type {string} */
let value
if (typeof chunk === 'string') {
value = chunk
} else
switch (chunk) {
case codes.carriageReturn: {
value = values.cr
break
}
case codes.lineFeed: {
value = values.lf
break
}
case codes.carriageReturnLineFeed: {
value = values.cr + values.lf
break
}
case codes.horizontalTab: {
value = expandTabs ? values.space : values.ht
break
}
case codes.virtualSpace: {
if (!expandTabs && atTab) continue
value = values.space
break
}
default: {
assert(typeof chunk === 'number', 'expected number')
// Currently only replacement character.
value = String.fromCharCode(chunk)
}
}
atTab = chunk === codes.horizontalTab
result.push(value)
}
return result.join('')
}

View File

@@ -0,0 +1,7 @@
/** @type {InitialConstruct} */
export const content: InitialConstruct
export type InitialConstruct = import('micromark-util-types').InitialConstruct
export type Initializer = import('micromark-util-types').Initializer
export type State = import('micromark-util-types').State
export type Token = import('micromark-util-types').Token
export type TokenizeContext = import('micromark-util-types').TokenizeContext

95
node_modules/micromark/dev/lib/initialize/content.js generated vendored Normal file
View File

@@ -0,0 +1,95 @@
/**
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').Initializer} Initializer
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
*/
import {factorySpace} from 'micromark-factory-space'
import {markdownLineEnding} from 'micromark-util-character'
import {codes, constants, types} from 'micromark-util-symbol'
import {ok as assert} from 'devlop'
/** @type {InitialConstruct} */
export const content = {tokenize: initializeContent}
/**
* @this {TokenizeContext}
* @type {Initializer}
*/
function initializeContent(effects) {
const contentStart = effects.attempt(
this.parser.constructs.contentInitial,
afterContentStartConstruct,
paragraphInitial
)
/** @type {Token} */
let previous
return contentStart
/** @type {State} */
function afterContentStartConstruct(code) {
assert(
code === codes.eof || markdownLineEnding(code),
'expected eol or eof'
)
if (code === codes.eof) {
effects.consume(code)
return
}
effects.enter(types.lineEnding)
effects.consume(code)
effects.exit(types.lineEnding)
return factorySpace(effects, contentStart, types.linePrefix)
}
/** @type {State} */
function paragraphInitial(code) {
assert(
code !== codes.eof && !markdownLineEnding(code),
'expected anything other than a line ending or EOF'
)
effects.enter(types.paragraph)
return lineStart(code)
}
/** @type {State} */
function lineStart(code) {
const token = effects.enter(types.chunkText, {
contentType: constants.contentTypeText,
previous
})
if (previous) {
previous.next = token
}
previous = token
return data(code)
}
/** @type {State} */
function data(code) {
if (code === codes.eof) {
effects.exit(types.chunkText)
effects.exit(types.paragraph)
effects.consume(code)
return
}
if (markdownLineEnding(code)) {
effects.consume(code)
effects.exit(types.chunkText)
return lineStart
}
// Data.
effects.consume(code)
return data
}
}

View File

@@ -0,0 +1,12 @@
/** @type {InitialConstruct} */
export const document: InitialConstruct
export type Construct = import('micromark-util-types').Construct
export type ContainerState = import('micromark-util-types').ContainerState
export type InitialConstruct = import('micromark-util-types').InitialConstruct
export type Initializer = import('micromark-util-types').Initializer
export type Point = import('micromark-util-types').Point
export type State = import('micromark-util-types').State
export type Token = import('micromark-util-types').Token
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Tokenizer = import('micromark-util-types').Tokenizer
export type StackItem = [Construct, ContainerState]

433
node_modules/micromark/dev/lib/initialize/document.js generated vendored Normal file
View File

@@ -0,0 +1,433 @@
/**
* @typedef {import('micromark-util-types').Construct} Construct
* @typedef {import('micromark-util-types').ContainerState} ContainerState
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').Initializer} Initializer
* @typedef {import('micromark-util-types').Point} Point
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
*/
/**
* @typedef {[Construct, ContainerState]} StackItem
*/
import {factorySpace} from 'micromark-factory-space'
import {markdownLineEnding} from 'micromark-util-character'
import {splice} from 'micromark-util-chunked'
import {codes, constants, types} from 'micromark-util-symbol'
import {ok as assert} from 'devlop'
/** @type {InitialConstruct} */
export const document = {tokenize: initializeDocument}
/** @type {Construct} */
const containerConstruct = {tokenize: tokenizeContainer}
/**
* @this {TokenizeContext}
* @type {Initializer}
*/
function initializeDocument(effects) {
const self = this
/** @type {Array<StackItem>} */
const stack = []
let continued = 0
/** @type {TokenizeContext | undefined} */
let childFlow
/** @type {Token | undefined} */
let childToken
/** @type {number} */
let lineStartOffset
return start
/** @type {State} */
function start(code) {
// First we iterate through the open blocks, starting with the root
// document, and descending through last children down to the last open
// block.
// Each block imposes a condition that the line must satisfy if the block is
// to remain open.
// For example, a block quote requires a `>` character.
// A paragraph requires a non-blank line.
// In this phase we may match all or just some of the open blocks.
// But we cannot close unmatched blocks yet, because we may have a lazy
// continuation line.
if (continued < stack.length) {
const item = stack[continued]
self.containerState = item[1]
assert(
item[0].continuation,
'expected `continuation` to be defined on container construct'
)
return effects.attempt(
item[0].continuation,
documentContinue,
checkNewContainers
)(code)
}
// Done.
return checkNewContainers(code)
}
/** @type {State} */
function documentContinue(code) {
assert(
self.containerState,
'expected `containerState` to be defined after continuation'
)
continued++
// Note: this field is called `_closeFlow` but it also closes containers.
// Perhaps a good idea to rename it but its already used in the wild by
// extensions.
if (self.containerState._closeFlow) {
self.containerState._closeFlow = undefined
if (childFlow) {
closeFlow()
}
// Note: this algorithm for moving events around is similar to the
// algorithm when dealing with lazy lines in `writeToChild`.
const indexBeforeExits = self.events.length
let indexBeforeFlow = indexBeforeExits
/** @type {Point | undefined} */
let point
// Find the flow chunk.
while (indexBeforeFlow--) {
if (
self.events[indexBeforeFlow][0] === 'exit' &&
self.events[indexBeforeFlow][1].type === types.chunkFlow
) {
point = self.events[indexBeforeFlow][1].end
break
}
}
assert(point, 'could not find previous flow chunk')
exitContainers(continued)
// Fix positions.
let index = indexBeforeExits
while (index < self.events.length) {
self.events[index][1].end = Object.assign({}, point)
index++
}
// Inject the exits earlier (theyre still also at the end).
splice(
self.events,
indexBeforeFlow + 1,
0,
self.events.slice(indexBeforeExits)
)
// Discard the duplicate exits.
self.events.length = index
return checkNewContainers(code)
}
return start(code)
}
/** @type {State} */
function checkNewContainers(code) {
// Next, after consuming the continuation markers for existing blocks, we
// look for new block starts (e.g. `>` for a block quote).
// If we encounter a new block start, we close any blocks unmatched in
// step 1 before creating the new block as a child of the last matched
// block.
if (continued === stack.length) {
// No need to `check` whether theres a container, of `exitContainers`
// would be moot.
// We can instead immediately `attempt` to parse one.
if (!childFlow) {
return documentContinued(code)
}
// If we have concrete content, such as block HTML or fenced code,
// we cant have containers “pierce” into them, so we can immediately
// start.
if (childFlow.currentConstruct && childFlow.currentConstruct.concrete) {
return flowStart(code)
}
// If we do have flow, it could still be a blank line,
// but wed be interrupting it w/ a new container if theres a current
// construct.
// To do: next major: remove `_gfmTableDynamicInterruptHack` (no longer
// needed in micromark-extension-gfm-table@1.0.6).
self.interrupt = Boolean(
childFlow.currentConstruct && !childFlow._gfmTableDynamicInterruptHack
)
}
// Check if there is a new container.
self.containerState = {}
return effects.check(
containerConstruct,
thereIsANewContainer,
thereIsNoNewContainer
)(code)
}
/** @type {State} */
function thereIsANewContainer(code) {
if (childFlow) closeFlow()
exitContainers(continued)
return documentContinued(code)
}
/** @type {State} */
function thereIsNoNewContainer(code) {
self.parser.lazy[self.now().line] = continued !== stack.length
lineStartOffset = self.now().offset
return flowStart(code)
}
/** @type {State} */
function documentContinued(code) {
// Try new containers.
self.containerState = {}
return effects.attempt(
containerConstruct,
containerContinue,
flowStart
)(code)
}
/** @type {State} */
function containerContinue(code) {
assert(
self.currentConstruct,
'expected `currentConstruct` to be defined on tokenizer'
)
assert(
self.containerState,
'expected `containerState` to be defined on tokenizer'
)
continued++
stack.push([self.currentConstruct, self.containerState])
// Try another.
return documentContinued(code)
}
/** @type {State} */
function flowStart(code) {
if (code === codes.eof) {
if (childFlow) closeFlow()
exitContainers(0)
effects.consume(code)
return
}
childFlow = childFlow || self.parser.flow(self.now())
effects.enter(types.chunkFlow, {
contentType: constants.contentTypeFlow,
previous: childToken,
_tokenizer: childFlow
})
return flowContinue(code)
}
/** @type {State} */
function flowContinue(code) {
if (code === codes.eof) {
writeToChild(effects.exit(types.chunkFlow), true)
exitContainers(0)
effects.consume(code)
return
}
if (markdownLineEnding(code)) {
effects.consume(code)
writeToChild(effects.exit(types.chunkFlow))
// Get ready for the next line.
continued = 0
self.interrupt = undefined
return start
}
effects.consume(code)
return flowContinue
}
/**
* @param {Token} token
* @param {boolean | undefined} [eof]
* @returns {undefined}
*/
function writeToChild(token, eof) {
assert(childFlow, 'expected `childFlow` to be defined when continuing')
const stream = self.sliceStream(token)
if (eof) stream.push(null)
token.previous = childToken
if (childToken) childToken.next = token
childToken = token
childFlow.defineSkip(token.start)
childFlow.write(stream)
// Alright, so we just added a lazy line:
//
// ```markdown
// > a
// b.
//
// Or:
//
// > ~~~c
// d
//
// Or:
//
// > | e |
// f
// ```
//
// The construct in the second example (fenced code) does not accept lazy
// lines, so it marked itself as done at the end of its first line, and
// then the content construct parses `d`.
// Most constructs in markdown match on the first line: if the first line
// forms a construct, a non-lazy line cant “unmake” it.
//
// The construct in the third example is potentially a GFM table, and
// those are *weird*.
// It *could* be a table, from the first line, if the following line
// matches a condition.
// In this case, that second line is lazy, which “unmakes” the first line
// and turns the whole into one content block.
//
// Weve now parsed the non-lazy and the lazy line, and can figure out
// whether the lazy line started a new flow block.
// If it did, we exit the current containers between the two flow blocks.
if (self.parser.lazy[token.start.line]) {
let index = childFlow.events.length
while (index--) {
if (
// The token starts before the line ending…
childFlow.events[index][1].start.offset < lineStartOffset &&
// …and either is not ended yet…
(!childFlow.events[index][1].end ||
// …or ends after it.
childFlow.events[index][1].end.offset > lineStartOffset)
) {
// Exit: theres still something open, which means its a lazy line
// part of something.
return
}
}
// Note: this algorithm for moving events around is similar to the
// algorithm when closing flow in `documentContinue`.
const indexBeforeExits = self.events.length
let indexBeforeFlow = indexBeforeExits
/** @type {boolean | undefined} */
let seen
/** @type {Point | undefined} */
let point
// Find the previous chunk (the one before the lazy line).
while (indexBeforeFlow--) {
if (
self.events[indexBeforeFlow][0] === 'exit' &&
self.events[indexBeforeFlow][1].type === types.chunkFlow
) {
if (seen) {
point = self.events[indexBeforeFlow][1].end
break
}
seen = true
}
}
assert(point, 'could not find previous flow chunk')
exitContainers(continued)
// Fix positions.
index = indexBeforeExits
while (index < self.events.length) {
self.events[index][1].end = Object.assign({}, point)
index++
}
// Inject the exits earlier (theyre still also at the end).
splice(
self.events,
indexBeforeFlow + 1,
0,
self.events.slice(indexBeforeExits)
)
// Discard the duplicate exits.
self.events.length = index
}
}
/**
* @param {number} size
* @returns {undefined}
*/
function exitContainers(size) {
let index = stack.length
// Exit open containers.
while (index-- > size) {
const entry = stack[index]
self.containerState = entry[1]
assert(
entry[0].exit,
'expected `exit` to be defined on container construct'
)
entry[0].exit.call(self, effects)
}
stack.length = size
}
function closeFlow() {
assert(
self.containerState,
'expected `containerState` to be defined when closing flow'
)
assert(childFlow, 'expected `childFlow` to be defined when closing it')
childFlow.write([codes.eof])
childToken = undefined
childFlow = undefined
self.containerState._closeFlow = undefined
}
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeContainer(effects, ok, nok) {
// Always populated by defaults.
assert(
this.parser.constructs.disable.null,
'expected `disable.null` to be populated'
)
return factorySpace(
effects,
effects.attempt(this.parser.constructs.document, ok, nok),
types.linePrefix,
this.parser.constructs.disable.null.includes('codeIndented')
? undefined
: constants.tabSize
)
}

6
node_modules/micromark/dev/lib/initialize/flow.d.ts generated vendored Normal file
View File

@@ -0,0 +1,6 @@
/** @type {InitialConstruct} */
export const flow: InitialConstruct
export type InitialConstruct = import('micromark-util-types').InitialConstruct
export type Initializer = import('micromark-util-types').Initializer
export type State = import('micromark-util-types').State
export type TokenizeContext = import('micromark-util-types').TokenizeContext

82
node_modules/micromark/dev/lib/initialize/flow.js generated vendored Normal file
View File

@@ -0,0 +1,82 @@
/**
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').Initializer} Initializer
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
*/
import {blankLine, content} from 'micromark-core-commonmark'
import {factorySpace} from 'micromark-factory-space'
import {markdownLineEnding} from 'micromark-util-character'
import {codes, types} from 'micromark-util-symbol'
import {ok as assert} from 'devlop'
/** @type {InitialConstruct} */
export const flow = {tokenize: initializeFlow}
/**
* @this {TokenizeContext}
* @type {Initializer}
*/
function initializeFlow(effects) {
const self = this
const initial = effects.attempt(
// Try to parse a blank line.
blankLine,
atBlankEnding,
// Try to parse initial flow (essentially, only code).
effects.attempt(
this.parser.constructs.flowInitial,
afterConstruct,
factorySpace(
effects,
effects.attempt(
this.parser.constructs.flow,
afterConstruct,
effects.attempt(content, afterConstruct)
),
types.linePrefix
)
)
)
return initial
/** @type {State} */
function atBlankEnding(code) {
assert(
code === codes.eof || markdownLineEnding(code),
'expected eol or eof'
)
if (code === codes.eof) {
effects.consume(code)
return
}
effects.enter(types.lineEndingBlank)
effects.consume(code)
effects.exit(types.lineEndingBlank)
self.currentConstruct = undefined
return initial
}
/** @type {State} */
function afterConstruct(code) {
assert(
code === codes.eof || markdownLineEnding(code),
'expected eol or eof'
)
if (code === codes.eof) {
effects.consume(code)
return
}
effects.enter(types.lineEnding)
effects.consume(code)
effects.exit(types.lineEnding)
self.currentConstruct = undefined
return initial
}
}

11
node_modules/micromark/dev/lib/initialize/text.d.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
export namespace resolver {
let resolveAll: import('micromark-util-types').Resolver
}
export const string: import('micromark-util-types').InitialConstruct
export const text: import('micromark-util-types').InitialConstruct
export type Code = import('micromark-util-types').Code
export type InitialConstruct = import('micromark-util-types').InitialConstruct
export type Initializer = import('micromark-util-types').Initializer
export type Resolver = import('micromark-util-types').Resolver
export type State = import('micromark-util-types').State
export type TokenizeContext = import('micromark-util-types').TokenizeContext

230
node_modules/micromark/dev/lib/initialize/text.js generated vendored Normal file
View File

@@ -0,0 +1,230 @@
/**
* @typedef {import('micromark-util-types').Code} Code
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').Initializer} Initializer
* @typedef {import('micromark-util-types').Resolver} Resolver
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
*/
import {codes, constants, types} from 'micromark-util-symbol'
import {ok as assert} from 'devlop'
export const resolver = {resolveAll: createResolver()}
export const string = initializeFactory('string')
export const text = initializeFactory('text')
/**
* @param {'string' | 'text'} field
* @returns {InitialConstruct}
*/
function initializeFactory(field) {
return {
tokenize: initializeText,
resolveAll: createResolver(
field === 'text' ? resolveAllLineSuffixes : undefined
)
}
/**
* @this {TokenizeContext}
* @type {Initializer}
*/
function initializeText(effects) {
const self = this
const constructs = this.parser.constructs[field]
const text = effects.attempt(constructs, start, notText)
return start
/** @type {State} */
function start(code) {
return atBreak(code) ? text(code) : notText(code)
}
/** @type {State} */
function notText(code) {
if (code === codes.eof) {
effects.consume(code)
return
}
effects.enter(types.data)
effects.consume(code)
return data
}
/** @type {State} */
function data(code) {
if (atBreak(code)) {
effects.exit(types.data)
return text(code)
}
// Data.
effects.consume(code)
return data
}
/**
* @param {Code} code
* @returns {boolean}
*/
function atBreak(code) {
if (code === codes.eof) {
return true
}
const list = constructs[code]
let index = -1
if (list) {
// Always populated by defaults.
assert(Array.isArray(list), 'expected `disable.null` to be populated')
while (++index < list.length) {
const item = list[index]
if (!item.previous || item.previous.call(self, self.previous)) {
return true
}
}
}
return false
}
}
}
/**
* @param {Resolver | undefined} [extraResolver]
* @returns {Resolver}
*/
function createResolver(extraResolver) {
return resolveAllText
/** @type {Resolver} */
function resolveAllText(events, context) {
let index = -1
/** @type {number | undefined} */
let enter
// A rather boring computation (to merge adjacent `data` events) which
// improves mm performance by 29%.
while (++index <= events.length) {
if (enter === undefined) {
if (events[index] && events[index][1].type === types.data) {
enter = index
index++
}
} else if (!events[index] || events[index][1].type !== types.data) {
// Dont do anything if there is one data token.
if (index !== enter + 2) {
events[enter][1].end = events[index - 1][1].end
events.splice(enter + 2, index - enter - 2)
index = enter + 2
}
enter = undefined
}
}
return extraResolver ? extraResolver(events, context) : events
}
}
/**
* A rather ugly set of instructions which again looks at chunks in the input
* stream.
* The reason to do this here is that it is *much* faster to parse in reverse.
* And that we cant hook into `null` to split the line suffix before an EOF.
* To do: figure out if we can make this into a clean utility, or even in core.
* As it will be useful for GFMs literal autolink extension (and maybe even
* tables?)
*
* @type {Resolver}
*/
function resolveAllLineSuffixes(events, context) {
let eventIndex = 0 // Skip first.
while (++eventIndex <= events.length) {
if (
(eventIndex === events.length ||
events[eventIndex][1].type === types.lineEnding) &&
events[eventIndex - 1][1].type === types.data
) {
const data = events[eventIndex - 1][1]
const chunks = context.sliceStream(data)
let index = chunks.length
let bufferIndex = -1
let size = 0
/** @type {boolean | undefined} */
let tabs
while (index--) {
const chunk = chunks[index]
if (typeof chunk === 'string') {
bufferIndex = chunk.length
while (chunk.charCodeAt(bufferIndex - 1) === codes.space) {
size++
bufferIndex--
}
if (bufferIndex) break
bufferIndex = -1
}
// Number
else if (chunk === codes.horizontalTab) {
tabs = true
size++
} else if (chunk === codes.virtualSpace) {
// Empty
} else {
// Replacement character, exit.
index++
break
}
}
if (size) {
const token = {
type:
eventIndex === events.length ||
tabs ||
size < constants.hardBreakPrefixSizeMin
? types.lineSuffix
: types.hardBreakTrailing,
start: {
line: data.end.line,
column: data.end.column - size,
offset: data.end.offset - size,
_index: data.start._index + index,
_bufferIndex: index
? bufferIndex
: data.start._bufferIndex + bufferIndex
},
end: Object.assign({}, data.end)
}
data.end = Object.assign({}, token.start)
if (data.start.offset === data.end.offset) {
Object.assign(data, token)
} else {
events.splice(
eventIndex,
0,
['enter', token, context],
['exit', token, context]
)
eventIndex += 2
}
}
eventIndex++
}
}
return events
}

11
node_modules/micromark/dev/lib/parse.d.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
/**
* @param {ParseOptions | null | undefined} [options]
* @returns {ParseContext}
*/
export function parse(options?: ParseOptions | null | undefined): ParseContext
export type Create = import('micromark-util-types').Create
export type FullNormalizedExtension =
import('micromark-util-types').FullNormalizedExtension
export type InitialConstruct = import('micromark-util-types').InitialConstruct
export type ParseContext = import('micromark-util-types').ParseContext
export type ParseOptions = import('micromark-util-types').ParseOptions

51
node_modules/micromark/dev/lib/parse.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
/**
* @typedef {import('micromark-util-types').Create} Create
* @typedef {import('micromark-util-types').FullNormalizedExtension} FullNormalizedExtension
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').ParseContext} ParseContext
* @typedef {import('micromark-util-types').ParseOptions} ParseOptions
*/
import {combineExtensions} from 'micromark-util-combine-extensions'
import {content} from './initialize/content.js'
import {document} from './initialize/document.js'
import {flow} from './initialize/flow.js'
import {string, text} from './initialize/text.js'
import {createTokenizer} from './create-tokenizer.js'
import * as defaultConstructs from './constructs.js'
/**
* @param {ParseOptions | null | undefined} [options]
* @returns {ParseContext}
*/
export function parse(options) {
const settings = options || {}
const constructs = /** @type {FullNormalizedExtension} */ (
combineExtensions([defaultConstructs, ...(settings.extensions || [])])
)
/** @type {ParseContext} */
const parser = {
defined: [],
lazy: {},
constructs,
content: create(content),
document: create(document),
flow: create(flow),
string: create(string),
text: create(text)
}
return parser
/**
* @param {InitialConstruct} initial
*/
function create(initial) {
return creator
/** @type {Create} */
function creator(from) {
return createTokenizer(parser, initial, from)
}
}
}

8
node_modules/micromark/dev/lib/postprocess.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
/**
* @param {Array<Event>} events
* @returns {Array<Event>}
*/
export function postprocess(
events: Array<import('micromark-util-types').Event>
): Array<import('micromark-util-types').Event>
export type Event = import('micromark-util-types').Event

17
node_modules/micromark/dev/lib/postprocess.js generated vendored Normal file
View File

@@ -0,0 +1,17 @@
/**
* @typedef {import('micromark-util-types').Event} Event
*/
import {subtokenize} from 'micromark-util-subtokenize'
/**
* @param {Array<Event>} events
* @returns {Array<Event>}
*/
export function postprocess(events) {
while (!subtokenize(events)) {
// Empty
}
return events
}

13
node_modules/micromark/dev/lib/preprocess.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
/**
* @returns {Preprocessor}
*/
export function preprocess(): Preprocessor
export type Chunk = import('micromark-util-types').Chunk
export type Code = import('micromark-util-types').Code
export type Encoding = import('micromark-util-types').Encoding
export type Value = import('micromark-util-types').Value
export type Preprocessor = (
value: Value,
encoding?: Encoding | null | undefined,
end?: boolean | null | undefined
) => Array<Chunk>

138
node_modules/micromark/dev/lib/preprocess.js generated vendored Normal file
View File

@@ -0,0 +1,138 @@
/**
* @typedef {import('micromark-util-types').Chunk} Chunk
* @typedef {import('micromark-util-types').Code} Code
* @typedef {import('micromark-util-types').Encoding} Encoding
* @typedef {import('micromark-util-types').Value} Value
*/
/**
* @callback Preprocessor
* @param {Value} value
* @param {Encoding | null | undefined} [encoding]
* @param {boolean | null | undefined} [end=false]
* @returns {Array<Chunk>}
*/
import {codes, constants} from 'micromark-util-symbol'
const search = /[\0\t\n\r]/g
/**
* @returns {Preprocessor}
*/
export function preprocess() {
let column = 1
let buffer = ''
/** @type {boolean | undefined} */
let start = true
/** @type {boolean | undefined} */
let atCarriageReturn
return preprocessor
/** @type {Preprocessor} */
// eslint-disable-next-line complexity
function preprocessor(value, encoding, end) {
/** @type {Array<Chunk>} */
const chunks = []
/** @type {RegExpMatchArray | null} */
let match
/** @type {number} */
let next
/** @type {number} */
let startPosition
/** @type {number} */
let endPosition
/** @type {Code} */
let code
value =
buffer +
(typeof value === 'string'
? value.toString()
: new TextDecoder(encoding || undefined).decode(value))
startPosition = 0
buffer = ''
if (start) {
// To do: `markdown-rs` actually parses BOMs (byte order mark).
if (value.charCodeAt(0) === codes.byteOrderMarker) {
startPosition++
}
start = undefined
}
while (startPosition < value.length) {
search.lastIndex = startPosition
match = search.exec(value)
endPosition =
match && match.index !== undefined ? match.index : value.length
code = value.charCodeAt(endPosition)
if (!match) {
buffer = value.slice(startPosition)
break
}
if (
code === codes.lf &&
startPosition === endPosition &&
atCarriageReturn
) {
chunks.push(codes.carriageReturnLineFeed)
atCarriageReturn = undefined
} else {
if (atCarriageReturn) {
chunks.push(codes.carriageReturn)
atCarriageReturn = undefined
}
if (startPosition < endPosition) {
chunks.push(value.slice(startPosition, endPosition))
column += endPosition - startPosition
}
switch (code) {
case codes.nul: {
chunks.push(codes.replacementCharacter)
column++
break
}
case codes.ht: {
next = Math.ceil(column / constants.tabSize) * constants.tabSize
chunks.push(codes.horizontalTab)
while (column++ < next) chunks.push(codes.virtualSpace)
break
}
case codes.lf: {
chunks.push(codes.lineFeed)
column = 1
break
}
default: {
atCarriageReturn = true
column = 1
}
}
}
startPosition = endPosition + 1
}
if (end) {
if (atCarriageReturn) chunks.push(codes.carriageReturn)
if (buffer) chunks.push(buffer)
chunks.push(codes.eof)
}
return chunks
}
}

37
node_modules/micromark/dev/stream.d.ts generated vendored Normal file
View File

@@ -0,0 +1,37 @@
/**
* Create a duplex (readable and writable) stream.
*
* Some of the work to parse markdown can be done streaming, but in the
* end buffering is required.
*
* micromark does not handle errors for you, so you must handle errors on whatever
* streams you pipe into it.
* As markdown does not know errors, `micromark` itself does not emit errors.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {MinimalDuplex}
* Duplex stream.
*/
export function stream(options?: Options | null | undefined): MinimalDuplex
export type Options = import('micromark-util-types').Options
export type Value = import('micromark-util-types').Value
export type Encoding = import('micromark-util-types').Encoding
/**
* Function called when write was successful.
*/
export type Callback = () => undefined
export type PipeOptions = {
end?: boolean | null | undefined
}
export type MinimalDuplex = Omit<
NodeJS.ReadableStream & NodeJS.WritableStream,
| 'isPaused'
| 'pause'
| 'read'
| 'resume'
| 'setEncoding'
| 'unpipe'
| 'unshift'
| 'wrap'
>

255
node_modules/micromark/dev/stream.js generated vendored Normal file
View File

@@ -0,0 +1,255 @@
/**
* @typedef {import('micromark-util-types').Options} Options
* @typedef {import('micromark-util-types').Value} Value
* @typedef {import('micromark-util-types').Encoding} Encoding
*/
/**
* @callback Callback
* Function called when write was successful.
* @returns {undefined}
* Nothing.
*
* @typedef PipeOptions
* @property {boolean | null | undefined} [end]
*
* @typedef {Omit<NodeJS.ReadableStream & NodeJS.WritableStream, 'isPaused' | 'pause' | 'read' | 'resume' | 'setEncoding' | 'unpipe' | 'unshift' | 'wrap'>} MinimalDuplex
*/
import {EventEmitter} from 'node:events'
import {compile} from './lib/compile.js'
import {parse} from './lib/parse.js'
import {postprocess} from './lib/postprocess.js'
import {preprocess} from './lib/preprocess.js'
/**
* Create a duplex (readable and writable) stream.
*
* Some of the work to parse markdown can be done streaming, but in the
* end buffering is required.
*
* micromark does not handle errors for you, so you must handle errors on whatever
* streams you pipe into it.
* As markdown does not know errors, `micromark` itself does not emit errors.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {MinimalDuplex}
* Duplex stream.
*/
export function stream(options) {
const prep = preprocess()
const tokenize = parse(options).document().write
const comp = compile(options)
/** @type {boolean} */
let ended
/** @type {MinimalDuplex} */
// @ts-expect-error `addListener` is fine.
const emitter = Object.assign(new EventEmitter(), {
end,
pipe,
readable: true,
writable: true,
write
})
return emitter
/**
* Write a chunk into memory.
*
* @overload
* @param {Value | null | undefined} [chunk]
* Slice of markdown to parse (`string` or `Uint8Array`).
* @param {Encoding | null | undefined} [encoding]
* Character encoding to understand `chunk` as when its a `Uint8Array`
* (`string`, default: `'utf8'`).
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
* Whether write was successful.
*
* @overload
* @param {Value | null | undefined} [chunk]
* Slice of markdown to parse (`string` or `Uint8Array`).
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
* Whether write was successful.
*
* @param {Value | null | undefined} [chunk]
* Slice of markdown to parse (`string` or `Uint8Array`).
* @param {Callback | Encoding | null | undefined} [encoding]
* Character encoding to understand `chunk` as when its a `Uint8Array`
* (`string`, default: `'utf8'`).
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
* Whether write was successful.
*/
function write(chunk, encoding, callback) {
if (typeof encoding === 'function') {
callback = encoding
encoding = undefined
}
if (ended) {
throw new Error('Did not expect `write` after `end`')
}
tokenize(prep(chunk || '', encoding))
if (callback) {
callback()
}
// Signal successful write.
return true
}
/**
* End the writing.
*
* Passes all arguments as a final `write`.
*
* @overload
* @param {Value | null | undefined} [chunk]
* Slice of markdown to parse (`string` or `Uint8Array`).
* @param {Encoding | null | undefined} [encoding]
* Character encoding to understand `chunk` as when its a `Uint8Array`
* (`string`, default: `'utf8'`).
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
* Whether write was successful.
*
* @overload
* @param {Value | null | undefined} [chunk]
* Slice of markdown to parse (`string` or `Uint8Array`).
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
* Whether write was successful.
*
* @overload
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
*
* @param {Callback | Value | null | undefined} [chunk]
* Slice of markdown to parse (`string` or `Uint8Array`).
* @param {Callback | Encoding | null | undefined} [encoding]
* Character encoding to understand `chunk` as when its a `Uint8Array`
* (`string`, default: `'utf8'`).
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
* Whether write was successful.
*/
function end(chunk, encoding, callback) {
if (typeof chunk === 'function') {
encoding = chunk
chunk = undefined
}
if (typeof encoding === 'function') {
callback = encoding
encoding = undefined
}
write(chunk, encoding, callback)
emitter.emit('data', comp(postprocess(tokenize(prep('', encoding, true)))))
emitter.emit('end')
ended = true
return true
}
/**
* Pipe the processor into a writable stream.
*
* Basically `Stream#pipe`, but inlined and simplified to keep the bundled
* size down.
* See: <https://github.com/nodejs/node/blob/43a5170/lib/internal/streams/legacy.js#L13>.
*
* @template {NodeJS.WritableStream} Stream
* @param {Stream} dest
* @param {PipeOptions | null | undefined} [options]
* @returns {Stream}
*/
function pipe(dest, options) {
emitter.on('data', ondata)
emitter.on('error', onerror)
emitter.on('end', cleanup)
emitter.on('close', cleanup)
// If the `end` option is not supplied, `dest.end()` will be
// called when the `end` or `close` events are received.
// @ts-expect-error `_isStdio` is available on `std{err,out}`
if (!dest._isStdio && (!options || options.end !== false)) {
emitter.on('end', onend)
}
dest.on('error', onerror)
dest.on('close', cleanup)
dest.emit('pipe', emitter)
return dest
/**
* End destination stream.
*
* @returns {undefined}
*/
function onend() {
if (dest.end) {
dest.end()
}
}
/**
* Handle data.
*
* @param {string} chunk
* @returns {undefined}
*/
function ondata(chunk) {
if (dest.writable) {
dest.write(chunk)
}
}
/**
* Clean listeners.
*
* @returns {undefined}
*/
function cleanup() {
emitter.removeListener('data', ondata)
emitter.removeListener('end', onend)
emitter.removeListener('error', onerror)
emitter.removeListener('end', cleanup)
emitter.removeListener('close', cleanup)
dest.removeListener('error', onerror)
dest.removeListener('close', cleanup)
}
/**
* Close dangling pipes and handle unheard errors.
*
* @param {Error | null | undefined} [error]
* @returns {undefined}
*/
function onerror(error) {
cleanup()
if (!emitter.listenerCount('error')) {
throw error // Unhandled stream error in pipe.
}
}
}
}

16
node_modules/micromark/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
export function micromark(
value: Value,
encoding: Encoding | null | undefined,
options?: Options | null | undefined
): string
export function micromark(
value: Value,
options?: Options | null | undefined
): string
export {compile} from './lib/compile.js'
export {parse} from './lib/parse.js'
export {postprocess} from './lib/postprocess.js'
export {preprocess} from './lib/preprocess.js'
export type Encoding = import('micromark-util-types').Encoding
export type Options = import('micromark-util-types').Options
export type Value = import('micromark-util-types').Value

62
node_modules/micromark/index.js generated vendored Normal file
View File

@@ -0,0 +1,62 @@
/**
* @typedef {import('micromark-util-types').Encoding} Encoding
* @typedef {import('micromark-util-types').Options} Options
* @typedef {import('micromark-util-types').Value} Value
*/
import {compile} from './lib/compile.js'
import {parse} from './lib/parse.js'
import {postprocess} from './lib/postprocess.js'
import {preprocess} from './lib/preprocess.js'
export {compile} from './lib/compile.js'
export {parse} from './lib/parse.js'
export {postprocess} from './lib/postprocess.js'
export {preprocess} from './lib/preprocess.js'
/**
* Compile markdown to HTML.
*
* > Note: which encodings are supported depends on the engine.
* > For info on Node.js, see:
* > <https://nodejs.org/api/util.html#whatwg-supported-encodings>.
*
* @overload
* @param {Value} value
* Markdown to parse (`string` or `Uint8Array`).
* @param {Encoding | null | undefined} encoding
* Character encoding to understand `value` as when its a `Uint8Array`
* (`string`, default: `'utf8'`).
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {string}
* Compiled HTML.
*
* @overload
* @param {Value} value
* Markdown to parse (`string` or `Uint8Array`).
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {string}
* Compiled HTML.
*
* @param {Value} value
* Markdown to parse (`string` or `Uint8Array`).
* @param {Encoding | Options | null | undefined} [encoding]
* Character encoding to understand `value` as when its a `Uint8Array`
* (`string`, default: `'utf8'`).
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {string}
* Compiled HTML.
*/
export function micromark(value, encoding, options) {
if (typeof encoding !== 'string') {
options = encoding
encoding = undefined
}
return compile(options)(
postprocess(
parse(options).document().write(preprocess()(value, encoding, true))
)
)
}

24
node_modules/micromark/lib/compile.d.ts generated vendored Normal file
View File

@@ -0,0 +1,24 @@
/**
* @param {CompileOptions | null | undefined} [options]
* @returns {Compile}
*/
export function compile(options?: CompileOptions | null | undefined): Compile
export type Compile = import('micromark-util-types').Compile
export type CompileContext = import('micromark-util-types').CompileContext
export type CompileData = import('micromark-util-types').CompileData
export type CompileOptions = import('micromark-util-types').CompileOptions
export type Definition = import('micromark-util-types').Definition
export type Event = import('micromark-util-types').Event
export type Handle = import('micromark-util-types').Handle
export type HtmlExtension = import('micromark-util-types').HtmlExtension
export type NormalizedHtmlExtension =
import('micromark-util-types').NormalizedHtmlExtension
export type Token = import('micromark-util-types').Token
export type Media = {
image?: boolean | undefined
labelId?: string | undefined
label?: string | undefined
referenceId?: string | undefined
destination?: string | undefined
title?: string | undefined
}

1109
node_modules/micromark/lib/compile.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

76
node_modules/micromark/lib/constructs.d.ts generated vendored Normal file
View File

@@ -0,0 +1,76 @@
/** @satisfies {Extension['document']} */
export const document: {
42: import('micromark-util-types').Construct
43: import('micromark-util-types').Construct
45: import('micromark-util-types').Construct
48: import('micromark-util-types').Construct
49: import('micromark-util-types').Construct
50: import('micromark-util-types').Construct
51: import('micromark-util-types').Construct
52: import('micromark-util-types').Construct
53: import('micromark-util-types').Construct
54: import('micromark-util-types').Construct
55: import('micromark-util-types').Construct
56: import('micromark-util-types').Construct
57: import('micromark-util-types').Construct
62: import('micromark-util-types').Construct
}
/** @satisfies {Extension['contentInitial']} */
export const contentInitial: {
91: import('micromark-util-types').Construct
}
/** @satisfies {Extension['flowInitial']} */
export const flowInitial: {
[-2]: import('micromark-util-types').Construct
[-1]: import('micromark-util-types').Construct
32: import('micromark-util-types').Construct
}
/** @satisfies {Extension['flow']} */
export const flow: {
35: import('micromark-util-types').Construct
42: import('micromark-util-types').Construct
45: import('micromark-util-types').Construct[]
60: import('micromark-util-types').Construct
61: import('micromark-util-types').Construct
95: import('micromark-util-types').Construct
96: import('micromark-util-types').Construct
126: import('micromark-util-types').Construct
}
/** @satisfies {Extension['string']} */
export const string: {
38: import('micromark-util-types').Construct
92: import('micromark-util-types').Construct
}
/** @satisfies {Extension['text']} */
export const text: {
[-5]: import('micromark-util-types').Construct
[-4]: import('micromark-util-types').Construct
[-3]: import('micromark-util-types').Construct
33: import('micromark-util-types').Construct
38: import('micromark-util-types').Construct
42: import('micromark-util-types').Construct
60: import('micromark-util-types').Construct[]
91: import('micromark-util-types').Construct
92: import('micromark-util-types').Construct[]
93: import('micromark-util-types').Construct
95: import('micromark-util-types').Construct
96: import('micromark-util-types').Construct
}
export namespace insideSpan {
let _null: (
| import('micromark-util-types').Construct
| {
resolveAll: import('micromark-util-types').Resolver
}
)[]
export {_null as null}
}
export namespace attentionMarkers {
let _null_1: (42 | 95)[]
export {_null_1 as null}
}
export namespace disable {
let _null_2: never[]
export {_null_2 as null}
}
export type Extension = import('micromark-util-types').Extension

106
node_modules/micromark/lib/constructs.js generated vendored Normal file
View File

@@ -0,0 +1,106 @@
/**
* @typedef {import('micromark-util-types').Extension} Extension
*/
import {
attention,
autolink,
blockQuote,
characterEscape,
characterReference,
codeFenced,
codeIndented,
codeText,
definition,
hardBreakEscape,
headingAtx,
htmlFlow,
htmlText,
labelEnd,
labelStartImage,
labelStartLink,
lineEnding,
list,
setextUnderline,
thematicBreak
} from 'micromark-core-commonmark'
import {resolver as resolveText} from './initialize/text.js'
/** @satisfies {Extension['document']} */
export const document = {
[42]: list,
[43]: list,
[45]: list,
[48]: list,
[49]: list,
[50]: list,
[51]: list,
[52]: list,
[53]: list,
[54]: list,
[55]: list,
[56]: list,
[57]: list,
[62]: blockQuote
}
/** @satisfies {Extension['contentInitial']} */
export const contentInitial = {
[91]: definition
}
/** @satisfies {Extension['flowInitial']} */
export const flowInitial = {
[-2]: codeIndented,
[-1]: codeIndented,
[32]: codeIndented
}
/** @satisfies {Extension['flow']} */
export const flow = {
[35]: headingAtx,
[42]: thematicBreak,
[45]: [setextUnderline, thematicBreak],
[60]: htmlFlow,
[61]: setextUnderline,
[95]: thematicBreak,
[96]: codeFenced,
[126]: codeFenced
}
/** @satisfies {Extension['string']} */
export const string = {
[38]: characterReference,
[92]: characterEscape
}
/** @satisfies {Extension['text']} */
export const text = {
[-5]: lineEnding,
[-4]: lineEnding,
[-3]: lineEnding,
[33]: labelStartImage,
[38]: characterReference,
[42]: attention,
[60]: [autolink, htmlText],
[91]: labelStartLink,
[92]: [hardBreakEscape, characterEscape],
[93]: labelEnd,
[95]: attention,
[96]: codeText
}
/** @satisfies {Extension['insideSpan']} */
export const insideSpan = {
null: [attention, resolveText]
}
/** @satisfies {Extension['attentionMarkers']} */
export const attentionMarkers = {
null: [42, 95]
}
/** @satisfies {Extension['disable']} */
export const disable = {
null: []
}

40
node_modules/micromark/lib/create-tokenizer.d.ts generated vendored Normal file
View File

@@ -0,0 +1,40 @@
/**
* Create a tokenizer.
* Tokenizers deal with one type of data (e.g., containers, flow, text).
* The parser is the object dealing with it all.
* `initialize` works like other constructs, except that only its `tokenize`
* function is used, in which case it doesnt receive an `ok` or `nok`.
* `from` can be given to set the point before the first character, although
* when further lines are indented, they must be set with `defineSkip`.
*
* @param {ParseContext} parser
* @param {InitialConstruct} initialize
* @param {Omit<Point, '_bufferIndex' | '_index'> | undefined} [from]
* @returns {TokenizeContext}
*/
export function createTokenizer(
parser: ParseContext,
initialize: InitialConstruct,
from?: Omit<Point, '_bufferIndex' | '_index'> | undefined
): TokenizeContext
export type Chunk = import('micromark-util-types').Chunk
export type Code = import('micromark-util-types').Code
export type Construct = import('micromark-util-types').Construct
export type ConstructRecord = import('micromark-util-types').ConstructRecord
export type Effects = import('micromark-util-types').Effects
export type InitialConstruct = import('micromark-util-types').InitialConstruct
export type ParseContext = import('micromark-util-types').ParseContext
export type Point = import('micromark-util-types').Point
export type State = import('micromark-util-types').State
export type Token = import('micromark-util-types').Token
export type TokenType = import('micromark-util-types').TokenType
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Restore = () => undefined
export type Info = {
restore: Restore
from: number
}
/**
* Handle a successful run.
*/
export type ReturnHandle = (construct: Construct, info: Info) => undefined

582
node_modules/micromark/lib/create-tokenizer.js generated vendored Normal file
View File

@@ -0,0 +1,582 @@
/**
* @typedef {import('micromark-util-types').Chunk} Chunk
* @typedef {import('micromark-util-types').Code} Code
* @typedef {import('micromark-util-types').Construct} Construct
* @typedef {import('micromark-util-types').ConstructRecord} ConstructRecord
* @typedef {import('micromark-util-types').Effects} Effects
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').ParseContext} ParseContext
* @typedef {import('micromark-util-types').Point} Point
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').TokenType} TokenType
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
*/
/**
* @callback Restore
* @returns {undefined}
*
* @typedef Info
* @property {Restore} restore
* @property {number} from
*
* @callback ReturnHandle
* Handle a successful run.
* @param {Construct} construct
* @param {Info} info
* @returns {undefined}
*/
import {markdownLineEnding} from 'micromark-util-character'
import {push, splice} from 'micromark-util-chunked'
import {resolveAll} from 'micromark-util-resolve-all'
/**
* Create a tokenizer.
* Tokenizers deal with one type of data (e.g., containers, flow, text).
* The parser is the object dealing with it all.
* `initialize` works like other constructs, except that only its `tokenize`
* function is used, in which case it doesnt receive an `ok` or `nok`.
* `from` can be given to set the point before the first character, although
* when further lines are indented, they must be set with `defineSkip`.
*
* @param {ParseContext} parser
* @param {InitialConstruct} initialize
* @param {Omit<Point, '_bufferIndex' | '_index'> | undefined} [from]
* @returns {TokenizeContext}
*/
export function createTokenizer(parser, initialize, from) {
/** @type {Point} */
let point = Object.assign(
from
? Object.assign({}, from)
: {
line: 1,
column: 1,
offset: 0
},
{
_index: 0,
_bufferIndex: -1
}
)
/** @type {Record<string, number>} */
const columnStart = {}
/** @type {Array<Construct>} */
const resolveAllConstructs = []
/** @type {Array<Chunk>} */
let chunks = []
/** @type {Array<Token>} */
let stack = []
/** @type {boolean | undefined} */
let consumed = true
/**
* Tools used for tokenizing.
*
* @type {Effects}
*/
const effects = {
consume,
enter,
exit,
attempt: constructFactory(onsuccessfulconstruct),
check: constructFactory(onsuccessfulcheck),
interrupt: constructFactory(onsuccessfulcheck, {
interrupt: true
})
}
/**
* State and tools for resolving and serializing.
*
* @type {TokenizeContext}
*/
const context = {
previous: null,
code: null,
containerState: {},
events: [],
parser,
sliceStream,
sliceSerialize,
now,
defineSkip,
write
}
/**
* The state function.
*
* @type {State | undefined}
*/
let state = initialize.tokenize.call(context, effects)
/**
* Track which character we expect to be consumed, to catch bugs.
*
* @type {Code}
*/
let expectedCode
if (initialize.resolveAll) {
resolveAllConstructs.push(initialize)
}
return context
/** @type {TokenizeContext['write']} */
function write(slice) {
chunks = push(chunks, slice)
main()
// Exit if were not done, resolve might change stuff.
if (chunks[chunks.length - 1] !== null) {
return []
}
addResult(initialize, 0)
// Otherwise, resolve, and exit.
context.events = resolveAll(resolveAllConstructs, context.events, context)
return context.events
}
//
// Tools.
//
/** @type {TokenizeContext['sliceSerialize']} */
function sliceSerialize(token, expandTabs) {
return serializeChunks(sliceStream(token), expandTabs)
}
/** @type {TokenizeContext['sliceStream']} */
function sliceStream(token) {
return sliceChunks(chunks, token)
}
/** @type {TokenizeContext['now']} */
function now() {
// This is a hot path, so we clone manually instead of `Object.assign({}, point)`
const {line, column, offset, _index, _bufferIndex} = point
return {
line,
column,
offset,
_index,
_bufferIndex
}
}
/** @type {TokenizeContext['defineSkip']} */
function defineSkip(value) {
columnStart[value.line] = value.column
accountForPotentialSkip()
}
//
// State management.
//
/**
* Main loop (note that `_index` and `_bufferIndex` in `point` are modified by
* `consume`).
* Here is where we walk through the chunks, which either include strings of
* several characters, or numerical character codes.
* The reason to do this in a loop instead of a call is so the stack can
* drain.
*
* @returns {undefined}
*/
function main() {
/** @type {number} */
let chunkIndex
while (point._index < chunks.length) {
const chunk = chunks[point._index]
// If were in a buffer chunk, loop through it.
if (typeof chunk === 'string') {
chunkIndex = point._index
if (point._bufferIndex < 0) {
point._bufferIndex = 0
}
while (
point._index === chunkIndex &&
point._bufferIndex < chunk.length
) {
go(chunk.charCodeAt(point._bufferIndex))
}
} else {
go(chunk)
}
}
}
/**
* Deal with one code.
*
* @param {Code} code
* @returns {undefined}
*/
function go(code) {
consumed = undefined
expectedCode = code
state = state(code)
}
/** @type {Effects['consume']} */
function consume(code) {
if (markdownLineEnding(code)) {
point.line++
point.column = 1
point.offset += code === -3 ? 2 : 1
accountForPotentialSkip()
} else if (code !== -1) {
point.column++
point.offset++
}
// Not in a string chunk.
if (point._bufferIndex < 0) {
point._index++
} else {
point._bufferIndex++
// At end of string chunk.
// @ts-expect-error Points w/ non-negative `_bufferIndex` reference
// strings.
if (point._bufferIndex === chunks[point._index].length) {
point._bufferIndex = -1
point._index++
}
}
// Expose the previous character.
context.previous = code
// Mark as consumed.
consumed = true
}
/** @type {Effects['enter']} */
function enter(type, fields) {
/** @type {Token} */
// @ts-expect-error Patch instead of assign required fields to help GC.
const token = fields || {}
token.type = type
token.start = now()
context.events.push(['enter', token, context])
stack.push(token)
return token
}
/** @type {Effects['exit']} */
function exit(type) {
const token = stack.pop()
token.end = now()
context.events.push(['exit', token, context])
return token
}
/**
* Use results.
*
* @type {ReturnHandle}
*/
function onsuccessfulconstruct(construct, info) {
addResult(construct, info.from)
}
/**
* Discard results.
*
* @type {ReturnHandle}
*/
function onsuccessfulcheck(_, info) {
info.restore()
}
/**
* Factory to attempt/check/interrupt.
*
* @param {ReturnHandle} onreturn
* @param {{interrupt?: boolean | undefined} | undefined} [fields]
*/
function constructFactory(onreturn, fields) {
return hook
/**
* Handle either an object mapping codes to constructs, a list of
* constructs, or a single construct.
*
* @param {Array<Construct> | Construct | ConstructRecord} constructs
* @param {State} returnState
* @param {State | undefined} [bogusState]
* @returns {State}
*/
function hook(constructs, returnState, bogusState) {
/** @type {Array<Construct>} */
let listOfConstructs
/** @type {number} */
let constructIndex
/** @type {Construct} */
let currentConstruct
/** @type {Info} */
let info
return Array.isArray(constructs) /* c8 ignore next 1 */
? handleListOfConstructs(constructs)
: 'tokenize' in constructs
? // @ts-expect-error Looks like a construct.
handleListOfConstructs([constructs])
: handleMapOfConstructs(constructs)
/**
* Handle a list of construct.
*
* @param {ConstructRecord} map
* @returns {State}
*/
function handleMapOfConstructs(map) {
return start
/** @type {State} */
function start(code) {
const def = code !== null && map[code]
const all = code !== null && map.null
const list = [
// To do: add more extension tests.
/* c8 ignore next 2 */
...(Array.isArray(def) ? def : def ? [def] : []),
...(Array.isArray(all) ? all : all ? [all] : [])
]
return handleListOfConstructs(list)(code)
}
}
/**
* Handle a list of construct.
*
* @param {Array<Construct>} list
* @returns {State}
*/
function handleListOfConstructs(list) {
listOfConstructs = list
constructIndex = 0
if (list.length === 0) {
return bogusState
}
return handleConstruct(list[constructIndex])
}
/**
* Handle a single construct.
*
* @param {Construct} construct
* @returns {State}
*/
function handleConstruct(construct) {
return start
/** @type {State} */
function start(code) {
// To do: not needed to store if there is no bogus state, probably?
// Currently doesnt work because `inspect` in document does a check
// w/o a bogus, which doesnt make sense. But it does seem to help perf
// by not storing.
info = store()
currentConstruct = construct
if (!construct.partial) {
context.currentConstruct = construct
}
// Always populated by defaults.
if (
construct.name &&
context.parser.constructs.disable.null.includes(construct.name)
) {
return nok(code)
}
return construct.tokenize.call(
// If we do have fields, create an object w/ `context` as its
// prototype.
// This allows a “live binding”, which is needed for `interrupt`.
fields ? Object.assign(Object.create(context), fields) : context,
effects,
ok,
nok
)(code)
}
}
/** @type {State} */
function ok(code) {
consumed = true
onreturn(currentConstruct, info)
return returnState
}
/** @type {State} */
function nok(code) {
consumed = true
info.restore()
if (++constructIndex < listOfConstructs.length) {
return handleConstruct(listOfConstructs[constructIndex])
}
return bogusState
}
}
}
/**
* @param {Construct} construct
* @param {number} from
* @returns {undefined}
*/
function addResult(construct, from) {
if (construct.resolveAll && !resolveAllConstructs.includes(construct)) {
resolveAllConstructs.push(construct)
}
if (construct.resolve) {
splice(
context.events,
from,
context.events.length - from,
construct.resolve(context.events.slice(from), context)
)
}
if (construct.resolveTo) {
context.events = construct.resolveTo(context.events, context)
}
}
/**
* Store state.
*
* @returns {Info}
*/
function store() {
const startPoint = now()
const startPrevious = context.previous
const startCurrentConstruct = context.currentConstruct
const startEventsIndex = context.events.length
const startStack = Array.from(stack)
return {
restore,
from: startEventsIndex
}
/**
* Restore state.
*
* @returns {undefined}
*/
function restore() {
point = startPoint
context.previous = startPrevious
context.currentConstruct = startCurrentConstruct
context.events.length = startEventsIndex
stack = startStack
accountForPotentialSkip()
}
}
/**
* Move the current point a bit forward in the line when its on a column
* skip.
*
* @returns {undefined}
*/
function accountForPotentialSkip() {
if (point.line in columnStart && point.column < 2) {
point.column = columnStart[point.line]
point.offset += columnStart[point.line] - 1
}
}
}
/**
* Get the chunks from a slice of chunks in the range of a token.
*
* @param {Array<Chunk>} chunks
* @param {Pick<Token, 'end' | 'start'>} token
* @returns {Array<Chunk>}
*/
function sliceChunks(chunks, token) {
const startIndex = token.start._index
const startBufferIndex = token.start._bufferIndex
const endIndex = token.end._index
const endBufferIndex = token.end._bufferIndex
/** @type {Array<Chunk>} */
let view
if (startIndex === endIndex) {
// @ts-expect-error `_bufferIndex` is used on string chunks.
view = [chunks[startIndex].slice(startBufferIndex, endBufferIndex)]
} else {
view = chunks.slice(startIndex, endIndex)
if (startBufferIndex > -1) {
const head = view[0]
if (typeof head === 'string') {
view[0] = head.slice(startBufferIndex)
} else {
view.shift()
}
}
if (endBufferIndex > 0) {
// @ts-expect-error `_bufferIndex` is used on string chunks.
view.push(chunks[endIndex].slice(0, endBufferIndex))
}
}
return view
}
/**
* Get the string value of a slice of chunks.
*
* @param {Array<Chunk>} chunks
* @param {boolean | undefined} [expandTabs=false]
* @returns {string}
*/
function serializeChunks(chunks, expandTabs) {
let index = -1
/** @type {Array<string>} */
const result = []
/** @type {boolean | undefined} */
let atTab
while (++index < chunks.length) {
const chunk = chunks[index]
/** @type {string} */
let value
if (typeof chunk === 'string') {
value = chunk
} else
switch (chunk) {
case -5: {
value = '\r'
break
}
case -4: {
value = '\n'
break
}
case -3: {
value = '\r' + '\n'
break
}
case -2: {
value = expandTabs ? ' ' : '\t'
break
}
case -1: {
if (!expandTabs && atTab) continue
value = ' '
break
}
default: {
// Currently only replacement character.
value = String.fromCharCode(chunk)
}
}
atTab = chunk === -2
result.push(value)
}
return result.join('')
}

7
node_modules/micromark/lib/initialize/content.d.ts generated vendored Normal file
View File

@@ -0,0 +1,7 @@
/** @type {InitialConstruct} */
export const content: InitialConstruct
export type InitialConstruct = import('micromark-util-types').InitialConstruct
export type Initializer = import('micromark-util-types').Initializer
export type State = import('micromark-util-types').State
export type Token = import('micromark-util-types').Token
export type TokenizeContext = import('micromark-util-types').TokenizeContext

79
node_modules/micromark/lib/initialize/content.js generated vendored Normal file
View File

@@ -0,0 +1,79 @@
/**
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').Initializer} Initializer
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
*/
import {factorySpace} from 'micromark-factory-space'
import {markdownLineEnding} from 'micromark-util-character'
/** @type {InitialConstruct} */
export const content = {
tokenize: initializeContent
}
/**
* @this {TokenizeContext}
* @type {Initializer}
*/
function initializeContent(effects) {
const contentStart = effects.attempt(
this.parser.constructs.contentInitial,
afterContentStartConstruct,
paragraphInitial
)
/** @type {Token} */
let previous
return contentStart
/** @type {State} */
function afterContentStartConstruct(code) {
if (code === null) {
effects.consume(code)
return
}
effects.enter('lineEnding')
effects.consume(code)
effects.exit('lineEnding')
return factorySpace(effects, contentStart, 'linePrefix')
}
/** @type {State} */
function paragraphInitial(code) {
effects.enter('paragraph')
return lineStart(code)
}
/** @type {State} */
function lineStart(code) {
const token = effects.enter('chunkText', {
contentType: 'text',
previous
})
if (previous) {
previous.next = token
}
previous = token
return data(code)
}
/** @type {State} */
function data(code) {
if (code === null) {
effects.exit('chunkText')
effects.exit('paragraph')
effects.consume(code)
return
}
if (markdownLineEnding(code)) {
effects.consume(code)
effects.exit('chunkText')
return lineStart
}
// Data.
effects.consume(code)
return data
}
}

12
node_modules/micromark/lib/initialize/document.d.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
/** @type {InitialConstruct} */
export const document: InitialConstruct
export type Construct = import('micromark-util-types').Construct
export type ContainerState = import('micromark-util-types').ContainerState
export type InitialConstruct = import('micromark-util-types').InitialConstruct
export type Initializer = import('micromark-util-types').Initializer
export type Point = import('micromark-util-types').Point
export type State = import('micromark-util-types').State
export type Token = import('micromark-util-types').Token
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Tokenizer = import('micromark-util-types').Tokenizer
export type StackItem = [Construct, ContainerState]

382
node_modules/micromark/lib/initialize/document.js generated vendored Normal file
View File

@@ -0,0 +1,382 @@
/**
* @typedef {import('micromark-util-types').Construct} Construct
* @typedef {import('micromark-util-types').ContainerState} ContainerState
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').Initializer} Initializer
* @typedef {import('micromark-util-types').Point} Point
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
*/
/**
* @typedef {[Construct, ContainerState]} StackItem
*/
import {factorySpace} from 'micromark-factory-space'
import {markdownLineEnding} from 'micromark-util-character'
import {splice} from 'micromark-util-chunked'
/** @type {InitialConstruct} */
export const document = {
tokenize: initializeDocument
}
/** @type {Construct} */
const containerConstruct = {
tokenize: tokenizeContainer
}
/**
* @this {TokenizeContext}
* @type {Initializer}
*/
function initializeDocument(effects) {
const self = this
/** @type {Array<StackItem>} */
const stack = []
let continued = 0
/** @type {TokenizeContext | undefined} */
let childFlow
/** @type {Token | undefined} */
let childToken
/** @type {number} */
let lineStartOffset
return start
/** @type {State} */
function start(code) {
// First we iterate through the open blocks, starting with the root
// document, and descending through last children down to the last open
// block.
// Each block imposes a condition that the line must satisfy if the block is
// to remain open.
// For example, a block quote requires a `>` character.
// A paragraph requires a non-blank line.
// In this phase we may match all or just some of the open blocks.
// But we cannot close unmatched blocks yet, because we may have a lazy
// continuation line.
if (continued < stack.length) {
const item = stack[continued]
self.containerState = item[1]
return effects.attempt(
item[0].continuation,
documentContinue,
checkNewContainers
)(code)
}
// Done.
return checkNewContainers(code)
}
/** @type {State} */
function documentContinue(code) {
continued++
// Note: this field is called `_closeFlow` but it also closes containers.
// Perhaps a good idea to rename it but its already used in the wild by
// extensions.
if (self.containerState._closeFlow) {
self.containerState._closeFlow = undefined
if (childFlow) {
closeFlow()
}
// Note: this algorithm for moving events around is similar to the
// algorithm when dealing with lazy lines in `writeToChild`.
const indexBeforeExits = self.events.length
let indexBeforeFlow = indexBeforeExits
/** @type {Point | undefined} */
let point
// Find the flow chunk.
while (indexBeforeFlow--) {
if (
self.events[indexBeforeFlow][0] === 'exit' &&
self.events[indexBeforeFlow][1].type === 'chunkFlow'
) {
point = self.events[indexBeforeFlow][1].end
break
}
}
exitContainers(continued)
// Fix positions.
let index = indexBeforeExits
while (index < self.events.length) {
self.events[index][1].end = Object.assign({}, point)
index++
}
// Inject the exits earlier (theyre still also at the end).
splice(
self.events,
indexBeforeFlow + 1,
0,
self.events.slice(indexBeforeExits)
)
// Discard the duplicate exits.
self.events.length = index
return checkNewContainers(code)
}
return start(code)
}
/** @type {State} */
function checkNewContainers(code) {
// Next, after consuming the continuation markers for existing blocks, we
// look for new block starts (e.g. `>` for a block quote).
// If we encounter a new block start, we close any blocks unmatched in
// step 1 before creating the new block as a child of the last matched
// block.
if (continued === stack.length) {
// No need to `check` whether theres a container, of `exitContainers`
// would be moot.
// We can instead immediately `attempt` to parse one.
if (!childFlow) {
return documentContinued(code)
}
// If we have concrete content, such as block HTML or fenced code,
// we cant have containers “pierce” into them, so we can immediately
// start.
if (childFlow.currentConstruct && childFlow.currentConstruct.concrete) {
return flowStart(code)
}
// If we do have flow, it could still be a blank line,
// but wed be interrupting it w/ a new container if theres a current
// construct.
// To do: next major: remove `_gfmTableDynamicInterruptHack` (no longer
// needed in micromark-extension-gfm-table@1.0.6).
self.interrupt = Boolean(
childFlow.currentConstruct && !childFlow._gfmTableDynamicInterruptHack
)
}
// Check if there is a new container.
self.containerState = {}
return effects.check(
containerConstruct,
thereIsANewContainer,
thereIsNoNewContainer
)(code)
}
/** @type {State} */
function thereIsANewContainer(code) {
if (childFlow) closeFlow()
exitContainers(continued)
return documentContinued(code)
}
/** @type {State} */
function thereIsNoNewContainer(code) {
self.parser.lazy[self.now().line] = continued !== stack.length
lineStartOffset = self.now().offset
return flowStart(code)
}
/** @type {State} */
function documentContinued(code) {
// Try new containers.
self.containerState = {}
return effects.attempt(
containerConstruct,
containerContinue,
flowStart
)(code)
}
/** @type {State} */
function containerContinue(code) {
continued++
stack.push([self.currentConstruct, self.containerState])
// Try another.
return documentContinued(code)
}
/** @type {State} */
function flowStart(code) {
if (code === null) {
if (childFlow) closeFlow()
exitContainers(0)
effects.consume(code)
return
}
childFlow = childFlow || self.parser.flow(self.now())
effects.enter('chunkFlow', {
contentType: 'flow',
previous: childToken,
_tokenizer: childFlow
})
return flowContinue(code)
}
/** @type {State} */
function flowContinue(code) {
if (code === null) {
writeToChild(effects.exit('chunkFlow'), true)
exitContainers(0)
effects.consume(code)
return
}
if (markdownLineEnding(code)) {
effects.consume(code)
writeToChild(effects.exit('chunkFlow'))
// Get ready for the next line.
continued = 0
self.interrupt = undefined
return start
}
effects.consume(code)
return flowContinue
}
/**
* @param {Token} token
* @param {boolean | undefined} [eof]
* @returns {undefined}
*/
function writeToChild(token, eof) {
const stream = self.sliceStream(token)
if (eof) stream.push(null)
token.previous = childToken
if (childToken) childToken.next = token
childToken = token
childFlow.defineSkip(token.start)
childFlow.write(stream)
// Alright, so we just added a lazy line:
//
// ```markdown
// > a
// b.
//
// Or:
//
// > ~~~c
// d
//
// Or:
//
// > | e |
// f
// ```
//
// The construct in the second example (fenced code) does not accept lazy
// lines, so it marked itself as done at the end of its first line, and
// then the content construct parses `d`.
// Most constructs in markdown match on the first line: if the first line
// forms a construct, a non-lazy line cant “unmake” it.
//
// The construct in the third example is potentially a GFM table, and
// those are *weird*.
// It *could* be a table, from the first line, if the following line
// matches a condition.
// In this case, that second line is lazy, which “unmakes” the first line
// and turns the whole into one content block.
//
// Weve now parsed the non-lazy and the lazy line, and can figure out
// whether the lazy line started a new flow block.
// If it did, we exit the current containers between the two flow blocks.
if (self.parser.lazy[token.start.line]) {
let index = childFlow.events.length
while (index--) {
if (
// The token starts before the line ending…
childFlow.events[index][1].start.offset < lineStartOffset &&
// …and either is not ended yet…
(!childFlow.events[index][1].end ||
// …or ends after it.
childFlow.events[index][1].end.offset > lineStartOffset)
) {
// Exit: theres still something open, which means its a lazy line
// part of something.
return
}
}
// Note: this algorithm for moving events around is similar to the
// algorithm when closing flow in `documentContinue`.
const indexBeforeExits = self.events.length
let indexBeforeFlow = indexBeforeExits
/** @type {boolean | undefined} */
let seen
/** @type {Point | undefined} */
let point
// Find the previous chunk (the one before the lazy line).
while (indexBeforeFlow--) {
if (
self.events[indexBeforeFlow][0] === 'exit' &&
self.events[indexBeforeFlow][1].type === 'chunkFlow'
) {
if (seen) {
point = self.events[indexBeforeFlow][1].end
break
}
seen = true
}
}
exitContainers(continued)
// Fix positions.
index = indexBeforeExits
while (index < self.events.length) {
self.events[index][1].end = Object.assign({}, point)
index++
}
// Inject the exits earlier (theyre still also at the end).
splice(
self.events,
indexBeforeFlow + 1,
0,
self.events.slice(indexBeforeExits)
)
// Discard the duplicate exits.
self.events.length = index
}
}
/**
* @param {number} size
* @returns {undefined}
*/
function exitContainers(size) {
let index = stack.length
// Exit open containers.
while (index-- > size) {
const entry = stack[index]
self.containerState = entry[1]
entry[0].exit.call(self, effects)
}
stack.length = size
}
function closeFlow() {
childFlow.write([null])
childToken = undefined
childFlow = undefined
self.containerState._closeFlow = undefined
}
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeContainer(effects, ok, nok) {
// Always populated by defaults.
return factorySpace(
effects,
effects.attempt(this.parser.constructs.document, ok, nok),
'linePrefix',
this.parser.constructs.disable.null.includes('codeIndented') ? undefined : 4
)
}

6
node_modules/micromark/lib/initialize/flow.d.ts generated vendored Normal file
View File

@@ -0,0 +1,6 @@
/** @type {InitialConstruct} */
export const flow: InitialConstruct
export type InitialConstruct = import('micromark-util-types').InitialConstruct
export type Initializer = import('micromark-util-types').Initializer
export type State = import('micromark-util-types').State
export type TokenizeContext = import('micromark-util-types').TokenizeContext

68
node_modules/micromark/lib/initialize/flow.js generated vendored Normal file
View File

@@ -0,0 +1,68 @@
/**
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').Initializer} Initializer
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
*/
import {blankLine, content} from 'micromark-core-commonmark'
import {factorySpace} from 'micromark-factory-space'
import {markdownLineEnding} from 'micromark-util-character'
/** @type {InitialConstruct} */
export const flow = {
tokenize: initializeFlow
}
/**
* @this {TokenizeContext}
* @type {Initializer}
*/
function initializeFlow(effects) {
const self = this
const initial = effects.attempt(
// Try to parse a blank line.
blankLine,
atBlankEnding,
// Try to parse initial flow (essentially, only code).
effects.attempt(
this.parser.constructs.flowInitial,
afterConstruct,
factorySpace(
effects,
effects.attempt(
this.parser.constructs.flow,
afterConstruct,
effects.attempt(content, afterConstruct)
),
'linePrefix'
)
)
)
return initial
/** @type {State} */
function atBlankEnding(code) {
if (code === null) {
effects.consume(code)
return
}
effects.enter('lineEndingBlank')
effects.consume(code)
effects.exit('lineEndingBlank')
self.currentConstruct = undefined
return initial
}
/** @type {State} */
function afterConstruct(code) {
if (code === null) {
effects.consume(code)
return
}
effects.enter('lineEnding')
effects.consume(code)
effects.exit('lineEnding')
self.currentConstruct = undefined
return initial
}
}

11
node_modules/micromark/lib/initialize/text.d.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
export namespace resolver {
let resolveAll: import('micromark-util-types').Resolver
}
export const string: import('micromark-util-types').InitialConstruct
export const text: import('micromark-util-types').InitialConstruct
export type Code = import('micromark-util-types').Code
export type InitialConstruct = import('micromark-util-types').InitialConstruct
export type Initializer = import('micromark-util-types').Initializer
export type Resolver = import('micromark-util-types').Resolver
export type State = import('micromark-util-types').State
export type TokenizeContext = import('micromark-util-types').TokenizeContext

210
node_modules/micromark/lib/initialize/text.js generated vendored Normal file
View File

@@ -0,0 +1,210 @@
/**
* @typedef {import('micromark-util-types').Code} Code
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').Initializer} Initializer
* @typedef {import('micromark-util-types').Resolver} Resolver
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
*/
export const resolver = {
resolveAll: createResolver()
}
export const string = initializeFactory('string')
export const text = initializeFactory('text')
/**
* @param {'string' | 'text'} field
* @returns {InitialConstruct}
*/
function initializeFactory(field) {
return {
tokenize: initializeText,
resolveAll: createResolver(
field === 'text' ? resolveAllLineSuffixes : undefined
)
}
/**
* @this {TokenizeContext}
* @type {Initializer}
*/
function initializeText(effects) {
const self = this
const constructs = this.parser.constructs[field]
const text = effects.attempt(constructs, start, notText)
return start
/** @type {State} */
function start(code) {
return atBreak(code) ? text(code) : notText(code)
}
/** @type {State} */
function notText(code) {
if (code === null) {
effects.consume(code)
return
}
effects.enter('data')
effects.consume(code)
return data
}
/** @type {State} */
function data(code) {
if (atBreak(code)) {
effects.exit('data')
return text(code)
}
// Data.
effects.consume(code)
return data
}
/**
* @param {Code} code
* @returns {boolean}
*/
function atBreak(code) {
if (code === null) {
return true
}
const list = constructs[code]
let index = -1
if (list) {
// Always populated by defaults.
while (++index < list.length) {
const item = list[index]
if (!item.previous || item.previous.call(self, self.previous)) {
return true
}
}
}
return false
}
}
}
/**
* @param {Resolver | undefined} [extraResolver]
* @returns {Resolver}
*/
function createResolver(extraResolver) {
return resolveAllText
/** @type {Resolver} */
function resolveAllText(events, context) {
let index = -1
/** @type {number | undefined} */
let enter
// A rather boring computation (to merge adjacent `data` events) which
// improves mm performance by 29%.
while (++index <= events.length) {
if (enter === undefined) {
if (events[index] && events[index][1].type === 'data') {
enter = index
index++
}
} else if (!events[index] || events[index][1].type !== 'data') {
// Dont do anything if there is one data token.
if (index !== enter + 2) {
events[enter][1].end = events[index - 1][1].end
events.splice(enter + 2, index - enter - 2)
index = enter + 2
}
enter = undefined
}
}
return extraResolver ? extraResolver(events, context) : events
}
}
/**
* A rather ugly set of instructions which again looks at chunks in the input
* stream.
* The reason to do this here is that it is *much* faster to parse in reverse.
* And that we cant hook into `null` to split the line suffix before an EOF.
* To do: figure out if we can make this into a clean utility, or even in core.
* As it will be useful for GFMs literal autolink extension (and maybe even
* tables?)
*
* @type {Resolver}
*/
function resolveAllLineSuffixes(events, context) {
let eventIndex = 0 // Skip first.
while (++eventIndex <= events.length) {
if (
(eventIndex === events.length ||
events[eventIndex][1].type === 'lineEnding') &&
events[eventIndex - 1][1].type === 'data'
) {
const data = events[eventIndex - 1][1]
const chunks = context.sliceStream(data)
let index = chunks.length
let bufferIndex = -1
let size = 0
/** @type {boolean | undefined} */
let tabs
while (index--) {
const chunk = chunks[index]
if (typeof chunk === 'string') {
bufferIndex = chunk.length
while (chunk.charCodeAt(bufferIndex - 1) === 32) {
size++
bufferIndex--
}
if (bufferIndex) break
bufferIndex = -1
}
// Number
else if (chunk === -2) {
tabs = true
size++
} else if (chunk === -1) {
// Empty
} else {
// Replacement character, exit.
index++
break
}
}
if (size) {
const token = {
type:
eventIndex === events.length || tabs || size < 2
? 'lineSuffix'
: 'hardBreakTrailing',
start: {
line: data.end.line,
column: data.end.column - size,
offset: data.end.offset - size,
_index: data.start._index + index,
_bufferIndex: index
? bufferIndex
: data.start._bufferIndex + bufferIndex
},
end: Object.assign({}, data.end)
}
data.end = Object.assign({}, token.start)
if (data.start.offset === data.end.offset) {
Object.assign(data, token)
} else {
events.splice(
eventIndex,
0,
['enter', token, context],
['exit', token, context]
)
eventIndex += 2
}
}
eventIndex++
}
}
return events
}

11
node_modules/micromark/lib/parse.d.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
/**
* @param {ParseOptions | null | undefined} [options]
* @returns {ParseContext}
*/
export function parse(options?: ParseOptions | null | undefined): ParseContext
export type Create = import('micromark-util-types').Create
export type FullNormalizedExtension =
import('micromark-util-types').FullNormalizedExtension
export type InitialConstruct = import('micromark-util-types').InitialConstruct
export type ParseContext = import('micromark-util-types').ParseContext
export type ParseOptions = import('micromark-util-types').ParseOptions

50
node_modules/micromark/lib/parse.js generated vendored Normal file
View File

@@ -0,0 +1,50 @@
/**
* @typedef {import('micromark-util-types').Create} Create
* @typedef {import('micromark-util-types').FullNormalizedExtension} FullNormalizedExtension
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').ParseContext} ParseContext
* @typedef {import('micromark-util-types').ParseOptions} ParseOptions
*/
import {combineExtensions} from 'micromark-util-combine-extensions'
import {content} from './initialize/content.js'
import {document} from './initialize/document.js'
import {flow} from './initialize/flow.js'
import {string, text} from './initialize/text.js'
import {createTokenizer} from './create-tokenizer.js'
import * as defaultConstructs from './constructs.js'
/**
* @param {ParseOptions | null | undefined} [options]
* @returns {ParseContext}
*/
export function parse(options) {
const settings = options || {}
const constructs =
/** @type {FullNormalizedExtension} */
combineExtensions([defaultConstructs, ...(settings.extensions || [])])
/** @type {ParseContext} */
const parser = {
defined: [],
lazy: {},
constructs,
content: create(content),
document: create(document),
flow: create(flow),
string: create(string),
text: create(text)
}
return parser
/**
* @param {InitialConstruct} initial
*/
function create(initial) {
return creator
/** @type {Create} */
function creator(from) {
return createTokenizer(parser, initial, from)
}
}
}

8
node_modules/micromark/lib/postprocess.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
/**
* @param {Array<Event>} events
* @returns {Array<Event>}
*/
export function postprocess(
events: Array<import('micromark-util-types').Event>
): Array<import('micromark-util-types').Event>
export type Event = import('micromark-util-types').Event

16
node_modules/micromark/lib/postprocess.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
/**
* @typedef {import('micromark-util-types').Event} Event
*/
import {subtokenize} from 'micromark-util-subtokenize'
/**
* @param {Array<Event>} events
* @returns {Array<Event>}
*/
export function postprocess(events) {
while (!subtokenize(events)) {
// Empty
}
return events
}

13
node_modules/micromark/lib/preprocess.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
/**
* @returns {Preprocessor}
*/
export function preprocess(): Preprocessor
export type Chunk = import('micromark-util-types').Chunk
export type Code = import('micromark-util-types').Code
export type Encoding = import('micromark-util-types').Encoding
export type Value = import('micromark-util-types').Value
export type Preprocessor = (
value: Value,
encoding?: Encoding | null | undefined,
end?: boolean | null | undefined
) => Array<Chunk>

113
node_modules/micromark/lib/preprocess.js generated vendored Normal file
View File

@@ -0,0 +1,113 @@
/**
* @typedef {import('micromark-util-types').Chunk} Chunk
* @typedef {import('micromark-util-types').Code} Code
* @typedef {import('micromark-util-types').Encoding} Encoding
* @typedef {import('micromark-util-types').Value} Value
*/
/**
* @callback Preprocessor
* @param {Value} value
* @param {Encoding | null | undefined} [encoding]
* @param {boolean | null | undefined} [end=false]
* @returns {Array<Chunk>}
*/
const search = /[\0\t\n\r]/g
/**
* @returns {Preprocessor}
*/
export function preprocess() {
let column = 1
let buffer = ''
/** @type {boolean | undefined} */
let start = true
/** @type {boolean | undefined} */
let atCarriageReturn
return preprocessor
/** @type {Preprocessor} */
// eslint-disable-next-line complexity
function preprocessor(value, encoding, end) {
/** @type {Array<Chunk>} */
const chunks = []
/** @type {RegExpMatchArray | null} */
let match
/** @type {number} */
let next
/** @type {number} */
let startPosition
/** @type {number} */
let endPosition
/** @type {Code} */
let code
value =
buffer +
(typeof value === 'string'
? value.toString()
: new TextDecoder(encoding || undefined).decode(value))
startPosition = 0
buffer = ''
if (start) {
// To do: `markdown-rs` actually parses BOMs (byte order mark).
if (value.charCodeAt(0) === 65279) {
startPosition++
}
start = undefined
}
while (startPosition < value.length) {
search.lastIndex = startPosition
match = search.exec(value)
endPosition =
match && match.index !== undefined ? match.index : value.length
code = value.charCodeAt(endPosition)
if (!match) {
buffer = value.slice(startPosition)
break
}
if (code === 10 && startPosition === endPosition && atCarriageReturn) {
chunks.push(-3)
atCarriageReturn = undefined
} else {
if (atCarriageReturn) {
chunks.push(-5)
atCarriageReturn = undefined
}
if (startPosition < endPosition) {
chunks.push(value.slice(startPosition, endPosition))
column += endPosition - startPosition
}
switch (code) {
case 0: {
chunks.push(65533)
column++
break
}
case 9: {
next = Math.ceil(column / 4) * 4
chunks.push(-2)
while (column++ < next) chunks.push(-1)
break
}
case 10: {
chunks.push(-4)
column = 1
break
}
default: {
atCarriageReturn = true
column = 1
}
}
}
startPosition = endPosition + 1
}
if (end) {
if (atCarriageReturn) chunks.push(-5)
if (buffer) chunks.push(buffer)
chunks.push(null)
}
return chunks
}
}

View File

@@ -0,0 +1,41 @@
/**
* Parse spaces and tabs.
*
* There is no `nok` parameter:
*
* * spaces in markdown are often optional, in which case this factory can be
* used and `ok` will be switched to whether spaces were found or not
* * one line ending or space can be detected with `markdownSpace(code)` right
* before using `factorySpace`
*
* ###### Examples
*
* Where `␉` represents a tab (plus how much it expands) and `␠` represents a
* single space.
*
* ```markdown
* ␉
* ␠␠␠␠
* ␉␠
* ```
*
* @param {Effects} effects
* Context.
* @param {State} ok
* State switched to when successful.
* @param {TokenType} type
* Type (`' \t'`).
* @param {number | undefined} [max=Infinity]
* Max (exclusive).
* @returns {State}
* Start state.
*/
export function factorySpace(
effects: Effects,
ok: State,
type: TokenType,
max?: number | undefined
): State
export type Effects = import('micromark-util-types').Effects
export type State = import('micromark-util-types').State
export type TokenType = import('micromark-util-types').TokenType

View File

@@ -0,0 +1,69 @@
/**
* @typedef {import('micromark-util-types').Effects} Effects
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenType} TokenType
*/
import {markdownSpace} from 'micromark-util-character'
// To do: implement `spaceOrTab`, `spaceOrTabMinMax`, `spaceOrTabWithOptions`.
/**
* Parse spaces and tabs.
*
* There is no `nok` parameter:
*
* * spaces in markdown are often optional, in which case this factory can be
* used and `ok` will be switched to whether spaces were found or not
* * one line ending or space can be detected with `markdownSpace(code)` right
* before using `factorySpace`
*
* ###### Examples
*
* Where `␉` represents a tab (plus how much it expands) and `␠` represents a
* single space.
*
* ```markdown
* ␉
* ␠␠␠␠
* ␉␠
* ```
*
* @param {Effects} effects
* Context.
* @param {State} ok
* State switched to when successful.
* @param {TokenType} type
* Type (`' \t'`).
* @param {number | undefined} [max=Infinity]
* Max (exclusive).
* @returns {State}
* Start state.
*/
export function factorySpace(effects, ok, type, max) {
const limit = max ? max - 1 : Number.POSITIVE_INFINITY
let size = 0
return start
/** @type {State} */
function start(code) {
if (markdownSpace(code)) {
effects.enter(type)
return prefix(code)
}
return ok(code)
}
/** @type {State} */
function prefix(code) {
if (markdownSpace(code) && size++ < limit) {
effects.consume(code)
return prefix
}
effects.exit(type)
return ok(code)
}
}

View File

@@ -0,0 +1,41 @@
/**
* Parse spaces and tabs.
*
* There is no `nok` parameter:
*
* * spaces in markdown are often optional, in which case this factory can be
* used and `ok` will be switched to whether spaces were found or not
* * one line ending or space can be detected with `markdownSpace(code)` right
* before using `factorySpace`
*
* ###### Examples
*
* Where `␉` represents a tab (plus how much it expands) and `␠` represents a
* single space.
*
* ```markdown
* ␉
* ␠␠␠␠
* ␉␠
* ```
*
* @param {Effects} effects
* Context.
* @param {State} ok
* State switched to when successful.
* @param {TokenType} type
* Type (`' \t'`).
* @param {number | undefined} [max=Infinity]
* Max (exclusive).
* @returns {State}
* Start state.
*/
export function factorySpace(
effects: Effects,
ok: State,
type: TokenType,
max?: number | undefined
): State
export type Effects = import('micromark-util-types').Effects
export type State = import('micromark-util-types').State
export type TokenType = import('micromark-util-types').TokenType

View File

@@ -0,0 +1,66 @@
/**
* @typedef {import('micromark-util-types').Effects} Effects
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenType} TokenType
*/
import {markdownSpace} from 'micromark-util-character'
// To do: implement `spaceOrTab`, `spaceOrTabMinMax`, `spaceOrTabWithOptions`.
/**
* Parse spaces and tabs.
*
* There is no `nok` parameter:
*
* * spaces in markdown are often optional, in which case this factory can be
* used and `ok` will be switched to whether spaces were found or not
* * one line ending or space can be detected with `markdownSpace(code)` right
* before using `factorySpace`
*
* ###### Examples
*
* Where `␉` represents a tab (plus how much it expands) and `␠` represents a
* single space.
*
* ```markdown
* ␉
* ␠␠␠␠
* ␉␠
* ```
*
* @param {Effects} effects
* Context.
* @param {State} ok
* State switched to when successful.
* @param {TokenType} type
* Type (`' \t'`).
* @param {number | undefined} [max=Infinity]
* Max (exclusive).
* @returns {State}
* Start state.
*/
export function factorySpace(effects, ok, type, max) {
const limit = max ? max - 1 : Number.POSITIVE_INFINITY
let size = 0
return start
/** @type {State} */
function start(code) {
if (markdownSpace(code)) {
effects.enter(type)
return prefix(code)
}
return ok(code)
}
/** @type {State} */
function prefix(code) {
if (markdownSpace(code) && size++ < limit) {
effects.consume(code)
return prefix
}
effects.exit(type)
return ok(code)
}
}

View File

@@ -0,0 +1,46 @@
{
"name": "micromark-factory-space",
"version": "2.0.0",
"description": "micromark factory to parse markdown space (found in lots of places)",
"license": "MIT",
"keywords": [
"micromark",
"factory",
"space"
],
"repository": "https://github.com/micromark/micromark/tree/main/packages/micromark-factory-space",
"bugs": "https://github.com/micromark/micromark/issues",
"funding": [
{
"type": "GitHub Sponsors",
"url": "https://github.com/sponsors/unifiedjs"
},
{
"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",
"files": [
"dev/",
"index.d.ts",
"index.js"
],
"exports": {
"development": "./dev/index.js",
"default": "./index.js"
},
"dependencies": {
"micromark-util-character": "^2.0.0",
"micromark-util-types": "^2.0.0"
},
"scripts": {
"build": "micromark-build"
},
"xo": false
}

View File

@@ -0,0 +1,224 @@
# micromark-factory-space
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
[micromark][] factory to parse [markdown space][markdown-space] (found in lots
of places).
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`factorySpace(…)`](#factoryspace)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package exposes states to parse spaces and/or tabs.
## When should I use this?
This package is useful when you are making your own micromark extensions.
## Install
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
```sh
npm install micromark-factory-space
```
In Deno with [`esm.sh`][esmsh]:
```js
import {factorySpace} from 'https://esm.sh/micromark-factory-space@1'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {factorySpace} from 'https://esm.sh/micromark-factory-space@1?bundle'
</script>
```
## Use
```js
import {factorySpace} from 'micromark-factory-space'
import {codes, types} from 'micromark-util-symbol'
// A micromark tokenizer that uses the factory:
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeCodeFenced(effects, ok, nok) {
return start
// …
/** @type {State} */
function info(code) {
if (code === codes.eof || markdownLineEndingOrSpace(code)) {
effects.exit(types.chunkString)
effects.exit(types.codeFencedFenceInfo)
return factorySpace(effects, infoAfter, types.whitespace)(code)
}
if (code === codes.graveAccent && code === marker) return nok(code)
effects.consume(code)
return info
}
// …
}
```
## API
This module exports the identifier [`factorySpace`][api-factory-space].
There is no default export.
### `factorySpace(…)`
Parse spaces and tabs.
There is no `nok` parameter:
* spaces in markdown are often optional, in which case this factory can be
used and `ok` will be switched to whether spaces were found or not
* one line ending or space can be detected with `markdownSpace(code)` right
before using `factorySpace`
###### Examples
Where `␉` represents a tab (plus how much it expands) and `␠` represents a
single space.
```markdown
␠␠␠␠
␉␠
```
###### Parameters
* `effects` (`Effects`)
— context
* `ok` (`State`)
— state switched to when successful
* `type` (`string`)
— type (`' \t'`)
* `max` (`number`, default: `Infinity`)
— max (exclusive)
###### Returns
Start state (`State`).
## Types
This package is fully typed with [TypeScript][].
It exports no additional types.
## Compatibility
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`micromark-factory-space@^2`, compatible with Node.js 16.
This package works with `micromark@^3`.
## Security
This package is safe.
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-factory-space.svg
[downloads]: https://www.npmjs.com/package/micromark-factory-space
[bundle-size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-factory-space
[bundle-size]: https://bundlejs.com/?q=micromark-factory-space
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/main/security.md
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md
[support]: https://github.com/micromark/.github/blob/main/support.md
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md
[markdown-space]: https://github.com/micromark/micromark/tree/main/packages/micromark-util-character#markdownspacecode
[typescript]: https://www.typescriptlang.org
[micromark]: https://github.com/micromark/micromark
[api-factory-space]: #factoryspace

View File

@@ -0,0 +1,64 @@
/**
* Check whether a character code is an ASCII control character.
*
* An **ASCII control** is a character in the inclusive range U+0000 NULL (NUL)
* to U+001F (US), or U+007F (DEL).
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function asciiControl(code: Code): boolean;
/**
* Check whether a character code is a markdown line ending.
*
* A **markdown line ending** is the virtual characters M-0003 CARRIAGE RETURN
* LINE FEED (CRLF), M-0004 LINE FEED (LF) and M-0005 CARRIAGE RETURN (CR).
*
* In micromark, the actual character U+000A LINE FEED (LF) and U+000D CARRIAGE
* RETURN (CR) are replaced by these virtual characters depending on whether
* they occurred together.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function markdownLineEnding(code: Code): boolean;
/**
* Check whether a character code is a markdown line ending (see
* `markdownLineEnding`) or markdown space (see `markdownSpace`).
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function markdownLineEndingOrSpace(code: Code): boolean;
/**
* Check whether a character code is a markdown space.
*
* A **markdown space** is the concrete character U+0020 SPACE (SP) and the
* virtual characters M-0001 VIRTUAL SPACE (VS) and M-0002 HORIZONTAL TAB (HT).
*
* In micromark, the actual character U+0009 CHARACTER TABULATION (HT) is
* replaced by one M-0002 HORIZONTAL TAB (HT) and between 0 and 3 M-0001 VIRTUAL
* SPACE (VS) characters, depending on the column at which the tab occurred.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function markdownSpace(code: Code): boolean;
export function asciiAlpha(code: Code): boolean;
export function asciiAlphanumeric(code: Code): boolean;
export function asciiAtext(code: Code): boolean;
export function asciiDigit(code: Code): boolean;
export function asciiHexDigit(code: Code): boolean;
export function asciiPunctuation(code: Code): boolean;
export function unicodePunctuation(code: Code): boolean;
export function unicodeWhitespace(code: Code): boolean;
export type Code = import('micromark-util-types').Code;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AA8DA;;;;;;;;;;GAUG;AACH,mCALW,IAAI,GAEF,OAAO,CASnB;AAkDD;;;;;;;;;;;;;;GAcG;AACH,yCALW,IAAI,GAEF,OAAO,CAKnB;AAED;;;;;;;;GAQG;AACH,gDALW,IAAI,GAEF,OAAO,CAKnB;AAED;;;;;;;;;;;;;;GAcG;AACH,oCALW,IAAI,GAEF,OAAO,CASnB;AAmDY,iCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,wCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,iCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,iCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,oCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,uCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,yCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,wCAAO,IAAI,GAAK,OAAO,CAAA;mBAxOvB,OAAO,sBAAsB,EAAE,IAAI"}

View File

@@ -0,0 +1,250 @@
/**
* @typedef {import('micromark-util-types').Code} Code
*/
import {codes} from 'micromark-util-symbol'
/**
* Check whether the character code represents an ASCII alpha (`a` through `z`,
* case insensitive).
*
* An **ASCII alpha** is an ASCII upper alpha or ASCII lower alpha.
*
* An **ASCII upper alpha** is a character in the inclusive range U+0041 (`A`)
* to U+005A (`Z`).
*
* An **ASCII lower alpha** is a character in the inclusive range U+0061 (`a`)
* to U+007A (`z`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export const asciiAlpha = regexCheck(/[A-Za-z]/)
/**
* Check whether the character code represents an ASCII alphanumeric (`a`
* through `z`, case insensitive, or `0` through `9`).
*
* An **ASCII alphanumeric** is an ASCII digit (see `asciiDigit`) or ASCII alpha
* (see `asciiAlpha`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export const asciiAlphanumeric = regexCheck(/[\dA-Za-z]/)
/**
* Check whether the character code represents an ASCII atext.
*
* atext is an ASCII alphanumeric (see `asciiAlphanumeric`), or a character in
* the inclusive ranges U+0023 NUMBER SIGN (`#`) to U+0027 APOSTROPHE (`'`),
* U+002A ASTERISK (`*`), U+002B PLUS SIGN (`+`), U+002D DASH (`-`), U+002F
* SLASH (`/`), U+003D EQUALS TO (`=`), U+003F QUESTION MARK (`?`), U+005E
* CARET (`^`) to U+0060 GRAVE ACCENT (`` ` ``), or U+007B LEFT CURLY BRACE
* (`{`) to U+007E TILDE (`~`).
*
* See:
* **\[RFC5322]**:
* [Internet Message Format](https://tools.ietf.org/html/rfc5322).
* P. Resnick.
* IETF.
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export const asciiAtext = regexCheck(/[#-'*+\--9=?A-Z^-~]/)
/**
* Check whether a character code is an ASCII control character.
*
* An **ASCII control** is a character in the inclusive range U+0000 NULL (NUL)
* to U+001F (US), or U+007F (DEL).
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function asciiControl(code) {
return (
// Special whitespace codes (which have negative values), C0 and Control
// character DEL
code !== null && (code < codes.space || code === codes.del)
)
}
/**
* Check whether the character code represents an ASCII digit (`0` through `9`).
*
* An **ASCII digit** is a character in the inclusive range U+0030 (`0`) to
* U+0039 (`9`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export const asciiDigit = regexCheck(/\d/)
/**
* Check whether the character code represents an ASCII hex digit (`a` through
* `f`, case insensitive, or `0` through `9`).
*
* An **ASCII hex digit** is an ASCII digit (see `asciiDigit`), ASCII upper hex
* digit, or an ASCII lower hex digit.
*
* An **ASCII upper hex digit** is a character in the inclusive range U+0041
* (`A`) to U+0046 (`F`).
*
* An **ASCII lower hex digit** is a character in the inclusive range U+0061
* (`a`) to U+0066 (`f`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export const asciiHexDigit = regexCheck(/[\dA-Fa-f]/)
/**
* Check whether the character code represents ASCII punctuation.
*
* An **ASCII punctuation** is a character in the inclusive ranges U+0021
* EXCLAMATION MARK (`!`) to U+002F SLASH (`/`), U+003A COLON (`:`) to U+0040 AT
* SIGN (`@`), U+005B LEFT SQUARE BRACKET (`[`) to U+0060 GRAVE ACCENT
* (`` ` ``), or U+007B LEFT CURLY BRACE (`{`) to U+007E TILDE (`~`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export const asciiPunctuation = regexCheck(/[!-/:-@[-`{-~]/)
/**
* Check whether a character code is a markdown line ending.
*
* A **markdown line ending** is the virtual characters M-0003 CARRIAGE RETURN
* LINE FEED (CRLF), M-0004 LINE FEED (LF) and M-0005 CARRIAGE RETURN (CR).
*
* In micromark, the actual character U+000A LINE FEED (LF) and U+000D CARRIAGE
* RETURN (CR) are replaced by these virtual characters depending on whether
* they occurred together.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function markdownLineEnding(code) {
return code !== null && code < codes.horizontalTab
}
/**
* Check whether a character code is a markdown line ending (see
* `markdownLineEnding`) or markdown space (see `markdownSpace`).
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function markdownLineEndingOrSpace(code) {
return code !== null && (code < codes.nul || code === codes.space)
}
/**
* Check whether a character code is a markdown space.
*
* A **markdown space** is the concrete character U+0020 SPACE (SP) and the
* virtual characters M-0001 VIRTUAL SPACE (VS) and M-0002 HORIZONTAL TAB (HT).
*
* In micromark, the actual character U+0009 CHARACTER TABULATION (HT) is
* replaced by one M-0002 HORIZONTAL TAB (HT) and between 0 and 3 M-0001 VIRTUAL
* SPACE (VS) characters, depending on the column at which the tab occurred.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function markdownSpace(code) {
return (
code === codes.horizontalTab ||
code === codes.virtualSpace ||
code === codes.space
)
}
// Size note: removing ASCII from the regex and using `asciiPunctuation` here
// In fact adds to the bundle size.
/**
* Check whether the character code represents Unicode punctuation.
*
* A **Unicode punctuation** is a character in the Unicode `Pc` (Punctuation,
* Connector), `Pd` (Punctuation, Dash), `Pe` (Punctuation, Close), `Pf`
* (Punctuation, Final quote), `Pi` (Punctuation, Initial quote), `Po`
* (Punctuation, Other), or `Ps` (Punctuation, Open) categories, or an ASCII
* punctuation (see `asciiPunctuation`).
*
* See:
* **\[UNICODE]**:
* [The Unicode Standard](https://www.unicode.org/versions/).
* Unicode Consortium.
*
* @param code
* Code.
* @returns
* Whether it matches.
*/
export const unicodePunctuation = regexCheck(/\p{P}|\p{S}/u)
/**
* Check whether the character code represents Unicode whitespace.
*
* Note that this does handle micromark specific markdown whitespace characters.
* See `markdownLineEndingOrSpace` to check that.
*
* A **Unicode whitespace** is a character in the Unicode `Zs` (Separator,
* Space) category, or U+0009 CHARACTER TABULATION (HT), U+000A LINE FEED (LF),
* U+000C (FF), or U+000D CARRIAGE RETURN (CR) (**\[UNICODE]**).
*
* See:
* **\[UNICODE]**:
* [The Unicode Standard](https://www.unicode.org/versions/).
* Unicode Consortium.
*
* @param code
* Code.
* @returns
* Whether it matches.
*/
export const unicodeWhitespace = regexCheck(/\s/)
/**
* Create a code check from a regex.
*
* @param {RegExp} regex
* @returns {(code: Code) => boolean}
*/
function regexCheck(regex) {
return check
/**
* Check whether a code matches the bound regex.
*
* @param {Code} code
* Character code.
* @returns {boolean}
* Whether the character code matches the bound regex.
*/
function check(code) {
return code !== null && code > -1 && regex.test(String.fromCharCode(code))
}
}

View File

@@ -0,0 +1,64 @@
/**
* Check whether a character code is an ASCII control character.
*
* An **ASCII control** is a character in the inclusive range U+0000 NULL (NUL)
* to U+001F (US), or U+007F (DEL).
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function asciiControl(code: Code): boolean;
/**
* Check whether a character code is a markdown line ending.
*
* A **markdown line ending** is the virtual characters M-0003 CARRIAGE RETURN
* LINE FEED (CRLF), M-0004 LINE FEED (LF) and M-0005 CARRIAGE RETURN (CR).
*
* In micromark, the actual character U+000A LINE FEED (LF) and U+000D CARRIAGE
* RETURN (CR) are replaced by these virtual characters depending on whether
* they occurred together.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function markdownLineEnding(code: Code): boolean;
/**
* Check whether a character code is a markdown line ending (see
* `markdownLineEnding`) or markdown space (see `markdownSpace`).
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function markdownLineEndingOrSpace(code: Code): boolean;
/**
* Check whether a character code is a markdown space.
*
* A **markdown space** is the concrete character U+0020 SPACE (SP) and the
* virtual characters M-0001 VIRTUAL SPACE (VS) and M-0002 HORIZONTAL TAB (HT).
*
* In micromark, the actual character U+0009 CHARACTER TABULATION (HT) is
* replaced by one M-0002 HORIZONTAL TAB (HT) and between 0 and 3 M-0001 VIRTUAL
* SPACE (VS) characters, depending on the column at which the tab occurred.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function markdownSpace(code: Code): boolean;
export function asciiAlpha(code: Code): boolean;
export function asciiAlphanumeric(code: Code): boolean;
export function asciiAtext(code: Code): boolean;
export function asciiDigit(code: Code): boolean;
export function asciiHexDigit(code: Code): boolean;
export function asciiPunctuation(code: Code): boolean;
export function unicodePunctuation(code: Code): boolean;
export function unicodeWhitespace(code: Code): boolean;
export type Code = import('micromark-util-types').Code;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AA8DA;;;;;;;;;;GAUG;AACH,mCALW,IAAI,GAEF,OAAO,CASnB;AAkDD;;;;;;;;;;;;;;GAcG;AACH,yCALW,IAAI,GAEF,OAAO,CAKnB;AAED;;;;;;;;GAQG;AACH,gDALW,IAAI,GAEF,OAAO,CAKnB;AAED;;;;;;;;;;;;;;GAcG;AACH,oCALW,IAAI,GAEF,OAAO,CASnB;AAmDY,iCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,wCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,iCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,iCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,oCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,uCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,yCAAO,IAAI,GAAK,OAAO,CAAA;AAAvB,wCAAO,IAAI,GAAK,OAAO,CAAA;mBAxOvB,OAAO,sBAAsB,EAAE,IAAI"}

View File

@@ -0,0 +1,244 @@
/**
* @typedef {import('micromark-util-types').Code} Code
*/
/**
* Check whether the character code represents an ASCII alpha (`a` through `z`,
* case insensitive).
*
* An **ASCII alpha** is an ASCII upper alpha or ASCII lower alpha.
*
* An **ASCII upper alpha** is a character in the inclusive range U+0041 (`A`)
* to U+005A (`Z`).
*
* An **ASCII lower alpha** is a character in the inclusive range U+0061 (`a`)
* to U+007A (`z`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export const asciiAlpha = regexCheck(/[A-Za-z]/);
/**
* Check whether the character code represents an ASCII alphanumeric (`a`
* through `z`, case insensitive, or `0` through `9`).
*
* An **ASCII alphanumeric** is an ASCII digit (see `asciiDigit`) or ASCII alpha
* (see `asciiAlpha`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export const asciiAlphanumeric = regexCheck(/[\dA-Za-z]/);
/**
* Check whether the character code represents an ASCII atext.
*
* atext is an ASCII alphanumeric (see `asciiAlphanumeric`), or a character in
* the inclusive ranges U+0023 NUMBER SIGN (`#`) to U+0027 APOSTROPHE (`'`),
* U+002A ASTERISK (`*`), U+002B PLUS SIGN (`+`), U+002D DASH (`-`), U+002F
* SLASH (`/`), U+003D EQUALS TO (`=`), U+003F QUESTION MARK (`?`), U+005E
* CARET (`^`) to U+0060 GRAVE ACCENT (`` ` ``), or U+007B LEFT CURLY BRACE
* (`{`) to U+007E TILDE (`~`).
*
* See:
* **\[RFC5322]**:
* [Internet Message Format](https://tools.ietf.org/html/rfc5322).
* P. Resnick.
* IETF.
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export const asciiAtext = regexCheck(/[#-'*+\--9=?A-Z^-~]/);
/**
* Check whether a character code is an ASCII control character.
*
* An **ASCII control** is a character in the inclusive range U+0000 NULL (NUL)
* to U+001F (US), or U+007F (DEL).
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function asciiControl(code) {
return (
// Special whitespace codes (which have negative values), C0 and Control
// character DEL
code !== null && (code < 32 || code === 127)
);
}
/**
* Check whether the character code represents an ASCII digit (`0` through `9`).
*
* An **ASCII digit** is a character in the inclusive range U+0030 (`0`) to
* U+0039 (`9`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export const asciiDigit = regexCheck(/\d/);
/**
* Check whether the character code represents an ASCII hex digit (`a` through
* `f`, case insensitive, or `0` through `9`).
*
* An **ASCII hex digit** is an ASCII digit (see `asciiDigit`), ASCII upper hex
* digit, or an ASCII lower hex digit.
*
* An **ASCII upper hex digit** is a character in the inclusive range U+0041
* (`A`) to U+0046 (`F`).
*
* An **ASCII lower hex digit** is a character in the inclusive range U+0061
* (`a`) to U+0066 (`f`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export const asciiHexDigit = regexCheck(/[\dA-Fa-f]/);
/**
* Check whether the character code represents ASCII punctuation.
*
* An **ASCII punctuation** is a character in the inclusive ranges U+0021
* EXCLAMATION MARK (`!`) to U+002F SLASH (`/`), U+003A COLON (`:`) to U+0040 AT
* SIGN (`@`), U+005B LEFT SQUARE BRACKET (`[`) to U+0060 GRAVE ACCENT
* (`` ` ``), or U+007B LEFT CURLY BRACE (`{`) to U+007E TILDE (`~`).
*
* @param code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export const asciiPunctuation = regexCheck(/[!-/:-@[-`{-~]/);
/**
* Check whether a character code is a markdown line ending.
*
* A **markdown line ending** is the virtual characters M-0003 CARRIAGE RETURN
* LINE FEED (CRLF), M-0004 LINE FEED (LF) and M-0005 CARRIAGE RETURN (CR).
*
* In micromark, the actual character U+000A LINE FEED (LF) and U+000D CARRIAGE
* RETURN (CR) are replaced by these virtual characters depending on whether
* they occurred together.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function markdownLineEnding(code) {
return code !== null && code < -2;
}
/**
* Check whether a character code is a markdown line ending (see
* `markdownLineEnding`) or markdown space (see `markdownSpace`).
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function markdownLineEndingOrSpace(code) {
return code !== null && (code < 0 || code === 32);
}
/**
* Check whether a character code is a markdown space.
*
* A **markdown space** is the concrete character U+0020 SPACE (SP) and the
* virtual characters M-0001 VIRTUAL SPACE (VS) and M-0002 HORIZONTAL TAB (HT).
*
* In micromark, the actual character U+0009 CHARACTER TABULATION (HT) is
* replaced by one M-0002 HORIZONTAL TAB (HT) and between 0 and 3 M-0001 VIRTUAL
* SPACE (VS) characters, depending on the column at which the tab occurred.
*
* @param {Code} code
* Code.
* @returns {boolean}
* Whether it matches.
*/
export function markdownSpace(code) {
return code === -2 || code === -1 || code === 32;
}
// Size note: removing ASCII from the regex and using `asciiPunctuation` here
// In fact adds to the bundle size.
/**
* Check whether the character code represents Unicode punctuation.
*
* A **Unicode punctuation** is a character in the Unicode `Pc` (Punctuation,
* Connector), `Pd` (Punctuation, Dash), `Pe` (Punctuation, Close), `Pf`
* (Punctuation, Final quote), `Pi` (Punctuation, Initial quote), `Po`
* (Punctuation, Other), or `Ps` (Punctuation, Open) categories, or an ASCII
* punctuation (see `asciiPunctuation`).
*
* See:
* **\[UNICODE]**:
* [The Unicode Standard](https://www.unicode.org/versions/).
* Unicode Consortium.
*
* @param code
* Code.
* @returns
* Whether it matches.
*/
export const unicodePunctuation = regexCheck(/\p{P}|\p{S}/u);
/**
* Check whether the character code represents Unicode whitespace.
*
* Note that this does handle micromark specific markdown whitespace characters.
* See `markdownLineEndingOrSpace` to check that.
*
* A **Unicode whitespace** is a character in the Unicode `Zs` (Separator,
* Space) category, or U+0009 CHARACTER TABULATION (HT), U+000A LINE FEED (LF),
* U+000C (FF), or U+000D CARRIAGE RETURN (CR) (**\[UNICODE]**).
*
* See:
* **\[UNICODE]**:
* [The Unicode Standard](https://www.unicode.org/versions/).
* Unicode Consortium.
*
* @param code
* Code.
* @returns
* Whether it matches.
*/
export const unicodeWhitespace = regexCheck(/\s/);
/**
* Create a code check from a regex.
*
* @param {RegExp} regex
* @returns {(code: Code) => boolean}
*/
function regexCheck(regex) {
return check;
/**
* Check whether a code matches the bound regex.
*
* @param {Code} code
* Character code.
* @returns {boolean}
* Whether the character code matches the bound regex.
*/
function check(code) {
return code !== null && code > -1 && regex.test(String.fromCharCode(code));
}
}

View File

@@ -0,0 +1,57 @@
{
"name": "micromark-util-character",
"version": "2.1.0",
"description": "micromark utility to handle character codes",
"license": "MIT",
"keywords": [
"micromark",
"util",
"utility",
"character"
],
"repository": "https://github.com/micromark/micromark/tree/main/packages/micromark-util-character",
"bugs": "https://github.com/micromark/micromark/issues",
"funding": [
{
"type": "GitHub Sponsors",
"url": "https://github.com/sponsors/unifiedjs"
},
{
"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",
"files": [
"dev/",
"lib/",
"index.d.ts.map",
"index.d.ts",
"index.js"
],
"exports": {
"development": "./dev/index.js",
"default": "./index.js"
},
"dependencies": {
"micromark-util-symbol": "^2.0.0",
"micromark-util-types": "^2.0.0"
},
"scripts": {
"build": "micromark-build"
},
"xo": {
"envs": [
"shared-node-browser"
],
"prettier": true,
"rules": {
"unicorn/prefer-code-point": "off"
}
}
}

View File

@@ -0,0 +1,446 @@
# micromark-util-character
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
[micromark][] utility to handle [character codes][code].
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`asciiAlpha(code)`](#asciialphacode)
* [`asciiAlphanumeric(code)`](#asciialphanumericcode)
* [`asciiAtext(code)`](#asciiatextcode)
* [`asciiControl(code)`](#asciicontrolcode)
* [`asciiDigit(code)`](#asciidigitcode)
* [`asciiHexDigit(code)`](#asciihexdigitcode)
* [`asciiPunctuation(code)`](#asciipunctuationcode)
* [`markdownLineEnding(code)`](#markdownlineendingcode)
* [`markdownLineEndingOrSpace(code)`](#markdownlineendingorspacecode)
* [`markdownSpace(code)`](#markdownspacecode)
* [`unicodePunctuation(code)`](#unicodepunctuationcode)
* [`unicodeWhitespace(code)`](#unicodewhitespacecode)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package exposes algorithms to check whether characters match groups.
## When should I use this?
This package might be useful when you are making your own micromark extensions.
## Install
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
```sh
npm install micromark-util-character
```
In Deno with [`esm.sh`][esmsh]:
```js
import * as character from 'https://esm.sh/micromark-util-character@1'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import * as character from 'https://esm.sh/micromark-util-character@1?bundle'
</script>
```
## Use
```js
import {asciiAlpha} from 'micromark-util-character'
console.log(asciiAlpha(64)) // false
console.log(asciiAlpha(65)) // true
```
## API
This module exports the identifiers
[`asciiAlpha`][api-ascii-alpha],
[`asciiAlphanumeric`][api-ascii-alphanumeric],
[`asciiAtext`][api-ascii-atext],
[`asciiControl`][api-ascii-control],
[`asciiDigit`][api-ascii-digit],
[`asciiHexDigit`][api-ascii-hex-digit],
[`asciiPunctuation`][api-ascii-punctuation],
[`markdownLineEnding`][api-markdown-line-ending],
[`markdownLineEndingOrSpace`][api-markdown-line-ending-or-space],
[`markdownSpace`][api-markdown-space],
[`unicodePunctuation`][api-unicode-punctuation],
[`unicodeWhitespace`][api-unicode-whitespace].
There is no default export.
### `asciiAlpha(code)`
Check whether the [character code][code] represents an ASCII alpha (`a` through
`z`, case insensitive).
An **ASCII alpha** is an ASCII upper alpha or ASCII lower alpha.
An **ASCII upper alpha** is a character in the inclusive range U+0041 (`A`)
to U+005A (`Z`).
An **ASCII lower alpha** is a character in the inclusive range U+0061 (`a`)
to U+007A (`z`).
###### Parameters
* `code` (`Code`)
— code
###### Returns
Whether it matches (`boolean`).
### `asciiAlphanumeric(code)`
Check whether the [character code][code] represents an ASCII alphanumeric (`a`
through `z`, case insensitive, or `0` through `9`).
An **ASCII alphanumeric** is an ASCII digit (see `asciiDigit`) or ASCII alpha
(see `asciiAlpha`).
###### Parameters
* `code` (`Code`)
— code
###### Returns
Whether it matches (`boolean`).
### `asciiAtext(code)`
Check whether the [character code][code] represents an ASCII atext.
atext is an ASCII alphanumeric (see `asciiAlphanumeric`), or a character in
the inclusive ranges U+0023 NUMBER SIGN (`#`) to U+0027 APOSTROPHE (`'`),
U+002A ASTERISK (`*`), U+002B PLUS SIGN (`+`), U+002D DASH (`-`), U+002F
SLASH (`/`), U+003D EQUALS TO (`=`), U+003F QUESTION MARK (`?`), U+005E
CARET (`^`) to U+0060 GRAVE ACCENT (`` ` ``), or U+007B LEFT CURLY BRACE
(`{`) to U+007E TILDE (`~`) (**\[RFC5322]**).
See **\[RFC5322]**:\
[Internet Message Format](https://tools.ietf.org/html/rfc5322).\
P. Resnick.\
IETF.
###### Parameters
* `code` (`Code`)
— code
###### Returns
Whether it matches (`boolean`).
### `asciiControl(code)`
Check whether a [character code][code] is an ASCII control character.
An **ASCII control** is a character in the inclusive range U+0000 NULL (NUL)
to U+001F (US), or U+007F (DEL).
###### Parameters
* `code` (`Code`)
— code
###### Returns
Whether it matches (`boolean`).
### `asciiDigit(code)`
Check whether the [character code][code] represents an ASCII digit (`0` through
`9`).
An **ASCII digit** is a character in the inclusive range U+0030 (`0`) to
U+0039 (`9`).
###### Parameters
* `code` (`Code`)
— code
###### Returns
Whether it matches (`boolean`).
### `asciiHexDigit(code)`
Check whether the [character code][code] represents an ASCII hex digit (`a`
through `f`, case insensitive, or `0` through `9`).
An **ASCII hex digit** is an ASCII digit (see `asciiDigit`), ASCII upper hex
digit, or an ASCII lower hex digit.
An **ASCII upper hex digit** is a character in the inclusive range U+0041
(`A`) to U+0046 (`F`).
An **ASCII lower hex digit** is a character in the inclusive range U+0061
(`a`) to U+0066 (`f`).
###### Parameters
* `code` (`Code`)
— code
###### Returns
Whether it matches (`boolean`).
### `asciiPunctuation(code)`
Check whether the [character code][code] represents ASCII punctuation.
An **ASCII punctuation** is a character in the inclusive ranges U+0021
EXCLAMATION MARK (`!`) to U+002F SLASH (`/`), U+003A COLON (`:`) to U+0040 AT
SIGN (`@`), U+005B LEFT SQUARE BRACKET (`[`) to U+0060 GRAVE ACCENT
(`` ` ``), or U+007B LEFT CURLY BRACE (`{`) to U+007E TILDE (`~`).
###### Parameters
* `code` (`Code`)
— code
###### Returns
Whether it matches (`boolean`).
### `markdownLineEnding(code)`
Check whether a [character code][code] is a markdown line ending.
A **markdown line ending** is the virtual characters M-0003 CARRIAGE RETURN
LINE FEED (CRLF), M-0004 LINE FEED (LF) and M-0005 CARRIAGE RETURN (CR).
In micromark, the actual character U+000A LINE FEED (LF) and U+000D CARRIAGE
RETURN (CR) are replaced by these virtual characters depending on whether
they occurred together.
###### Parameters
* `code` (`Code`)
— code
###### Returns
Whether it matches (`boolean`).
### `markdownLineEndingOrSpace(code)`
Check whether a [character code][code] is a markdown line ending (see
`markdownLineEnding`) or markdown space (see `markdownSpace`).
###### Parameters
* `code` (`Code`)
— code
###### Returns
Whether it matches (`boolean`).
### `markdownSpace(code)`
Check whether a [character code][code] is a markdown space.
A **markdown space** is the concrete character U+0020 SPACE (SP) and the
virtual characters M-0001 VIRTUAL SPACE (VS) and M-0002 HORIZONTAL TAB (HT).
In micromark, the actual character U+0009 CHARACTER TABULATION (HT) is
replaced by one M-0002 HORIZONTAL TAB (HT) and between 0 and 3 M-0001 VIRTUAL
SPACE (VS) characters, depending on the column at which the tab occurred.
###### Parameters
* `code` (`Code`)
— code
###### Returns
Whether it matches (`boolean`).
### `unicodePunctuation(code)`
Check whether the [character code][code] represents Unicode punctuation.
A **Unicode punctuation** is a character in the Unicode `Pc` (Punctuation,
Connector), `Pd` (Punctuation, Dash), `Pe` (Punctuation, Close), `Pf`
(Punctuation, Final quote), `Pi` (Punctuation, Initial quote), `Po`
(Punctuation, Other), or `Ps` (Punctuation, Open) categories, or an ASCII
punctuation (see `asciiPunctuation`) (**\[UNICODE]**).
See **\[UNICODE]**:\
[The Unicode Standard](https://www.unicode.org/versions/).\
Unicode Consortium.
###### Parameters
* `code` (`Code`)
— code
###### Returns
Whether it matches (`boolean`).
### `unicodeWhitespace(code)`
Check whether the [character code][code] represents Unicode whitespace.
Note that this does handle micromark specific markdown whitespace characters.
See `markdownLineEndingOrSpace` to check that.
A **Unicode whitespace** is a character in the Unicode `Zs` (Separator,
Space) category, or U+0009 CHARACTER TABULATION (HT), U+000A LINE FEED (LF),
U+000C (FF), or U+000D CARRIAGE RETURN (CR) (**\[UNICODE]**).
See **\[UNICODE]**:\
[The Unicode Standard](https://www.unicode.org/versions/).\
Unicode Consortium.
###### Parameters
* `code` (`Code`)
— code
###### Returns
Whether it matches (`boolean`).
## Types
This package is fully typed with [TypeScript][].
It exports no additional types.
## Compatibility
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`micromark-util-character@^2`, compatible with Node.js 16.
This package works with `micromark@^3`.
## Security
This package is safe.
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-character.svg
[downloads]: https://www.npmjs.com/package/micromark-util-character
[bundle-size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-util-character
[bundle-size]: https://bundlejs.com/?q=micromark-util-character
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/main/security.md
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md
[support]: https://github.com/micromark/.github/blob/main/support.md
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md
[typescript]: https://www.typescriptlang.org
[micromark]: https://github.com/micromark/micromark
[code]: https://github.com/micromark/micromark#preprocess
[api-ascii-alpha]: #asciialphacode
[api-ascii-alphanumeric]: #asciialphanumericcode
[api-ascii-atext]: #asciiatextcode
[api-ascii-control]: #asciicontrolcode
[api-ascii-digit]: #asciidigitcode
[api-ascii-hex-digit]: #asciihexdigitcode
[api-ascii-punctuation]: #asciipunctuationcode
[api-markdown-line-ending]: #markdownlineendingcode
[api-markdown-line-ending-or-space]: #markdownlineendingorspacecode
[api-markdown-space]: #markdownspacecode
[api-unicode-punctuation]: #unicodepunctuationcode
[api-unicode-whitespace]: #unicodewhitespacecode

View File

@@ -0,0 +1,138 @@
export namespace codes {
let carriageReturn: -5
let lineFeed: -4
let carriageReturnLineFeed: -3
let horizontalTab: -2
let virtualSpace: -1
let eof: null
let nul: 0
let soh: 1
let stx: 2
let etx: 3
let eot: 4
let enq: 5
let ack: 6
let bel: 7
let bs: 8
let ht: 9
let lf: 10
let vt: 11
let ff: 12
let cr: 13
let so: 14
let si: 15
let dle: 16
let dc1: 17
let dc2: 18
let dc3: 19
let dc4: 20
let nak: 21
let syn: 22
let etb: 23
let can: 24
let em: 25
let sub: 26
let esc: 27
let fs: 28
let gs: 29
let rs: 30
let us: 31
let space: 32
let exclamationMark: 33
let quotationMark: 34
let numberSign: 35
let dollarSign: 36
let percentSign: 37
let ampersand: 38
let apostrophe: 39
let leftParenthesis: 40
let rightParenthesis: 41
let asterisk: 42
let plusSign: 43
let comma: 44
let dash: 45
let dot: 46
let slash: 47
let digit0: 48
let digit1: 49
let digit2: 50
let digit3: 51
let digit4: 52
let digit5: 53
let digit6: 54
let digit7: 55
let digit8: 56
let digit9: 57
let colon: 58
let semicolon: 59
let lessThan: 60
let equalsTo: 61
let greaterThan: 62
let questionMark: 63
let atSign: 64
let uppercaseA: 65
let uppercaseB: 66
let uppercaseC: 67
let uppercaseD: 68
let uppercaseE: 69
let uppercaseF: 70
let uppercaseG: 71
let uppercaseH: 72
let uppercaseI: 73
let uppercaseJ: 74
let uppercaseK: 75
let uppercaseL: 76
let uppercaseM: 77
let uppercaseN: 78
let uppercaseO: 79
let uppercaseP: 80
let uppercaseQ: 81
let uppercaseR: 82
let uppercaseS: 83
let uppercaseT: 84
let uppercaseU: 85
let uppercaseV: 86
let uppercaseW: 87
let uppercaseX: 88
let uppercaseY: 89
let uppercaseZ: 90
let leftSquareBracket: 91
let backslash: 92
let rightSquareBracket: 93
let caret: 94
let underscore: 95
let graveAccent: 96
let lowercaseA: 97
let lowercaseB: 98
let lowercaseC: 99
let lowercaseD: 100
let lowercaseE: 101
let lowercaseF: 102
let lowercaseG: 103
let lowercaseH: 104
let lowercaseI: 105
let lowercaseJ: 106
let lowercaseK: 107
let lowercaseL: 108
let lowercaseM: 109
let lowercaseN: 110
let lowercaseO: 111
let lowercaseP: 112
let lowercaseQ: 113
let lowercaseR: 114
let lowercaseS: 115
let lowercaseT: 116
let lowercaseU: 117
let lowercaseV: 118
let lowercaseW: 119
let lowercaseX: 120
let lowercaseY: 121
let lowercaseZ: 122
let leftCurlyBrace: 123
let verticalBar: 124
let rightCurlyBrace: 125
let tilde: 126
let del: 127
let byteOrderMarker: 65279
let replacementCharacter: 65533
}

View File

@@ -0,0 +1,158 @@
/**
* Character codes.
*
* This module is compiled away!
*
* micromark works based on character codes.
* This module contains constants for the ASCII block and the replacement
* character.
* A couple of them are handled in a special way, such as the line endings
* (CR, LF, and CR+LF, commonly known as end-of-line: EOLs), the tab (horizontal
* tab) and its expansion based on what column its at (virtual space),
* and the end-of-file (eof) character.
* As values are preprocessed before handling them, the actual characters LF,
* CR, HT, and NUL (which is present as the replacement character), are
* guaranteed to not exist.
*
* Unicode basic latin block.
*/
export const codes = /** @type {const} */ ({
carriageReturn: -5,
lineFeed: -4,
carriageReturnLineFeed: -3,
horizontalTab: -2,
virtualSpace: -1,
eof: null,
nul: 0,
soh: 1,
stx: 2,
etx: 3,
eot: 4,
enq: 5,
ack: 6,
bel: 7,
bs: 8,
ht: 9, // `\t`
lf: 10, // `\n`
vt: 11, // `\v`
ff: 12, // `\f`
cr: 13, // `\r`
so: 14,
si: 15,
dle: 16,
dc1: 17,
dc2: 18,
dc3: 19,
dc4: 20,
nak: 21,
syn: 22,
etb: 23,
can: 24,
em: 25,
sub: 26,
esc: 27,
fs: 28,
gs: 29,
rs: 30,
us: 31,
space: 32,
exclamationMark: 33, // `!`
quotationMark: 34, // `"`
numberSign: 35, // `#`
dollarSign: 36, // `$`
percentSign: 37, // `%`
ampersand: 38, // `&`
apostrophe: 39, // `'`
leftParenthesis: 40, // `(`
rightParenthesis: 41, // `)`
asterisk: 42, // `*`
plusSign: 43, // `+`
comma: 44, // `,`
dash: 45, // `-`
dot: 46, // `.`
slash: 47, // `/`
digit0: 48, // `0`
digit1: 49, // `1`
digit2: 50, // `2`
digit3: 51, // `3`
digit4: 52, // `4`
digit5: 53, // `5`
digit6: 54, // `6`
digit7: 55, // `7`
digit8: 56, // `8`
digit9: 57, // `9`
colon: 58, // `:`
semicolon: 59, // `;`
lessThan: 60, // `<`
equalsTo: 61, // `=`
greaterThan: 62, // `>`
questionMark: 63, // `?`
atSign: 64, // `@`
uppercaseA: 65, // `A`
uppercaseB: 66, // `B`
uppercaseC: 67, // `C`
uppercaseD: 68, // `D`
uppercaseE: 69, // `E`
uppercaseF: 70, // `F`
uppercaseG: 71, // `G`
uppercaseH: 72, // `H`
uppercaseI: 73, // `I`
uppercaseJ: 74, // `J`
uppercaseK: 75, // `K`
uppercaseL: 76, // `L`
uppercaseM: 77, // `M`
uppercaseN: 78, // `N`
uppercaseO: 79, // `O`
uppercaseP: 80, // `P`
uppercaseQ: 81, // `Q`
uppercaseR: 82, // `R`
uppercaseS: 83, // `S`
uppercaseT: 84, // `T`
uppercaseU: 85, // `U`
uppercaseV: 86, // `V`
uppercaseW: 87, // `W`
uppercaseX: 88, // `X`
uppercaseY: 89, // `Y`
uppercaseZ: 90, // `Z`
leftSquareBracket: 91, // `[`
backslash: 92, // `\`
rightSquareBracket: 93, // `]`
caret: 94, // `^`
underscore: 95, // `_`
graveAccent: 96, // `` ` ``
lowercaseA: 97, // `a`
lowercaseB: 98, // `b`
lowercaseC: 99, // `c`
lowercaseD: 100, // `d`
lowercaseE: 101, // `e`
lowercaseF: 102, // `f`
lowercaseG: 103, // `g`
lowercaseH: 104, // `h`
lowercaseI: 105, // `i`
lowercaseJ: 106, // `j`
lowercaseK: 107, // `k`
lowercaseL: 108, // `l`
lowercaseM: 109, // `m`
lowercaseN: 110, // `n`
lowercaseO: 111, // `o`
lowercaseP: 112, // `p`
lowercaseQ: 113, // `q`
lowercaseR: 114, // `r`
lowercaseS: 115, // `s`
lowercaseT: 116, // `t`
lowercaseU: 117, // `u`
lowercaseV: 118, // `v`
lowercaseW: 119, // `w`
lowercaseX: 120, // `x`
lowercaseY: 121, // `y`
lowercaseZ: 122, // `z`
leftCurlyBrace: 123, // `{`
verticalBar: 124, // `|`
rightCurlyBrace: 125, // `}`
tilde: 126, // `~`
del: 127,
// Unicode Specials block.
byteOrderMarker: 65279,
// Unicode Specials block.
replacementCharacter: 65533 // `<60>`
})

View File

@@ -0,0 +1,36 @@
export namespace constants {
let attentionSideBefore: 1
let attentionSideAfter: 2
let atxHeadingOpeningFenceSizeMax: 6
let autolinkDomainSizeMax: 63
let autolinkSchemeSizeMax: 32
let cdataOpeningString: 'CDATA['
let characterGroupWhitespace: 1
let characterGroupPunctuation: 2
let characterReferenceDecimalSizeMax: 7
let characterReferenceHexadecimalSizeMax: 6
let characterReferenceNamedSizeMax: 31
let codeFencedSequenceSizeMin: 3
let contentTypeDocument: 'document'
let contentTypeFlow: 'flow'
let contentTypeContent: 'content'
let contentTypeString: 'string'
let contentTypeText: 'text'
let hardBreakPrefixSizeMin: 2
let htmlRaw: 1
let htmlComment: 2
let htmlInstruction: 3
let htmlDeclaration: 4
let htmlCdata: 5
let htmlBasic: 6
let htmlComplete: 7
let htmlRawSizeMax: 8
let linkResourceDestinationBalanceMax: 32
let linkReferenceSizeMax: 999
let listItemValueSizeMax: 10
let numericBaseDecimal: 10
let numericBaseHexadecimal: 16
let tabSize: 4
let thematicBreakMarkerCountMin: 3
let v8MaxSafeChunkSize: 10000
}

View File

@@ -0,0 +1,44 @@
/**
* This module is compiled away!
*
* Parsing markdown comes with a couple of constants, such as minimum or maximum
* sizes of certain sequences.
* Additionally, there are a couple symbols used inside micromark.
* These are all defined here, but compiled away by scripts.
*/
export const constants = /** @type {const} */ ({
attentionSideBefore: 1, // Symbol to mark an attention sequence as before content: `*a`
attentionSideAfter: 2, // Symbol to mark an attention sequence as after content: `a*`
atxHeadingOpeningFenceSizeMax: 6, // 6 number signs is fine, 7 isnt.
autolinkDomainSizeMax: 63, // 63 characters is fine, 64 is too many.
autolinkSchemeSizeMax: 32, // 32 characters is fine, 33 is too many.
cdataOpeningString: 'CDATA[', // And preceded by `<![`.
characterGroupWhitespace: 1, // Symbol used to indicate a character is whitespace
characterGroupPunctuation: 2, // Symbol used to indicate a character is punctuation
characterReferenceDecimalSizeMax: 7, // `&#9999999;`.
characterReferenceHexadecimalSizeMax: 6, // `&#xff9999;`.
characterReferenceNamedSizeMax: 31, // `&CounterClockwiseContourIntegral;`.
codeFencedSequenceSizeMin: 3, // At least 3 ticks or tildes are needed.
contentTypeDocument: 'document',
contentTypeFlow: 'flow',
contentTypeContent: 'content',
contentTypeString: 'string',
contentTypeText: 'text',
hardBreakPrefixSizeMin: 2, // At least 2 trailing spaces are needed.
htmlRaw: 1, // Symbol for `<script>`
htmlComment: 2, // Symbol for `<!---->`
htmlInstruction: 3, // Symbol for `<?php?>`
htmlDeclaration: 4, // Symbol for `<!doctype>`
htmlCdata: 5, // Symbol for `<![CDATA[]]>`
htmlBasic: 6, // Symbol for `<div`
htmlComplete: 7, // Symbol for `<x>`
htmlRawSizeMax: 8, // Length of `textarea`.
linkResourceDestinationBalanceMax: 32, // See: <https://spec.commonmark.org/0.30/#link-destination>, <https://github.com/remarkjs/react-markdown/issues/658#issuecomment-984345577>
linkReferenceSizeMax: 999, // See: <https://spec.commonmark.org/0.30/#link-label>
listItemValueSizeMax: 10, // See: <https://spec.commonmark.org/0.30/#ordered-list-marker>
numericBaseDecimal: 10,
numericBaseHexadecimal: 0x10,
tabSize: 4, // Tabs have a hard-coded size of 4, per CommonMark.
thematicBreakMarkerCountMin: 3, // At least 3 asterisks, dashes, or underscores are needed.
v8MaxSafeChunkSize: 10000 // V8 (and potentially others) have problems injecting giant arrays into other arrays, hence we operate in chunks.
})

View File

@@ -0,0 +1,4 @@
export {codes} from './codes.js'
export {constants} from './constants.js'
export {types} from './types.js'
export {values} from './values.js'

View File

@@ -0,0 +1,4 @@
export {codes} from './codes.js'
export {constants} from './constants.js'
export {types} from './types.js'
export {values} from './values.js'

View File

@@ -0,0 +1,105 @@
export namespace types {
let data: 'data'
let whitespace: 'whitespace'
let lineEnding: 'lineEnding'
let lineEndingBlank: 'lineEndingBlank'
let linePrefix: 'linePrefix'
let lineSuffix: 'lineSuffix'
let atxHeading: 'atxHeading'
let atxHeadingSequence: 'atxHeadingSequence'
let atxHeadingText: 'atxHeadingText'
let autolink: 'autolink'
let autolinkEmail: 'autolinkEmail'
let autolinkMarker: 'autolinkMarker'
let autolinkProtocol: 'autolinkProtocol'
let characterEscape: 'characterEscape'
let characterEscapeValue: 'characterEscapeValue'
let characterReference: 'characterReference'
let characterReferenceMarker: 'characterReferenceMarker'
let characterReferenceMarkerNumeric: 'characterReferenceMarkerNumeric'
let characterReferenceMarkerHexadecimal: 'characterReferenceMarkerHexadecimal'
let characterReferenceValue: 'characterReferenceValue'
let codeFenced: 'codeFenced'
let codeFencedFence: 'codeFencedFence'
let codeFencedFenceSequence: 'codeFencedFenceSequence'
let codeFencedFenceInfo: 'codeFencedFenceInfo'
let codeFencedFenceMeta: 'codeFencedFenceMeta'
let codeFlowValue: 'codeFlowValue'
let codeIndented: 'codeIndented'
let codeText: 'codeText'
let codeTextData: 'codeTextData'
let codeTextPadding: 'codeTextPadding'
let codeTextSequence: 'codeTextSequence'
let content: 'content'
let definition: 'definition'
let definitionDestination: 'definitionDestination'
let definitionDestinationLiteral: 'definitionDestinationLiteral'
let definitionDestinationLiteralMarker: 'definitionDestinationLiteralMarker'
let definitionDestinationRaw: 'definitionDestinationRaw'
let definitionDestinationString: 'definitionDestinationString'
let definitionLabel: 'definitionLabel'
let definitionLabelMarker: 'definitionLabelMarker'
let definitionLabelString: 'definitionLabelString'
let definitionMarker: 'definitionMarker'
let definitionTitle: 'definitionTitle'
let definitionTitleMarker: 'definitionTitleMarker'
let definitionTitleString: 'definitionTitleString'
let emphasis: 'emphasis'
let emphasisSequence: 'emphasisSequence'
let emphasisText: 'emphasisText'
let escapeMarker: 'escapeMarker'
let hardBreakEscape: 'hardBreakEscape'
let hardBreakTrailing: 'hardBreakTrailing'
let htmlFlow: 'htmlFlow'
let htmlFlowData: 'htmlFlowData'
let htmlText: 'htmlText'
let htmlTextData: 'htmlTextData'
let image: 'image'
let label: 'label'
let labelText: 'labelText'
let labelLink: 'labelLink'
let labelImage: 'labelImage'
let labelMarker: 'labelMarker'
let labelImageMarker: 'labelImageMarker'
let labelEnd: 'labelEnd'
let link: 'link'
let paragraph: 'paragraph'
let reference: 'reference'
let referenceMarker: 'referenceMarker'
let referenceString: 'referenceString'
let resource: 'resource'
let resourceDestination: 'resourceDestination'
let resourceDestinationLiteral: 'resourceDestinationLiteral'
let resourceDestinationLiteralMarker: 'resourceDestinationLiteralMarker'
let resourceDestinationRaw: 'resourceDestinationRaw'
let resourceDestinationString: 'resourceDestinationString'
let resourceMarker: 'resourceMarker'
let resourceTitle: 'resourceTitle'
let resourceTitleMarker: 'resourceTitleMarker'
let resourceTitleString: 'resourceTitleString'
let setextHeading: 'setextHeading'
let setextHeadingText: 'setextHeadingText'
let setextHeadingLine: 'setextHeadingLine'
let setextHeadingLineSequence: 'setextHeadingLineSequence'
let strong: 'strong'
let strongSequence: 'strongSequence'
let strongText: 'strongText'
let thematicBreak: 'thematicBreak'
let thematicBreakSequence: 'thematicBreakSequence'
let blockQuote: 'blockQuote'
let blockQuotePrefix: 'blockQuotePrefix'
let blockQuoteMarker: 'blockQuoteMarker'
let blockQuotePrefixWhitespace: 'blockQuotePrefixWhitespace'
let listOrdered: 'listOrdered'
let listUnordered: 'listUnordered'
let listItemIndent: 'listItemIndent'
let listItemMarker: 'listItemMarker'
let listItemPrefix: 'listItemPrefix'
let listItemPrefixWhitespace: 'listItemPrefixWhitespace'
let listItemValue: 'listItemValue'
let chunkDocument: 'chunkDocument'
let chunkContent: 'chunkContent'
let chunkFlow: 'chunkFlow'
let chunkText: 'chunkText'
let chunkString: 'chunkString'
}

View File

@@ -0,0 +1,453 @@
/**
* This module is compiled away!
*
* Here is the list of all types of tokens exposed by micromark, with a short
* explanation of what they include and where they are found.
* In picking names, generally, the rule is to be as explicit as possible
* instead of reusing names.
* For example, there is a `definitionDestination` and a `resourceDestination`,
* instead of one shared name.
*/
// Note: when changing the next record, you must also change `TokenTypeMap`
// in `micromark-util-types/index.d.ts`.
export const types = /** @type {const} */ ({
// Generic type for data, such as in a title, a destination, etc.
data: 'data',
// Generic type for syntactic whitespace (tabs, virtual spaces, spaces).
// Such as, between a fenced code fence and an info string.
whitespace: 'whitespace',
// Generic type for line endings (line feed, carriage return, carriage return +
// line feed).
lineEnding: 'lineEnding',
// A line ending, but ending a blank line.
lineEndingBlank: 'lineEndingBlank',
// Generic type for whitespace (tabs, virtual spaces, spaces) at the start of a
// line.
linePrefix: 'linePrefix',
// Generic type for whitespace (tabs, virtual spaces, spaces) at the end of a
// line.
lineSuffix: 'lineSuffix',
// Whole ATX heading:
//
// ```markdown
// #
// ## Alpha
// ### Bravo ###
// ```
//
// Includes `atxHeadingSequence`, `whitespace`, `atxHeadingText`.
atxHeading: 'atxHeading',
// Sequence of number signs in an ATX heading (`###`).
atxHeadingSequence: 'atxHeadingSequence',
// Content in an ATX heading (`alpha`).
// Includes text.
atxHeadingText: 'atxHeadingText',
// Whole autolink (`<https://example.com>` or `<admin@example.com>`)
// Includes `autolinkMarker` and `autolinkProtocol` or `autolinkEmail`.
autolink: 'autolink',
// Email autolink w/o markers (`admin@example.com`)
autolinkEmail: 'autolinkEmail',
// Marker around an `autolinkProtocol` or `autolinkEmail` (`<` or `>`).
autolinkMarker: 'autolinkMarker',
// Protocol autolink w/o markers (`https://example.com`)
autolinkProtocol: 'autolinkProtocol',
// A whole character escape (`\-`).
// Includes `escapeMarker` and `characterEscapeValue`.
characterEscape: 'characterEscape',
// The escaped character (`-`).
characterEscapeValue: 'characterEscapeValue',
// A whole character reference (`&amp;`, `&#8800;`, or `&#x1D306;`).
// Includes `characterReferenceMarker`, an optional
// `characterReferenceMarkerNumeric`, in which case an optional
// `characterReferenceMarkerHexadecimal`, and a `characterReferenceValue`.
characterReference: 'characterReference',
// The start or end marker (`&` or `;`).
characterReferenceMarker: 'characterReferenceMarker',
// Mark reference as numeric (`#`).
characterReferenceMarkerNumeric: 'characterReferenceMarkerNumeric',
// Mark reference as numeric (`x` or `X`).
characterReferenceMarkerHexadecimal: 'characterReferenceMarkerHexadecimal',
// Value of character reference w/o markers (`amp`, `8800`, or `1D306`).
characterReferenceValue: 'characterReferenceValue',
// Whole fenced code:
//
// ````markdown
// ```js
// alert(1)
// ```
// ````
codeFenced: 'codeFenced',
// A fenced code fence, including whitespace, sequence, info, and meta
// (` ```js `).
codeFencedFence: 'codeFencedFence',
// Sequence of grave accent or tilde characters (` ``` `) in a fence.
codeFencedFenceSequence: 'codeFencedFenceSequence',
// Info word (`js`) in a fence.
// Includes string.
codeFencedFenceInfo: 'codeFencedFenceInfo',
// Meta words (`highlight="1"`) in a fence.
// Includes string.
codeFencedFenceMeta: 'codeFencedFenceMeta',
// A line of code.
codeFlowValue: 'codeFlowValue',
// Whole indented code:
//
// ```markdown
// alert(1)
// ```
//
// Includes `lineEnding`, `linePrefix`, and `codeFlowValue`.
codeIndented: 'codeIndented',
// A text code (``` `alpha` ```).
// Includes `codeTextSequence`, `codeTextData`, `lineEnding`, and can include
// `codeTextPadding`.
codeText: 'codeText',
codeTextData: 'codeTextData',
// A space or line ending right after or before a tick.
codeTextPadding: 'codeTextPadding',
// A text code fence (` `` `).
codeTextSequence: 'codeTextSequence',
// Whole content:
//
// ```markdown
// [a]: b
// c
// =
// d
// ```
//
// Includes `paragraph` and `definition`.
content: 'content',
// Whole definition:
//
// ```markdown
// [micromark]: https://github.com/micromark/micromark
// ```
//
// Includes `definitionLabel`, `definitionMarker`, `whitespace`,
// `definitionDestination`, and optionally `lineEnding` and `definitionTitle`.
definition: 'definition',
// Destination of a definition (`https://github.com/micromark/micromark` or
// `<https://github.com/micromark/micromark>`).
// Includes `definitionDestinationLiteral` or `definitionDestinationRaw`.
definitionDestination: 'definitionDestination',
// Enclosed destination of a definition
// (`<https://github.com/micromark/micromark>`).
// Includes `definitionDestinationLiteralMarker` and optionally
// `definitionDestinationString`.
definitionDestinationLiteral: 'definitionDestinationLiteral',
// Markers of an enclosed definition destination (`<` or `>`).
definitionDestinationLiteralMarker: 'definitionDestinationLiteralMarker',
// Unenclosed destination of a definition
// (`https://github.com/micromark/micromark`).
// Includes `definitionDestinationString`.
definitionDestinationRaw: 'definitionDestinationRaw',
// Text in an destination (`https://github.com/micromark/micromark`).
// Includes string.
definitionDestinationString: 'definitionDestinationString',
// Label of a definition (`[micromark]`).
// Includes `definitionLabelMarker` and `definitionLabelString`.
definitionLabel: 'definitionLabel',
// Markers of a definition label (`[` or `]`).
definitionLabelMarker: 'definitionLabelMarker',
// Value of a definition label (`micromark`).
// Includes string.
definitionLabelString: 'definitionLabelString',
// Marker between a label and a destination (`:`).
definitionMarker: 'definitionMarker',
// Title of a definition (`"x"`, `'y'`, or `(z)`).
// Includes `definitionTitleMarker` and optionally `definitionTitleString`.
definitionTitle: 'definitionTitle',
// Marker around a title of a definition (`"`, `'`, `(`, or `)`).
definitionTitleMarker: 'definitionTitleMarker',
// Data without markers in a title (`z`).
// Includes string.
definitionTitleString: 'definitionTitleString',
// Emphasis (`*alpha*`).
// Includes `emphasisSequence` and `emphasisText`.
emphasis: 'emphasis',
// Sequence of emphasis markers (`*` or `_`).
emphasisSequence: 'emphasisSequence',
// Emphasis text (`alpha`).
// Includes text.
emphasisText: 'emphasisText',
// The character escape marker (`\`).
escapeMarker: 'escapeMarker',
// A hard break created with a backslash (`\\n`).
// Note: does not include the line ending.
hardBreakEscape: 'hardBreakEscape',
// A hard break created with trailing spaces (` \n`).
// Does not include the line ending.
hardBreakTrailing: 'hardBreakTrailing',
// Flow HTML:
//
// ```markdown
// <div
// ```
//
// Inlcudes `lineEnding`, `htmlFlowData`.
htmlFlow: 'htmlFlow',
htmlFlowData: 'htmlFlowData',
// HTML in text (the tag in `a <i> b`).
// Includes `lineEnding`, `htmlTextData`.
htmlText: 'htmlText',
htmlTextData: 'htmlTextData',
// Whole image (`![alpha](bravo)`, `![alpha][bravo]`, `![alpha][]`, or
// `![alpha]`).
// Includes `label` and an optional `resource` or `reference`.
image: 'image',
// Whole link label (`[*alpha*]`).
// Includes `labelLink` or `labelImage`, `labelText`, and `labelEnd`.
label: 'label',
// Text in an label (`*alpha*`).
// Includes text.
labelText: 'labelText',
// Start a link label (`[`).
// Includes a `labelMarker`.
labelLink: 'labelLink',
// Start an image label (`![`).
// Includes `labelImageMarker` and `labelMarker`.
labelImage: 'labelImage',
// Marker of a label (`[` or `]`).
labelMarker: 'labelMarker',
// Marker to start an image (`!`).
labelImageMarker: 'labelImageMarker',
// End a label (`]`).
// Includes `labelMarker`.
labelEnd: 'labelEnd',
// Whole link (`[alpha](bravo)`, `[alpha][bravo]`, `[alpha][]`, or `[alpha]`).
// Includes `label` and an optional `resource` or `reference`.
link: 'link',
// Whole paragraph:
//
// ```markdown
// alpha
// bravo.
// ```
//
// Includes text.
paragraph: 'paragraph',
// A reference (`[alpha]` or `[]`).
// Includes `referenceMarker` and an optional `referenceString`.
reference: 'reference',
// A reference marker (`[` or `]`).
referenceMarker: 'referenceMarker',
// Reference text (`alpha`).
// Includes string.
referenceString: 'referenceString',
// A resource (`(https://example.com "alpha")`).
// Includes `resourceMarker`, an optional `resourceDestination` with an optional
// `whitespace` and `resourceTitle`.
resource: 'resource',
// A resource destination (`https://example.com`).
// Includes `resourceDestinationLiteral` or `resourceDestinationRaw`.
resourceDestination: 'resourceDestination',
// A literal resource destination (`<https://example.com>`).
// Includes `resourceDestinationLiteralMarker` and optionally
// `resourceDestinationString`.
resourceDestinationLiteral: 'resourceDestinationLiteral',
// A resource destination marker (`<` or `>`).
resourceDestinationLiteralMarker: 'resourceDestinationLiteralMarker',
// A raw resource destination (`https://example.com`).
// Includes `resourceDestinationString`.
resourceDestinationRaw: 'resourceDestinationRaw',
// Resource destination text (`https://example.com`).
// Includes string.
resourceDestinationString: 'resourceDestinationString',
// A resource marker (`(` or `)`).
resourceMarker: 'resourceMarker',
// A resource title (`"alpha"`, `'alpha'`, or `(alpha)`).
// Includes `resourceTitleMarker` and optionally `resourceTitleString`.
resourceTitle: 'resourceTitle',
// A resource title marker (`"`, `'`, `(`, or `)`).
resourceTitleMarker: 'resourceTitleMarker',
// Resource destination title (`alpha`).
// Includes string.
resourceTitleString: 'resourceTitleString',
// Whole setext heading:
//
// ```markdown
// alpha
// bravo
// =====
// ```
//
// Includes `setextHeadingText`, `lineEnding`, `linePrefix`, and
// `setextHeadingLine`.
setextHeading: 'setextHeading',
// Content in a setext heading (`alpha\nbravo`).
// Includes text.
setextHeadingText: 'setextHeadingText',
// Underline in a setext heading, including whitespace suffix (`==`).
// Includes `setextHeadingLineSequence`.
setextHeadingLine: 'setextHeadingLine',
// Sequence of equals or dash characters in underline in a setext heading (`-`).
setextHeadingLineSequence: 'setextHeadingLineSequence',
// Strong (`**alpha**`).
// Includes `strongSequence` and `strongText`.
strong: 'strong',
// Sequence of strong markers (`**` or `__`).
strongSequence: 'strongSequence',
// Strong text (`alpha`).
// Includes text.
strongText: 'strongText',
// Whole thematic break:
//
// ```markdown
// * * *
// ```
//
// Includes `thematicBreakSequence` and `whitespace`.
thematicBreak: 'thematicBreak',
// A sequence of one or more thematic break markers (`***`).
thematicBreakSequence: 'thematicBreakSequence',
// Whole block quote:
//
// ```markdown
// > a
// >
// > b
// ```
//
// Includes `blockQuotePrefix` and flow.
blockQuote: 'blockQuote',
// The `>` or `> ` of a block quote.
blockQuotePrefix: 'blockQuotePrefix',
// The `>` of a block quote prefix.
blockQuoteMarker: 'blockQuoteMarker',
// The optional ` ` of a block quote prefix.
blockQuotePrefixWhitespace: 'blockQuotePrefixWhitespace',
// Whole unordered list:
//
// ```markdown
// - a
// b
// ```
//
// Includes `listItemPrefix`, flow, and optionally `listItemIndent` on further
// lines.
listOrdered: 'listOrdered',
// Whole ordered list:
//
// ```markdown
// 1. a
// b
// ```
//
// Includes `listItemPrefix`, flow, and optionally `listItemIndent` on further
// lines.
listUnordered: 'listUnordered',
// The indent of further list item lines.
listItemIndent: 'listItemIndent',
// A marker, as in, `*`, `+`, `-`, `.`, or `)`.
listItemMarker: 'listItemMarker',
// The thing that starts a list item, such as `1. `.
// Includes `listItemValue` if ordered, `listItemMarker`, and
// `listItemPrefixWhitespace` (unless followed by a line ending).
listItemPrefix: 'listItemPrefix',
// The whitespace after a marker.
listItemPrefixWhitespace: 'listItemPrefixWhitespace',
// The numerical value of an ordered item.
listItemValue: 'listItemValue',
// Internal types used for subtokenizers, compiled away
chunkDocument: 'chunkDocument',
chunkContent: 'chunkContent',
chunkFlow: 'chunkFlow',
chunkText: 'chunkText',
chunkString: 'chunkString'
})

View File

@@ -0,0 +1,101 @@
export namespace values {
let ht: '\t'
let lf: '\n'
let cr: '\r'
let space: ' '
let exclamationMark: '!'
let quotationMark: '"'
let numberSign: '#'
let dollarSign: '$'
let percentSign: '%'
let ampersand: '&'
let apostrophe: "'"
let leftParenthesis: '('
let rightParenthesis: ')'
let asterisk: '*'
let plusSign: '+'
let comma: ','
let dash: '-'
let dot: '.'
let slash: '/'
let digit0: '0'
let digit1: '1'
let digit2: '2'
let digit3: '3'
let digit4: '4'
let digit5: '5'
let digit6: '6'
let digit7: '7'
let digit8: '8'
let digit9: '9'
let colon: ':'
let semicolon: ';'
let lessThan: '<'
let equalsTo: '='
let greaterThan: '>'
let questionMark: '?'
let atSign: '@'
let uppercaseA: 'A'
let uppercaseB: 'B'
let uppercaseC: 'C'
let uppercaseD: 'D'
let uppercaseE: 'E'
let uppercaseF: 'F'
let uppercaseG: 'G'
let uppercaseH: 'H'
let uppercaseI: 'I'
let uppercaseJ: 'J'
let uppercaseK: 'K'
let uppercaseL: 'L'
let uppercaseM: 'M'
let uppercaseN: 'N'
let uppercaseO: 'O'
let uppercaseP: 'P'
let uppercaseQ: 'Q'
let uppercaseR: 'R'
let uppercaseS: 'S'
let uppercaseT: 'T'
let uppercaseU: 'U'
let uppercaseV: 'V'
let uppercaseW: 'W'
let uppercaseX: 'X'
let uppercaseY: 'Y'
let uppercaseZ: 'Z'
let leftSquareBracket: '['
let backslash: '\\'
let rightSquareBracket: ']'
let caret: '^'
let underscore: '_'
let graveAccent: '`'
let lowercaseA: 'a'
let lowercaseB: 'b'
let lowercaseC: 'c'
let lowercaseD: 'd'
let lowercaseE: 'e'
let lowercaseF: 'f'
let lowercaseG: 'g'
let lowercaseH: 'h'
let lowercaseI: 'i'
let lowercaseJ: 'j'
let lowercaseK: 'k'
let lowercaseL: 'l'
let lowercaseM: 'm'
let lowercaseN: 'n'
let lowercaseO: 'o'
let lowercaseP: 'p'
let lowercaseQ: 'q'
let lowercaseR: 'r'
let lowercaseS: 's'
let lowercaseT: 't'
let lowercaseU: 'u'
let lowercaseV: 'v'
let lowercaseW: 'w'
let lowercaseX: 'x'
let lowercaseY: 'y'
let lowercaseZ: 'z'
let leftCurlyBrace: '{'
let verticalBar: '|'
let rightCurlyBrace: '}'
let tilde: '~'
let replacementCharacter: '<27>'
}

View File

@@ -0,0 +1,109 @@
/**
* This module is compiled away!
*
* While micromark works based on character codes, this module includes the
* string versions of em.
* The C0 block, except for LF, CR, HT, and w/ the replacement character added,
* are available here.
*/
export const values = /** @type {const} */ ({
ht: '\t',
lf: '\n',
cr: '\r',
space: ' ',
exclamationMark: '!',
quotationMark: '"',
numberSign: '#',
dollarSign: '$',
percentSign: '%',
ampersand: '&',
apostrophe: "'",
leftParenthesis: '(',
rightParenthesis: ')',
asterisk: '*',
plusSign: '+',
comma: ',',
dash: '-',
dot: '.',
slash: '/',
digit0: '0',
digit1: '1',
digit2: '2',
digit3: '3',
digit4: '4',
digit5: '5',
digit6: '6',
digit7: '7',
digit8: '8',
digit9: '9',
colon: ':',
semicolon: ';',
lessThan: '<',
equalsTo: '=',
greaterThan: '>',
questionMark: '?',
atSign: '@',
uppercaseA: 'A',
uppercaseB: 'B',
uppercaseC: 'C',
uppercaseD: 'D',
uppercaseE: 'E',
uppercaseF: 'F',
uppercaseG: 'G',
uppercaseH: 'H',
uppercaseI: 'I',
uppercaseJ: 'J',
uppercaseK: 'K',
uppercaseL: 'L',
uppercaseM: 'M',
uppercaseN: 'N',
uppercaseO: 'O',
uppercaseP: 'P',
uppercaseQ: 'Q',
uppercaseR: 'R',
uppercaseS: 'S',
uppercaseT: 'T',
uppercaseU: 'U',
uppercaseV: 'V',
uppercaseW: 'W',
uppercaseX: 'X',
uppercaseY: 'Y',
uppercaseZ: 'Z',
leftSquareBracket: '[',
backslash: '\\',
rightSquareBracket: ']',
caret: '^',
underscore: '_',
graveAccent: '`',
lowercaseA: 'a',
lowercaseB: 'b',
lowercaseC: 'c',
lowercaseD: 'd',
lowercaseE: 'e',
lowercaseF: 'f',
lowercaseG: 'g',
lowercaseH: 'h',
lowercaseI: 'i',
lowercaseJ: 'j',
lowercaseK: 'k',
lowercaseL: 'l',
lowercaseM: 'm',
lowercaseN: 'n',
lowercaseO: 'o',
lowercaseP: 'p',
lowercaseQ: 'q',
lowercaseR: 'r',
lowercaseS: 's',
lowercaseT: 't',
lowercaseU: 'u',
lowercaseV: 'v',
lowercaseW: 'w',
lowercaseX: 'x',
lowercaseY: 'y',
lowercaseZ: 'z',
leftCurlyBrace: '{',
verticalBar: '|',
rightCurlyBrace: '}',
tilde: '~',
replacementCharacter: '<27>'
})

View File

@@ -0,0 +1,35 @@
{
"name": "micromark-util-symbol",
"version": "2.0.0",
"description": "micromark utility with symbols",
"license": "MIT",
"keywords": [
"micromark",
"util",
"utility",
"symbol"
],
"repository": "https://github.com/micromark/micromark/tree/main/packages/micromark-util-symbol",
"bugs": "https://github.com/micromark/micromark/issues",
"funding": [
{
"type": "GitHub Sponsors",
"url": "https://github.com/sponsors/unifiedjs"
},
{
"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",
"files": [
"lib/"
],
"exports": "./lib/default.js",
"xo": false
}

View File

@@ -0,0 +1,168 @@
# micromark-util-symbol
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
[micromark][] utility with symbols.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package exposes constants used throughout the micromark ecosystem.
## When should I use this?
This package is useful when you are making your own micromark extensions.
Its useful to reference these constants by name instead of value while
developing.
[`micromark-build`][micromark-build] compiles them away for production code.
## Install
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
```sh
npm install micromark-util-symbol
```
In Deno with [`esm.sh`][esmsh]:
```js
import * as symbol from 'https://esm.sh/micromark-util-symbol@1'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import * as symbol from 'https://esm.sh/micromark-util-symbol@1?bundle'
</script>
```
## Use
```js
import {codes, constants, types, values} from 'micromark-util-symbol'
console.log(codes.atSign) // 64
console.log(constants.characterReferenceNamedSizeMax) // 31
console.log(types.definitionDestinationRaw) // 'definitionDestinationRaw'
console.log(values.atSign) // '@'
```
## API
This package exports the identifiers `codes`, `constants`, `types`, and
`values`.
There is no default export.
Each identifier is an object mapping strings to values.
See the code for the exposed data.
## Types
This package is fully typed with [TypeScript][].
It exports no additional types.
## Compatibility
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`micromark-util-symbol@^2`, compatible with Node.js 16.
This package works with `micromark@^3`.
## Security
This package is safe.
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-symbol.svg
[downloads]: https://www.npmjs.com/package/micromark-util-symbol
[bundle-size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-util-symbol
[bundle-size]: https://bundlejs.com/?q=micromark-util-symbol
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/main/security.md
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md
[support]: https://github.com/micromark/.github/blob/main/support.md
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md
[typescript]: https://www.typescriptlang.org
[micromark]: https://github.com/micromark/micromark
[micromark-build]: https://github.com/micromark/micromark/tree/main/packages/micromark-build

85
node_modules/micromark/package.json generated vendored Normal file
View File

@@ -0,0 +1,85 @@
{
"name": "micromark",
"version": "4.0.0",
"description": "small commonmark compliant markdown parser with positional info and concrete tokens",
"license": "MIT",
"keywords": [
"commonmark",
"compiler",
"gfm",
"html",
"lexer",
"markdown",
"markup",
"md",
"unified",
"parse",
"parser",
"plugin",
"process",
"remark",
"render",
"renderer",
"token",
"tokenizer"
],
"repository": "https://github.com/micromark/micromark/tree/main/packages/micromark",
"bugs": "https://github.com/micromark/micromark/issues",
"funding": [
{
"type": "GitHub Sponsors",
"url": "https://github.com/sponsors/unifiedjs"
},
{
"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",
"files": [
"dev/",
"lib/",
"index.d.ts",
"index.js",
"stream.d.ts",
"stream.js"
],
"exports": {
".": {
"development": "./dev/index.js",
"default": "./index.js"
},
"./stream": {
"development": "./dev/stream.js",
"default": "./stream.js"
}
},
"dependencies": {
"@types/debug": "^4.0.0",
"debug": "^4.0.0",
"decode-named-character-reference": "^1.0.0",
"devlop": "^1.0.0",
"micromark-core-commonmark": "^2.0.0",
"micromark-factory-space": "^2.0.0",
"micromark-util-character": "^2.0.0",
"micromark-util-chunked": "^2.0.0",
"micromark-util-combine-extensions": "^2.0.0",
"micromark-util-decode-numeric-character-reference": "^2.0.0",
"micromark-util-encode": "^2.0.0",
"micromark-util-normalize-identifier": "^2.0.0",
"micromark-util-resolve-all": "^2.0.0",
"micromark-util-sanitize-uri": "^2.0.0",
"micromark-util-subtokenize": "^2.0.0",
"micromark-util-symbol": "^2.0.0",
"micromark-util-types": "^2.0.0"
},
"scripts": {
"build": "micromark-build"
},
"xo": false
}

491
node_modules/micromark/readme.md generated vendored Normal file
View File

@@ -0,0 +1,491 @@
# micromark
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
Markdown parser.
> **Note**: this is the `micromark` package from the micromark monorepo.
> See the [monorepo readme][micromark] for more on the project.
> See this readme for how to use it.
## Feature highlights
<!-- Note: this section has to be in sync with the monorepo readme. -->
* [x] **[compliant][commonmark]** (100% to CommonMark)
* [x] **[extensions][]** (100% [GFM][], 100% [MDX.js][mdxjs], [directives][],
[frontmatter][], [math][])
* [x] **[safe][security]** (by default)
* [x] **[robust][test]** (±2k tests, 100% coverage, fuzz testing)
* [x] **[small][size-debug]** (smallest CM parser at ±14kb)
## Contents
* [When should I use this?](#when-should-i-use-this)
* [What is this?](#what-is-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`micromark(value[, encoding][, options])`](#micromarkvalue-encoding-options)
* [`stream(options?)`](#streamoptions)
* [`Options`](#options)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Contribute](#contribute)
* [Sponsor](#sponsor)
* [License](#license)
## When should I use this?
<!-- Note: this section has to be in sync with the monorepo readme. -->
* If you *just* want to turn markdown into HTML (with maybe a few extensions)
* If you want to do *really complex things* with markdown
See [§ Comparison][comparison] for more info
## What is this?
<!-- Note: this section has to be in sync with the monorepo readme. -->
`micromark` is an open source markdown parser written in JavaScript.
Its implemented as a state machine that emits concrete tokens, so that every
byte is accounted for, with positional info.
It then compiles those tokens directly to HTML, but other tools can take the
data and for example build an AST which is easier to work with
([`mdast-util-to-markdown`][mdast-util-to-markdown]).
While most markdown parsers work towards compliancy with CommonMark (or GFM),
this project goes further by following how the reference parsers (`cmark`,
`cmark-gfm`) work, which is confirmed with thousands of extra tests.
Other than CommonMark and GFM, micromark also supports common extensions to
markdown such as MDX, math, and frontmatter.
These npm packages have a sibling project in Rust:
[`markdown-rs`][markdown-rs].
* to learn markdown, see this [cheatsheet and tutorial][cheat]
* for more about us, see [`unifiedjs.com`][site]
* for updates, see [Twitter][]
* for questions, see [Discussions][chat]
* to help, see [contribute][] and [sponsor][] below
## Install
<!-- Note: this section has to be in sync with the monorepo readme. -->
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
```sh
npm install micromark
```
In Deno with [`esm.sh`][esmsh]:
```js
import {micromark} from 'https://esm.sh/micromark@3'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {micromark} from 'https://esm.sh/micromark@3?bundle'
</script>
```
## Use
<!-- Note: this section has to be in sync with the monorepo readme. -->
Typical use (buffering):
```js
import {micromark} from 'micromark'
console.log(micromark('## Hello, *world*!'))
```
Yields:
```html
<h2>Hello, <em>world</em>!</h2>
```
You can pass extensions (in this case [`micromark-extension-gfm`][gfm]):
```js
import {micromark} from 'micromark'
import {gfm, gfmHtml} from 'micromark-extension-gfm'
const value = '* [x] contact@example.com ~~strikethrough~~'
const result = micromark(value, {
extensions: [gfm()],
htmlExtensions: [gfmHtml()]
})
console.log(result)
```
Yields:
```html
<ul>
<li><input checked="" disabled="" type="checkbox"> <a href="mailto:contact@example.com">contact@example.com</a> <del>strikethrough</del></li>
</ul>
```
Streaming interface:
```js
import {createReadStream} from 'node:fs'
import {stream} from 'micromark/stream'
createReadStream('example.md')
.on('error', handleError)
.pipe(stream())
.pipe(process.stdout)
function handleError(error) {
// Handle your error here!
throw error
}
```
## API
`micromark` core has two entries in its export map: `micromark` and
`micromark/stream`.
`micromark` exports the identifier [`micromark`][api-micromark].
`micromark/stream` exports the identifier [`stream`][api-stream].
There are no default exports.
The export map supports the [`development` condition][development].
Run `node --conditions development module.js` to get instrumented dev code.
Without this condition, production code is loaded.
See [§ Size & debug][size-debug] for more info.
### `micromark(value[, encoding][, options])`
Compile markdown to HTML.
> Note: which encodings are supported depends on the engine.
> For info on Node.js, see *[WHATWG supported encodings][encoding]*.
###### Parameters
* `value` (`string` or [`Uint8Array`][uint8-array])
— markdown to parse
* `encoding` (`string`, default: `'utf8'`)
— [character encoding][encoding] to understand `value` as when its a
[`Uint8Array`][uint8-array]
* `options` ([`Options`][api-options], optional)
— configuration
###### Returns
Compiled HTML (`string`).
### `stream(options?)`
Create a duplex (readable and writable) stream.
Some of the work to parse markdown can be done streaming, but in the
end buffering is required.
micromark does not handle errors for you, so you must handle errors on whatever
streams you pipe into it.
As markdown does not know errors, `micromark` itself does not emit errors.
###### Parameters
* `options` ([`Options`][api-options], optional)
— configuration
###### Returns
Duplex stream.
### `Options`
Configuration (TypeScript type).
##### Fields
###### `allowDangerousHtml`
Whether to allow (dangerous) HTML (`boolean`, default: `false`).
The default is `false`, which still parses the HTML according to `CommonMark`
but shows the HTML as text instead of as elements.
Pass `true` for trusted content to get actual HTML elements.
See [§ Security][security].
###### `allowDangerousProtocol`
Whether to allow dangerous protocols in links and images (`boolean`, default:
`false`).
The default is `false`, which drops URLs in links and images that use dangerous
protocols.
Pass `true` for trusted content to support all protocols.
URLs that have no protocol (which means its relative to the current page, such
as `./some/page.html`) and URLs that have a safe protocol (for images: `http`,
`https`; for links: `http`, `https`, `irc`, `ircs`, `mailto`, `xmpp`), are
safe.
All other URLs are dangerous and dropped.
See [§ Security][security].
###### `defaultLineEnding`
Default line ending to use when compiling to HTML, for line endings not in
`value` (`'\r'`, `'\n'`, or `'\r\n'`; default: first line ending or `'\n'`).
Generally, `micromark` copies line endings (`\r`, `\n`, `\r\n`) in the markdown
document over to the compiled HTML.
In some cases, such as `> a`, CommonMark requires that extra line endings are
added: `<blockquote>\n<p>a</p>\n</blockquote>`.
To create that line ending, the document is checked for the first line ending
that is used.
If there is no line ending, `defaultLineEnding` is used.
If that isnt configured, `\n` is used.
###### `extensions`
Array of syntax extensions (`Array<SyntaxExtension>`, default: `[]`).
See [§ Extensions][extensions].
###### `htmlExtensions`
Array of syntax extensions (`Array<HtmlExtension>`, default: `[]`).
See [§ Extensions][extensions].
## Types
This package is fully typed with [TypeScript][].
It exports the additional type [`Options`][api-options].
## Compatibility
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, `micromark@^4`, compatible
with Node.js 16.
## Security
This package is safe.
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## Sponsor
<!-- Note: this section has to be in sync with the monorepo readme. -->
Support this effort and give back by sponsoring on [OpenCollective][]!
<table>
<tr valign="middle">
<td width="100%" align="center" colspan="10">
<br>
<a href="https://www.salesforce.com">Salesforce</a> 🏅<br><br>
<a href="https://www.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo/512.png" width="256"></a>
</td>
</tr>
<tr valign="middle">
<td width="20%" align="center" rowspan="2" colspan="2">
<a href="https://vercel.com">Vercel</a><br><br>
<a href="https://vercel.com"><img src="https://avatars1.githubusercontent.com/u/14985020?s=256&v=4" width="128"></a>
</td>
<td width="20%" align="center" rowspan="2" colspan="2">
<a href="https://motif.land">Motif</a><br><br>
<a href="https://motif.land"><img src="https://avatars1.githubusercontent.com/u/74457950?s=256&v=4" width="128"></a>
</td>
<td width="20%" align="center" rowspan="2" colspan="2">
<a href="https://www.hashicorp.com">HashiCorp</a><br><br>
<a href="https://www.hashicorp.com"><img src="https://avatars1.githubusercontent.com/u/761456?s=256&v=4" width="128"></a>
</td>
<td width="20%" align="center" rowspan="2" colspan="2">
<a href="https://www.gitbook.com">GitBook</a><br><br>
<a href="https://www.gitbook.com"><img src="https://avatars1.githubusercontent.com/u/7111340?s=256&v=4" width="128"></a>
</td>
<td width="20%" align="center" rowspan="2" colspan="2">
<a href="https://www.gatsbyjs.org">Gatsby</a><br><br>
<a href="https://www.gatsbyjs.org"><img src="https://avatars1.githubusercontent.com/u/12551863?s=256&v=4" width="128"></a>
</td>
</tr>
<tr valign="middle">
</tr>
<tr valign="middle">
<td width="20%" align="center" rowspan="2" colspan="2">
<a href="https://www.netlify.com">Netlify</a><br><br>
<!--OC has a sharper image-->
<a href="https://www.netlify.com"><img src="https://images.opencollective.com/netlify/4087de2/logo/256.png" width="128"></a>
</td>
<td width="10%" align="center">
<a href="https://www.coinbase.com">Coinbase</a><br><br>
<a href="https://www.coinbase.com"><img src="https://avatars1.githubusercontent.com/u/1885080?s=256&v=4" width="64"></a>
</td>
<td width="10%" align="center">
<a href="https://themeisle.com">ThemeIsle</a><br><br>
<a href="https://themeisle.com"><img src="https://avatars1.githubusercontent.com/u/58979018?s=128&v=4" width="64"></a>
</td>
<td width="10%" align="center">
<a href="https://expo.io">Expo</a><br><br>
<a href="https://expo.io"><img src="https://avatars1.githubusercontent.com/u/12504344?s=128&v=4" width="64"></a>
</td>
<td width="10%" align="center">
<a href="https://boostnote.io">Boost Note</a><br><br>
<a href="https://boostnote.io"><img src="https://images.opencollective.com/boosthub/6318083/logo/128.png" width="64"></a>
</td>
<td width="10%" align="center">
<a href="https://markdown.space">Markdown Space</a><br><br>
<a href="https://markdown.space"><img src="https://images.opencollective.com/markdown-space/e1038ed/logo/128.png" width="64"></a>
</td>
<td width="10%" align="center">
<a href="https://www.holloway.com">Holloway</a><br><br>
<a href="https://www.holloway.com"><img src="https://avatars1.githubusercontent.com/u/35904294?s=128&v=4" width="64"></a>
</td>
<td width="10%"></td>
<td width="10%"></td>
</tr>
<tr valign="middle">
<td width="100%" align="center" colspan="8">
<br>
<a href="https://opencollective.com/unified"><strong>You?</strong></a>
<br><br>
</td>
</tr>
</table>
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark.svg
[downloads]: https://www.npmjs.com/package/micromark
[bundle-size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark
[bundle-size]: https://bundlejs.com/?q=micromark
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[typescript]: https://www.typescriptlang.org
[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/main/security.md
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md
[support]: https://github.com/micromark/.github/blob/main/support.md
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md
[cheat]: https://commonmark.org/help/
[twitter]: https://twitter.com/unifiedjs
[site]: https://unifiedjs.com
[contribute]: #contribute
[uint8-array]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
[encoding]: https://nodejs.org/api/util.html#whatwg-supported-encodings
[commonmark]: https://commonmark.org
[directives]: https://github.com/micromark/micromark-extension-directive
[frontmatter]: https://github.com/micromark/micromark-extension-frontmatter
[gfm]: https://github.com/micromark/micromark-extension-gfm
[math]: https://github.com/micromark/micromark-extension-math
[mdxjs]: https://github.com/micromark/micromark-extension-mdxjs
[security]: #security
[sponsor]: #sponsor
[micromark]: https://github.com/micromark/micromark
[extensions]: https://github.com/micromark/micromark#extensions
[test]: https://github.com/micromark/micromark#test
[size-debug]: https://github.com/micromark/micromark#size--debug
[comparison]: https://github.com/micromark/micromark#comparison
[markdown-rs]: https://github.com/wooorm/markdown-rs
[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown
[api-micromark]: #micromarkvalue-encoding-options
[api-stream]: #streamoptions
[api-options]: #options

37
node_modules/micromark/stream.d.ts generated vendored Normal file
View File

@@ -0,0 +1,37 @@
/**
* Create a duplex (readable and writable) stream.
*
* Some of the work to parse markdown can be done streaming, but in the
* end buffering is required.
*
* micromark does not handle errors for you, so you must handle errors on whatever
* streams you pipe into it.
* As markdown does not know errors, `micromark` itself does not emit errors.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {MinimalDuplex}
* Duplex stream.
*/
export function stream(options?: Options | null | undefined): MinimalDuplex
export type Options = import('micromark-util-types').Options
export type Value = import('micromark-util-types').Value
export type Encoding = import('micromark-util-types').Encoding
/**
* Function called when write was successful.
*/
export type Callback = () => undefined
export type PipeOptions = {
end?: boolean | null | undefined
}
export type MinimalDuplex = Omit<
NodeJS.ReadableStream & NodeJS.WritableStream,
| 'isPaused'
| 'pause'
| 'read'
| 'resume'
| 'setEncoding'
| 'unpipe'
| 'unshift'
| 'wrap'
>

242
node_modules/micromark/stream.js generated vendored Normal file
View File

@@ -0,0 +1,242 @@
/**
* @typedef {import('micromark-util-types').Options} Options
* @typedef {import('micromark-util-types').Value} Value
* @typedef {import('micromark-util-types').Encoding} Encoding
*/
/**
* @callback Callback
* Function called when write was successful.
* @returns {undefined}
* Nothing.
*
* @typedef PipeOptions
* @property {boolean | null | undefined} [end]
*
* @typedef {Omit<NodeJS.ReadableStream & NodeJS.WritableStream, 'isPaused' | 'pause' | 'read' | 'resume' | 'setEncoding' | 'unpipe' | 'unshift' | 'wrap'>} MinimalDuplex
*/
import {EventEmitter} from 'node:events'
import {compile} from './lib/compile.js'
import {parse} from './lib/parse.js'
import {postprocess} from './lib/postprocess.js'
import {preprocess} from './lib/preprocess.js'
/**
* Create a duplex (readable and writable) stream.
*
* Some of the work to parse markdown can be done streaming, but in the
* end buffering is required.
*
* micromark does not handle errors for you, so you must handle errors on whatever
* streams you pipe into it.
* As markdown does not know errors, `micromark` itself does not emit errors.
*
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {MinimalDuplex}
* Duplex stream.
*/
export function stream(options) {
const prep = preprocess()
const tokenize = parse(options).document().write
const comp = compile(options)
/** @type {boolean} */
let ended
/** @type {MinimalDuplex} */
// @ts-expect-error `addListener` is fine.
const emitter = Object.assign(new EventEmitter(), {
end,
pipe,
readable: true,
writable: true,
write
})
return emitter
/**
* Write a chunk into memory.
*
* @overload
* @param {Value | null | undefined} [chunk]
* Slice of markdown to parse (`string` or `Uint8Array`).
* @param {Encoding | null | undefined} [encoding]
* Character encoding to understand `chunk` as when its a `Uint8Array`
* (`string`, default: `'utf8'`).
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
* Whether write was successful.
*
* @overload
* @param {Value | null | undefined} [chunk]
* Slice of markdown to parse (`string` or `Uint8Array`).
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
* Whether write was successful.
*
* @param {Value | null | undefined} [chunk]
* Slice of markdown to parse (`string` or `Uint8Array`).
* @param {Callback | Encoding | null | undefined} [encoding]
* Character encoding to understand `chunk` as when its a `Uint8Array`
* (`string`, default: `'utf8'`).
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
* Whether write was successful.
*/
function write(chunk, encoding, callback) {
if (typeof encoding === 'function') {
callback = encoding
encoding = undefined
}
if (ended) {
throw new Error('Did not expect `write` after `end`')
}
tokenize(prep(chunk || '', encoding))
if (callback) {
callback()
}
// Signal successful write.
return true
}
/**
* End the writing.
*
* Passes all arguments as a final `write`.
*
* @overload
* @param {Value | null | undefined} [chunk]
* Slice of markdown to parse (`string` or `Uint8Array`).
* @param {Encoding | null | undefined} [encoding]
* Character encoding to understand `chunk` as when its a `Uint8Array`
* (`string`, default: `'utf8'`).
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
* Whether write was successful.
*
* @overload
* @param {Value | null | undefined} [chunk]
* Slice of markdown to parse (`string` or `Uint8Array`).
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
* Whether write was successful.
*
* @overload
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
*
* @param {Callback | Value | null | undefined} [chunk]
* Slice of markdown to parse (`string` or `Uint8Array`).
* @param {Callback | Encoding | null | undefined} [encoding]
* Character encoding to understand `chunk` as when its a `Uint8Array`
* (`string`, default: `'utf8'`).
* @param {Callback | null | undefined} [callback]
* Function called when write was successful.
* @returns {boolean}
* Whether write was successful.
*/
function end(chunk, encoding, callback) {
if (typeof chunk === 'function') {
encoding = chunk
chunk = undefined
}
if (typeof encoding === 'function') {
callback = encoding
encoding = undefined
}
write(chunk, encoding, callback)
emitter.emit('data', comp(postprocess(tokenize(prep('', encoding, true)))))
emitter.emit('end')
ended = true
return true
}
/**
* Pipe the processor into a writable stream.
*
* Basically `Stream#pipe`, but inlined and simplified to keep the bundled
* size down.
* See: <https://github.com/nodejs/node/blob/43a5170/lib/internal/streams/legacy.js#L13>.
*
* @template {NodeJS.WritableStream} Stream
* @param {Stream} dest
* @param {PipeOptions | null | undefined} [options]
* @returns {Stream}
*/
function pipe(dest, options) {
emitter.on('data', ondata)
emitter.on('error', onerror)
emitter.on('end', cleanup)
emitter.on('close', cleanup)
// If the `end` option is not supplied, `dest.end()` will be
// called when the `end` or `close` events are received.
// @ts-expect-error `_isStdio` is available on `std{err,out}`
if (!dest._isStdio && (!options || options.end !== false)) {
emitter.on('end', onend)
}
dest.on('error', onerror)
dest.on('close', cleanup)
dest.emit('pipe', emitter)
return dest
/**
* End destination stream.
*
* @returns {undefined}
*/
function onend() {
if (dest.end) {
dest.end()
}
}
/**
* Handle data.
*
* @param {string} chunk
* @returns {undefined}
*/
function ondata(chunk) {
if (dest.writable) {
dest.write(chunk)
}
}
/**
* Clean listeners.
*
* @returns {undefined}
*/
function cleanup() {
emitter.removeListener('data', ondata)
emitter.removeListener('end', onend)
emitter.removeListener('error', onerror)
emitter.removeListener('end', cleanup)
emitter.removeListener('close', cleanup)
dest.removeListener('error', onerror)
dest.removeListener('close', cleanup)
}
/**
* Close dangling pipes and handle unheard errors.
*
* @param {Error | null | undefined} [error]
* @returns {undefined}
*/
function onerror(error) {
cleanup()
if (!emitter.listenerCount('error')) {
throw error // Unhandled stream error in pipe.
}
}
}
}