Urara-Blog/node_modules/.pnpm-store/v3/files/21/945c81983506bff540df3ad01387133d23ec219a38677ea814ed2621a8c8bc187ee4f639e58cd23b8a84ac39f2de82a9a62cd8beacaddc4e00606ac59f6d1a
2022-08-14 01:14:53 +08:00

109 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').Construct} Construct
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
* @typedef {import('micromark-util-types').Resolver} Resolver
* @typedef {import('micromark-util-types').Token} Token
* @typedef {import('micromark-util-types').State} State
*/
import {factorySpace} from 'micromark-factory-space'
import {markdownLineEnding} from 'micromark-util-character'
/** @type {Construct} */
export const codeIndented = {
name: 'codeIndented',
tokenize: tokenizeCodeIndented
}
/** @type {Construct} */
const indentedContent = {
tokenize: tokenizeIndentedContent,
partial: true
}
/** @type {Tokenizer} */
function tokenizeCodeIndented(effects, ok, nok) {
const self = this
return start
/** @type {State} */
function start(code) {
effects.enter('codeIndented')
return factorySpace(effects, afterStartPrefix, 'linePrefix', 4 + 1)(code)
}
/** @type {State} */
function afterStartPrefix(code) {
const tail = self.events[self.events.length - 1]
return tail &&
tail[1].type === 'linePrefix' &&
tail[2].sliceSerialize(tail[1], true).length >= 4
? afterPrefix(code)
: nok(code)
}
/** @type {State} */
function afterPrefix(code) {
if (code === null) {
return after(code)
}
if (markdownLineEnding(code)) {
return effects.attempt(indentedContent, afterPrefix, after)(code)
}
effects.enter('codeFlowValue')
return content(code)
}
/** @type {State} */
function content(code) {
if (code === null || markdownLineEnding(code)) {
effects.exit('codeFlowValue')
return afterPrefix(code)
}
effects.consume(code)
return content
}
/** @type {State} */
function after(code) {
effects.exit('codeIndented')
return ok(code)
}
}
/** @type {Tokenizer} */
function tokenizeIndentedContent(effects, ok, nok) {
const self = this
return start
/** @type {State} */
function start(code) {
// If this is a lazy line, it cant be code.
if (self.parser.lazy[self.now().line]) {
return nok(code)
}
if (markdownLineEnding(code)) {
effects.enter('lineEnding')
effects.consume(code)
effects.exit('lineEnding')
return start
}
return factorySpace(effects, afterPrefix, 'linePrefix', 4 + 1)(code)
}
/** @type {State} */
function afterPrefix(code) {
const tail = self.events[self.events.length - 1]
return tail &&
tail[1].type === 'linePrefix' &&
tail[2].sliceSerialize(tail[1], true).length >= 4
? ok(code)
: markdownLineEnding(code)
? start(code)
: nok(code)
}
}