Files
coopgo/node_modules/micromark-extension-gfm-task-list-item/syntax.js
sgauthier 6e64e138e2
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
planning
2024-10-14 09:15:30 +02:00

81 lines
1.9 KiB
JavaScript
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.
var markdownLineEndingOrSpace = require('micromark/dist/character/markdown-line-ending-or-space')
var spaceFactory = require('micromark/dist/tokenize/factory-space')
var prefixSize = require('micromark/dist/util/prefix-size')
var tasklistCheck = {tokenize: tokenizeTasklistCheck}
exports.text = {91: tasklistCheck}
function tokenizeTasklistCheck(effects, ok, nok) {
var self = this
return open
function open(code) {
if (
// Exit if not `[`.
code !== 91 ||
// Exit if theres stuff before.
self.previous !== null ||
// Exit if not in the first content that is the first child of a list
// item.
!self._gfmTasklistFirstContentOfListItem
) {
return nok(code)
}
effects.enter('taskListCheck')
effects.enter('taskListCheckMarker')
effects.consume(code)
effects.exit('taskListCheckMarker')
return inside
}
function inside(code) {
// Tab or space.
if (code === -2 || code === 32) {
effects.enter('taskListCheckValueUnchecked')
effects.consume(code)
effects.exit('taskListCheckValueUnchecked')
return close
}
// Upper- and lower `x`.
if (code === 88 || code === 120) {
effects.enter('taskListCheckValueChecked')
effects.consume(code)
effects.exit('taskListCheckValueChecked')
return close
}
return nok(code)
}
function close(code) {
// `]`
if (code === 93) {
effects.enter('taskListCheckMarker')
effects.consume(code)
effects.exit('taskListCheckMarker')
effects.exit('taskListCheck')
return effects.check({tokenize: spaceThenNonSpace}, ok, nok)
}
return nok(code)
}
}
function spaceThenNonSpace(effects, ok, nok) {
var self = this
return spaceFactory(effects, after, 'whitespace')
function after(code) {
return prefixSize(self.events, 'whitespace') &&
code !== null &&
!markdownLineEndingOrSpace(code)
? ok(code)
: nok(code)
}
}