From a3a49b5c55383f968c9a8e17432c290d13cb3818 Mon Sep 17 00:00:00 2001 From: Kirill Efimov Date: Thu, 19 Feb 2015 15:30:22 +0300 Subject: [PATCH] Tables: add/remove columns to match the first row, fix #59 --- lib/rules_block/table.js | 5 ++++- test/fixtures/markdown-it/tables.txt | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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 1Heading 2Heading 3
12
123
+.