diff --git a/lib/rules_block/table.js b/lib/rules_block/table.js index cb7c3f9..7175892 100644 --- a/lib/rules_block/table.js +++ b/lib/rules_block/table.js @@ -55,7 +55,7 @@ function escapedSplit(str) { module.exports = function table(state, startLine, endLine, silent) { var ch, lineText, pos, i, nextLine, columns, columnCount, token, - aligns, t, tableLines, tbodyLines; + aligns, t, tableLines, tbodyLines, len; // should have at least three lines if (startLine + 2 > endLine) { return false; } @@ -151,7 +151,8 @@ module.exports = function table(state, startLine, endLine, silent) { columns = escapedSplit(lineText.replace(/^\||\|\s*$/g, '')); token = state.push('tr_open', 'tr', 1); - for (i = 0; i < columnCount; i++) { + len = Math.max(columns.length, columnCount); + for (i = 0; i < len; i++) { token = state.push('td_open', 'td', 1); if (aligns[i]) { token.attrs = [ [ 'style', 'text-align:' + aligns[i] ] ]; diff --git a/test/fixtures/markdown-it/tables.txt b/test/fixtures/markdown-it/tables.txt index c168be5..e6dfc0e 100644 --- a/test/fixtures/markdown-it/tables.txt +++ b/test/fixtures/markdown-it/tables.txt @@ -401,7 +401,7 @@ Should be parsed before code blocks: . -An amount of rows might be different across the table (issue #171): +Allow tables with extra cells in a row outside of thead: . | 1 | 2 | | :-----: | :-----: | :-----: | @@ -418,6 +418,8 @@ An amount of rows might be different across the table (issue #171):