Browse Source

Merge pull request #224 from slang800/tables-with-empty-cells

fix tables with empty cells at beginning
pull/223/merge
Vitaly Puzrin 9 years ago
parent
commit
a10193c304
  1. 2
      lib/index.js
  2. 7
      lib/rules_block/table.js
  3. 32
      test/fixtures/markdown-it/tables.txt

2
lib/index.js

@ -1,4 +1,4 @@
// Main perser class
// Main parser class
'use strict';

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