All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
exports.exit = {
|
||
taskListCheckValueChecked: exitCheck,
|
||
taskListCheckValueUnchecked: exitCheck,
|
||
paragraph: exitParagraphWithTaskListItem
|
||
}
|
||
|
||
function exitCheck(token) {
|
||
// We’re always in a paragraph, in a list item.
|
||
this.stack[this.stack.length - 2].checked =
|
||
token.type === 'taskListCheckValueChecked'
|
||
}
|
||
|
||
function exitParagraphWithTaskListItem(token) {
|
||
var parent = this.stack[this.stack.length - 2]
|
||
var node = this.stack[this.stack.length - 1]
|
||
var siblings = parent.children
|
||
var head = node.children[0]
|
||
var index = -1
|
||
var firstParaghraph
|
||
|
||
if (
|
||
parent &&
|
||
parent.type === 'listItem' &&
|
||
typeof parent.checked === 'boolean' &&
|
||
head &&
|
||
head.type === 'text'
|
||
) {
|
||
while (++index < siblings.length) {
|
||
if (siblings[index].type === 'paragraph') {
|
||
firstParaghraph = siblings[index]
|
||
break
|
||
}
|
||
}
|
||
|
||
if (firstParaghraph === node) {
|
||
// Must start with a space or a tab.
|
||
head.value = head.value.slice(1)
|
||
|
||
if (head.value.length === 0) {
|
||
node.children.shift()
|
||
} else {
|
||
head.position.start.column++
|
||
head.position.start.offset++
|
||
node.position.start = Object.assign({}, head.position.start)
|
||
}
|
||
}
|
||
}
|
||
|
||
this.exit(token)
|
||
}
|