mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-04 11:19:30 +08:00
40 lines
887 B
Text
40 lines
887 B
Text
/**
|
|
* @typedef {import('micromark-util-types').Effects} Effects
|
|
* @typedef {import('micromark-util-types').State} State
|
|
*/
|
|
|
|
import {factorySpace} from 'micromark-factory-space'
|
|
import {markdownLineEnding, markdownSpace} from 'micromark-util-character'
|
|
import {types} from 'micromark-util-symbol/types.js'
|
|
|
|
/**
|
|
* @param {Effects} effects
|
|
* @param {State} ok
|
|
*/
|
|
export function factoryWhitespace(effects, ok) {
|
|
/** @type {boolean} */
|
|
let seen
|
|
|
|
return start
|
|
|
|
/** @type {State} */
|
|
function start(code) {
|
|
if (markdownLineEnding(code)) {
|
|
effects.enter(types.lineEnding)
|
|
effects.consume(code)
|
|
effects.exit(types.lineEnding)
|
|
seen = true
|
|
return start
|
|
}
|
|
|
|
if (markdownSpace(code)) {
|
|
return factorySpace(
|
|
effects,
|
|
start,
|
|
seen ? types.linePrefix : types.lineSuffix
|
|
)(code)
|
|
}
|
|
|
|
return ok(code)
|
|
}
|
|
}
|