Skip to content

Commit

Permalink
support tables with missing values
Browse files Browse the repository at this point in the history
(and add supporting test case)
  • Loading branch information
notslang committed Apr 1, 2016
1 parent 0e51825 commit a25beb4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/index.js
Expand Up @@ -13,7 +13,6 @@ var LinkifyIt = require('linkify-it');
var mdurl = require('mdurl');
var punycode = require('punycode');


var config = {
'default': require('./presets/default'),
zero: require('./presets/zero'),
Expand Down
7 changes: 5 additions & 2 deletions lib/rules_block/table.js
Expand Up @@ -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++) {
Expand Down
32 changes: 32 additions & 0 deletions test/fixtures/markdown-it/tables.txt
Expand Up @@ -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>
.

0 comments on commit a25beb4

Please sign in to comment.