mirror of
https://github.com/Sevichecc/Urara-Blog.git
synced 2025-05-03 06:49:29 +08:00
41 lines
1 KiB
Text
41 lines
1 KiB
Text
/**
|
|
* @typedef {import('micromark-util-types').Construct} Construct
|
|
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
|
|
* @typedef {import('micromark-util-types').State} State
|
|
*/
|
|
|
|
import {ok as assert} from 'uvu/assert'
|
|
import {markdownLineEnding} from 'micromark-util-character'
|
|
import {codes} from 'micromark-util-symbol/codes.js'
|
|
import {types} from 'micromark-util-symbol/types.js'
|
|
|
|
/** @type {Construct} */
|
|
export const hardBreakEscape = {
|
|
name: 'hardBreakEscape',
|
|
tokenize: tokenizeHardBreakEscape
|
|
}
|
|
|
|
/** @type {Tokenizer} */
|
|
function tokenizeHardBreakEscape(effects, ok, nok) {
|
|
return start
|
|
|
|
/** @type {State} */
|
|
function start(code) {
|
|
assert(code === codes.backslash, 'expected `\\`')
|
|
effects.enter(types.hardBreakEscape)
|
|
effects.enter(types.escapeMarker)
|
|
effects.consume(code)
|
|
return open
|
|
}
|
|
|
|
/** @type {State} */
|
|
function open(code) {
|
|
if (markdownLineEnding(code)) {
|
|
effects.exit(types.escapeMarker)
|
|
effects.exit(types.hardBreakEscape)
|
|
return ok(code)
|
|
}
|
|
|
|
return nok(code)
|
|
}
|
|
}
|