Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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)
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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
})
}
Expand Down
Loading