Urara-Blog/node_modules/.pnpm-store/v3/files/5a/512f2786c7f66323f7fa0552e68a200216b97bc485b8099c593375c1eb85fd394ed2c2cc99491416dbf0ec6fac4c63089b02e53c8d6ac26f9ebc79b1853f73
2022-08-14 01:14:53 +08:00

92 lines
2.1 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @typedef {import('micromark-util-types').Effects} Effects
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Code} Code
*/
import {factorySpace} from 'micromark-factory-space'
import {markdownLineEnding} from 'micromark-util-character'
/**
* @param {Effects} effects
* @param {State} ok
* @param {State} nok
* @param {string} type
* @param {string} markerType
* @param {string} stringType
* @returns {State}
*/
// eslint-disable-next-line max-params
export function factoryTitle(effects, ok, nok, type, markerType, stringType) {
/** @type {NonNullable<Code>} */
let marker
return start
/** @type {State} */
function start(code) {
effects.enter(type)
effects.enter(markerType)
effects.consume(code)
effects.exit(markerType)
marker = code === 40 ? 41 : code
return atFirstTitleBreak
}
/** @type {State} */
function atFirstTitleBreak(code) {
if (code === marker) {
effects.enter(markerType)
effects.consume(code)
effects.exit(markerType)
effects.exit(type)
return ok
}
effects.enter(stringType)
return atTitleBreak(code)
}
/** @type {State} */
function atTitleBreak(code) {
if (code === marker) {
effects.exit(stringType)
return atFirstTitleBreak(marker)
}
if (code === null) {
return nok(code)
} // Note: blank lines cant exist in content.
if (markdownLineEnding(code)) {
effects.enter('lineEnding')
effects.consume(code)
effects.exit('lineEnding')
return factorySpace(effects, atTitleBreak, 'linePrefix')
}
effects.enter('chunkString', {
contentType: 'string'
})
return title(code)
}
/** @type {State} */
function title(code) {
if (code === marker || code === null || markdownLineEnding(code)) {
effects.exit('chunkString')
return atTitleBreak(code)
}
effects.consume(code)
return code === 92 ? titleEscape : title
}
/** @type {State} */
function titleEscape(code) {
if (code === marker || code === 92) {
effects.consume(code)
return title
}
return title(code)
}
}