Browse Source

support tables with missing values

(and add supporting test case)
pull/224/head
Sean Lang 9 years ago
parent
commit
10d6448b22
  1. 7
      lib/rules_block/table.js
  2. 32
      test/fixtures/markdown-it/tables.txt

7
lib/rules_block/table.js

@ -143,9 +143,12 @@ module.exports = function table(state, startLine, endLine, silent) {
for (nextLine = startLine + 2; nextLine < endLine; nextLine++) {
if (state.sCount[nextLine] < state.blkIndent) { break; }
lineText = getLine(state, nextLine).trim();
lineText = getLine(state, nextLine);
if (lineText.indexOf('|') === -1) { break; }
columns = escapedSplit(lineText.replace(/^\||\|$/g, ''));
// keep spaces at beginning of line to indicate an empty first cell, but
// strip trailing whitespace
columns = escapedSplit(lineText.replace(/^\||\|\s*$/g, ''));
token = state.push('tr_open', 'tr', 1);
for (i = 0; i < columnCount; i++) {

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

@ -470,3 +470,35 @@ Allow one-column tables (issue #171):
</tbody>
</table>
.
Allow tables with missing values:
.
0,0 | 0,1 | 0,2
--- | --- | ---
1,0 | | 1,2
| 2,1 |
.
<table>
<thead>
<tr>
<th>0,0</th>
<th>0,1</th>
<th>0,2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1,0</td>
<td></td>
<td>1,2</td>
</tr>
<tr>
<td></td>
<td>2,1</td>
<td></td>
</tr>
</tbody>
</table>
.

Loading…
Cancel
Save