diff --git a/lib/index.js b/lib/index.js index 11e5115..dd22c09 100644 --- a/lib/index.js +++ b/lib/index.js @@ -65,13 +65,17 @@ export function gfmTableFromMarkdown() { function enterTable(token) { const align = token._align assert(align, 'expected `_align` on table') + // Trailing `position: undefined` keeps the table hidden class stable; + // mdast-util-from-markdown's enter() patches the field to a real value + // but the property already exists, so no shape transition fires. this.enter( { type: 'table', align: align.map(function (d) { return d === 'none' ? null : d }), - children: [] + children: [], + position: undefined }, token ) @@ -92,7 +96,8 @@ function exitTable(token) { * @type {FromMarkdownHandle} */ function enterRow(token) { - this.enter({type: 'tableRow', children: []}, token) + // See enterTable above for the rationale on the trailing position field. + this.enter({type: 'tableRow', children: [], position: undefined}, token) } /** @@ -108,7 +113,8 @@ function exit(token) { * @type {FromMarkdownHandle} */ function enterCell(token) { - this.enter({type: 'tableCell', children: []}, token) + // See enterTable above for the rationale on the trailing position field. + this.enter({type: 'tableCell', children: [], position: undefined}, token) } // Overwrite the default code text data handler to unescape escaped pipes when @@ -230,11 +236,8 @@ export function gfmTableToMarkdown(options) { function serializeData(matrix, align) { return markdownTable(matrix, { align, - // @ts-expect-error: `markdown-table` types should support `null`. alignDelimiters, - // @ts-expect-error: `markdown-table` types should support `null`. padding, - // @ts-expect-error: `markdown-table` types should support `null`. stringLength }) }