Files
coopgo/node_modules/mdast-util-gfm-table/from-markdown.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

54 lines
1.1 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.
exports.enter = {
table: enterTable,
tableData: enterCell,
tableHeader: enterCell,
tableRow: enterRow
}
exports.exit = {
codeText: exitCodeText,
table: exitTable,
tableData: exit,
tableHeader: exit,
tableRow: exit
}
function enterTable(token) {
this.enter({type: 'table', align: token._align, children: []}, token)
this.setData('inTable', true)
}
function exitTable(token) {
this.exit(token)
this.setData('inTable')
}
function enterRow(token) {
this.enter({type: 'tableRow', children: []}, token)
}
function exit(token) {
this.exit(token)
}
function enterCell(token) {
this.enter({type: 'tableCell', children: []}, token)
}
// Overwrite the default code text data handler to unescape escaped pipes when
// they are in tables.
function exitCodeText(token) {
var value = this.resume()
if (this.getData('inTable')) {
value = value.replace(/\\([\\|])/g, replace)
}
this.stack[this.stack.length - 1].value = value
this.exit(token)
}
function replace($0, $1) {
// Pipes work, backslashes dont (but cant escape pipes).
return $1 === '|' ? $1 : $0
}