Urara-Blog/node_modules/.pnpm-store/v3/files/3e/198a394ee9b805c65c8e330832beac404aa9afd0b81fdf8a91d8620bc5e37c6aff36fadba9b6fe2ad8176f5bdf01174021140a2fe03189153a6398fea091bc
2022-08-14 01:14:53 +08:00

52 lines
1.6 KiB
Text

/**
* @typedef {import('micromark-util-types').InitialConstruct} InitialConstruct
* @typedef {import('micromark-util-types').FullNormalizedExtension} FullNormalizedExtension
* @typedef {import('micromark-util-types').ParseOptions} ParseOptions
* @typedef {import('micromark-util-types').ParseContext} ParseContext
* @typedef {import('micromark-util-types').Create} Create
*/
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 {text, string} from './initialize/text.js'
import {createTokenizer} from './create-tokenizer.js'
import * as defaultConstructs from './constructs.js'
/**
* @param {ParseOptions} [options]
* @returns {ParseContext}
*/
export function parse(options = {}) {
/** @type {FullNormalizedExtension} */
// @ts-expect-error `defaultConstructs` is full, so the result will be too.
const constructs = combineExtensions(
// @ts-expect-error Same as above.
[defaultConstructs].concat(options.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)
}
}
}