Browse Source

Tables: add/remove columns to match the first row, fix #59

pull/82/head
Kirill Efimov 10 years ago
parent
commit
a3a49b5c55
  1. 5
      lib/rules_block/table.js
  2. 19
      test/fixtures/markdown-it/tables.txt

5
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: []
});

19
test/fixtures/markdown-it/tables.txt

@ -241,3 +241,22 @@ Delimiter escaping:
</tbody>
</table>
.
Add/remove columns to match the first row:
.
Heading 1|Heading 2|Heading 3
---|---|---
1|2
1|2|3|4
.
<table>
<thead>
<tr><th>Heading 1</th><th>Heading 2</th><th>Heading 3</th></tr>
</thead>
<tbody>
<tr><td>1</td><td>2</td><td></td></tr>
<tr><td>1</td><td>2</td><td>3</td></tr>
</tbody>
</table>
.

Loading…
Cancel
Save