Urara-Blog/node_modules/.pnpm-store/v3/files/af/3438c041d85a2137f319e54be35984f11130447fe410e216e20a374a002e1baab8d157b66adf9505ad38125faf39a8c2fb0ac7bd85a2aa12cd3de6fcfa4da2
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)
}
}
}