Files
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

51 lines
1.2 KiB
JavaScript
Raw Permalink 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.
exports.exit = {
taskListCheckValueChecked: exitCheck,
taskListCheckValueUnchecked: exitCheck,
paragraph: exitParagraphWithTaskListItem
}
function exitCheck(token) {
// Were 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)
}