diff --git a/lib/rules_block/table.js b/lib/rules_block/table.js index 000005d..bf276e2 100644 --- a/lib/rules_block/table.js +++ b/lib/rules_block/table.js @@ -140,12 +140,15 @@ module.exports = function table(state, startLine, endLine, silent) { if (lineText.indexOf('|') === -1) { break; } rows = escapedSplit(lineText.replace(/^\||\|$/g, '')); + // set number of columns to number of columns in header row + rows.length = aligns.length; + state.tokens.push({ type: 'tr_open', level: state.level++ }); for (i = 0; i < rows.length; i++) { state.tokens.push({ type: 'td_open', align: aligns[i], level: state.level++ }); state.tokens.push({ type: 'inline', - content: rows[i].trim(), + content: rows[i] ? rows[i].trim() : '', level: state.level, children: [] }); diff --git a/test/fixtures/markdown-it/tables.txt b/test/fixtures/markdown-it/tables.txt index 1f25547..23eefcb 100644 --- a/test/fixtures/markdown-it/tables.txt +++ b/test/fixtures/markdown-it/tables.txt @@ -241,3 +241,22 @@ Delimiter escaping: . + + +Add/remove columns to match the first row: +. +Heading 1|Heading 2|Heading 3 +---|---|--- +1|2 +1|2|3|4 +. +
Heading 1 | Heading 2 | Heading 3 |
---|---|---|
1 | 2 | |
1 | 2 | 3 |