Skip to content

Commit

Permalink
Merge pull request #224 from slang800/tables-with-empty-cells
Browse files Browse the repository at this point in the history
fix tables with empty cells at beginning
  • Loading branch information
Vitaly Puzrin committed Apr 1, 2016
2 parents 0e51825 + 86eea8c commit a10193c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
@@ -1,4 +1,4 @@
// Main perser class
// Main parser class

'use strict';

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 a10193c

Please sign in to comment.