/** * @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension */ /** * @typedef {import('./infer.js').Align} Align */ import {ok as assert} from 'devlop' const alignment = { none: '', left: ' align="left"', right: ' align="right"', center: ' align="center"' } // To do: micromark@5: use `infer` here, when all events are exposed. /** * Create an HTML extension for `micromark` to support GitHub tables when * serializing to HTML. * * @returns {HtmlExtension} * Extension for `micromark` that can be passed in `htmlExtensions` to * support GitHub tables when serializing to HTML. */ export function gfmTableHtml() { return { enter: { table(token) { const tableAlign = token._align assert(tableAlign, 'expected `_align`') this.lineEndingIfNeeded() this.tag('
')
}
},
tableHead() {
this.lineEndingIfNeeded()
this.tag('')
},
tableHeader() {
const tableAlign = this.getData('tableAlign')
const tableColumn = this.getData('tableColumn')
assert(tableAlign, 'expected `tableAlign`')
assert(typeof tableColumn === 'number', 'expected `tableColumn`')
const align = alignment[tableAlign[tableColumn]]
this.lineEndingIfNeeded()
this.tag('')
},
tableRow() {
this.setData('tableColumn', 0)
this.lineEndingIfNeeded()
this.tag(' | |