mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-04 20:39:30 +08:00
41 lines
827 B
Text
41 lines
827 B
Text
/**
|
|
* @typedef {import('micromark-util-types').Effects} Effects
|
|
* @typedef {import('micromark-util-types').State} State
|
|
*/
|
|
|
|
import {markdownSpace} from 'micromark-util-character'
|
|
|
|
/**
|
|
* @param {Effects} effects
|
|
* @param {State} ok
|
|
* @param {string} type
|
|
* @param {number} [max=Infinity]
|
|
* @returns {State}
|
|
*/
|
|
export function factorySpace(effects, ok, type, max) {
|
|
const limit = max ? max - 1 : Number.POSITIVE_INFINITY
|
|
let size = 0
|
|
|
|
return start
|
|
|
|
/** @type {State} */
|
|
function start(code) {
|
|
if (markdownSpace(code)) {
|
|
effects.enter(type)
|
|
return prefix(code)
|
|
}
|
|
|
|
return ok(code)
|
|
}
|
|
|
|
/** @type {State} */
|
|
function prefix(code) {
|
|
if (markdownSpace(code) && size++ < limit) {
|
|
effects.consume(code)
|
|
return prefix
|
|
}
|
|
|
|
effects.exit(type)
|
|
return ok(code)
|
|
}
|
|
}
|