Skip to content

Commit a28b860

Browse files
committed
1 parent 59a11b2 commit a28b860

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ export const gfmTableFromMarkdown = {
4040

4141
/** @type {FromMarkdownHandle} */
4242
function enterTable(token) {
43-
/** @type {AlignType[]} */
43+
/** @type {Array<'left'|'right'|'center'|'none'>} */
4444
// @ts-expect-error: `align` is custom.
4545
const align = token._align
46-
this.enter({type: 'table', align, children: []}, token)
46+
this.enter(
47+
{
48+
type: 'table',
49+
align: align.map((d) => (d === 'none' ? null : d)),
50+
children: []
51+
},
52+
token
53+
)
4754
this.setData('inTable', true)
4855
}
4956

test.js

+31
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,37 @@ test('markdown -> mdast', (t) => {
6464
'should support tables'
6565
)
6666

67+
t.deepEqual(
68+
removePosition(
69+
fromMarkdown('| a | b | c | d |\n| - | :- | -: | :-: |', {
70+
extensions: [gfmTable],
71+
mdastExtensions: [gfmTableFromMarkdown]
72+
}),
73+
true
74+
),
75+
{
76+
type: 'root',
77+
children: [
78+
{
79+
type: 'table',
80+
align: [null, 'left', 'right', 'center'],
81+
children: [
82+
{
83+
type: 'tableRow',
84+
children: [
85+
{type: 'tableCell', children: [{type: 'text', value: 'a'}]},
86+
{type: 'tableCell', children: [{type: 'text', value: 'b'}]},
87+
{type: 'tableCell', children: [{type: 'text', value: 'c'}]},
88+
{type: 'tableCell', children: [{type: 'text', value: 'd'}]}
89+
]
90+
}
91+
]
92+
}
93+
]
94+
},
95+
'should support alignment'
96+
)
97+
6798
t.deepEqual(
6899
removePosition(
69100
fromMarkdown('| `\\|` |\n | --- |', {

0 commit comments

Comments
 (0)