Skip to content

Commit

Permalink
Fix alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Dec 21, 2021
1 parent 59a11b2 commit a28b860
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
11 changes: 9 additions & 2 deletions index.js
Expand Up @@ -40,10 +40,17 @@ export const gfmTableFromMarkdown = {

/** @type {FromMarkdownHandle} */
function enterTable(token) {
/** @type {AlignType[]} */
/** @type {Array<'left'|'right'|'center'|'none'>} */
// @ts-expect-error: `align` is custom.
const align = token._align
this.enter({type: 'table', align, children: []}, token)
this.enter(
{
type: 'table',
align: align.map((d) => (d === 'none' ? null : d)),
children: []
},
token
)
this.setData('inTable', true)
}

Expand Down
31 changes: 31 additions & 0 deletions test.js
Expand Up @@ -64,6 +64,37 @@ test('markdown -> mdast', (t) => {
'should support tables'
)

t.deepEqual(
removePosition(
fromMarkdown('| a | b | c | d |\n| - | :- | -: | :-: |', {
extensions: [gfmTable],
mdastExtensions: [gfmTableFromMarkdown]
}),
true
),
{
type: 'root',
children: [
{
type: 'table',
align: [null, 'left', 'right', 'center'],
children: [
{
type: 'tableRow',
children: [
{type: 'tableCell', children: [{type: 'text', value: 'a'}]},
{type: 'tableCell', children: [{type: 'text', value: 'b'}]},
{type: 'tableCell', children: [{type: 'text', value: 'c'}]},
{type: 'tableCell', children: [{type: 'text', value: 'd'}]}
]
}
]
}
]
},
'should support alignment'
)

t.deepEqual(
removePosition(
fromMarkdown('| `\\|` |\n | --- |', {
Expand Down

0 comments on commit a28b860

Please sign in to comment.