Urara-Blog/node_modules/.pnpm-store/v3/files/86/107664212996f63f35e54464d4f9ea638a5d5d8abf4676804e87326bb34598d69473def5b14200b7e08fa6a59cf07cc9753da40e77b1727b9463b2cdee1ab5
2022-08-14 01:14:53 +08:00

103 lines
2.6 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 {ok as assert} from 'uvu/assert'
import {factorySpace} from 'micromark-factory-space'
import {markdownLineEnding} from 'micromark-util-character'
import {codes} from 'micromark-util-symbol/codes.js'
import {constants} from 'micromark-util-symbol/constants.js'
import {types} from 'micromark-util-symbol/types.js'
/**
* @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) {
assert(
code === codes.quotationMark ||
code === codes.apostrophe ||
code === codes.leftParenthesis,
'expected `"`, `\'`, or `(`'
)
effects.enter(type)
effects.enter(markerType)
effects.consume(code)
effects.exit(markerType)
marker = code === codes.leftParenthesis ? codes.rightParenthesis : 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 === codes.eof) {
return nok(code)
}
// Note: blank lines cant exist in content.
if (markdownLineEnding(code)) {
effects.enter(types.lineEnding)
effects.consume(code)
effects.exit(types.lineEnding)
return factorySpace(effects, atTitleBreak, types.linePrefix)
}
effects.enter(types.chunkString, {contentType: constants.contentTypeString})
return title(code)
}
/** @type {State} */
function title(code) {
if (code === marker || code === codes.eof || markdownLineEnding(code)) {
effects.exit(types.chunkString)
return atTitleBreak(code)
}
effects.consume(code)
return code === codes.backslash ? titleEscape : title
}
/** @type {State} */
function titleEscape(code) {
if (code === marker || code === codes.backslash) {
effects.consume(code)
return title
}
return title(code)
}
}