Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tables with empty cells at beginning #224

Merged
merged 2 commits into from Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>
.