Urara-Blog/node_modules/.pnpm-store/v3/files/34/e7873b2eaa9ae2512bc234ad64ea2b4bfac63b4c232ad0f2fb825f44d30455ea6843afcba19b02b99bb3e1e0402b7fab7c6d348d9d078ba72a0429db248c24
2022-08-14 01:14:53 +08:00

61 lines
1.4 KiB
Text

/**
* @typedef {import('micromark-util-types').Construct} Construct
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Code} Code
*/
import {factorySpace} from 'micromark-factory-space'
import {markdownLineEnding, markdownSpace} from 'micromark-util-character'
/** @type {Construct} */
export const thematicBreak = {
name: 'thematicBreak',
tokenize: tokenizeThematicBreak
}
/** @type {Tokenizer} */
function tokenizeThematicBreak(effects, ok, nok) {
let size = 0
/** @type {NonNullable<Code>} */
let marker
return start
/** @type {State} */
function start(code) {
effects.enter('thematicBreak')
marker = code
return atBreak(code)
}
/** @type {State} */
function atBreak(code) {
if (code === marker) {
effects.enter('thematicBreakSequence')
return sequence(code)
}
if (markdownSpace(code)) {
return factorySpace(effects, atBreak, 'whitespace')(code)
}
if (size < 3 || (code !== null && !markdownLineEnding(code))) {
return nok(code)
}
effects.exit('thematicBreak')
return ok(code)
}
/** @type {State} */
function sequence(code) {
if (code === marker) {
effects.consume(code)
size++
return sequence
}
effects.exit('thematicBreakSequence')
return atBreak(code)
}
}