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 a bug in does not display of the table cell if it empty. #697

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ Lexer.prototype.token = function(src, top) {
type: 'table',
header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
cells: cap[3].replace(/\n$/, '').split('\n')
};

for (i = 0; i < item.align.length; i++) {
Expand All @@ -401,6 +401,9 @@ Lexer.prototype.token = function(src, top) {
}

for (i = 0; i < item.cells.length; i++) {
if (!item.cells[i].match(/\|$/)) {
item.cells[i] = item.cells[i] + "\|";
}
item.cells[i] = item.cells[i]
.replace(/^ *\| *| *\| *$/g, '')
.split(/ *\| */);
Expand Down
31 changes: 31 additions & 0 deletions test/new/gfm_tables.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,34 @@
<tr><td style="text-align:left"><em>Cell 5</em></td><td style="text-align:center">Cell 6</td><td style="text-align:right">Cell 7</td><td>Cell 8</td></tr>
</tbody>
</table>
<p>In the bottom right corner cell is empty.</p>
<table>
<thead>
<tr><th style="text-align:center">Header 1</th><th style="text-align:right">Header 2</th><th style="text-align:left">Header 3</th><th>Header 4</th></tr>
</thead>
<tbody>
<tr><td style="text-align:center">Cell 1</td><td style="text-align:right">Cell 2</td><td style="text-align:left">Cell 3</td><td>Cell 4</td></tr>
<tr><td style="text-align:center">Cell 5</td><td style="text-align:right">Cell 6</td><td style="text-align:left">Cell 7</td><td>Cell 8</td></tr>
<tr><td style="text-align:center">Cell 9</td><td style="text-align:right">Cell 10</td><td style="text-align:left">Cell 11</td><td></td></tr>
</tbody>
</table>
<table>
<thead>
<tr><th style="text-align:center">Header 1</th><th style="text-align:right">Header 2</th><th style="text-align:left">Header 3</th><th>Header 4 </th></tr>
</thead>
<tbody>
<tr><td style="text-align:center">Cell 1</td><td style="text-align:right">Cell 2</td><td style="text-align:left">Cell 3</td><td>Cell 4</td></tr>
<tr><td style="text-align:center">Cell 5</td><td style="text-align:right">Cell 6</td><td style="text-align:left">Cell 7</td><td>Cell 8</td></tr>
<tr><td style="text-align:center">Cell 9</td><td style="text-align:right">Cell 10</td><td style="text-align:left">Cell 11</td><td></td></tr>
</tbody>
</table>
<table>
<thead>
<tr><th style="text-align:center">Header 1</th><th style="text-align:right">Header 2</th><th style="text-align:left">Header 3</th><th>Header 4 </th></tr>
</thead>
<tbody>
<tr><td style="text-align:center">Cell 1</td><td style="text-align:right">Cell 2</td><td style="text-align:left">Cell 3</td><td>Cell 4 </td></tr>
<tr><td style="text-align:center">Cell 5</td><td style="text-align:right">Cell 6</td><td style="text-align:left">Cell 7</td><td>Cell 8 </td></tr>
<tr><td style="text-align:center">Cell 9</td><td style="text-align:right">Cell 10</td><td style="text-align:left">Cell 11</td><td></td></tr>
</tbody>
</table>
20 changes: 20 additions & 0 deletions test/new/gfm_tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,23 @@ Header 1|Header 2|Header 3|Header 4
:-------|:------:|-------:|--------
Cell 1 |Cell 2 |Cell 3 |Cell 4
*Cell 5*|Cell 6 |Cell 7 |Cell 8

In the bottom right corner cell is empty.

| Header 1 | Header 2 | Header 3 | Header 4 |
| :------: | -------: | :------- | -------- |
| Cell 1 | Cell 2 | Cell 3 | Cell 4 |
| Cell 5 | Cell 6 | Cell 7 | Cell 8 |
| Cell 9 | Cell 10 | Cell 11 | |

| Header 1 | Header 2 | Header 3 | Header 4
| :------: | -------: | :------- | --------
| Cell 1 | Cell 2 | Cell 3 | Cell 4
| Cell 5 | Cell 6 | Cell 7 | Cell 8
| Cell 9 | Cell 10 | Cell 11 |

Header 1 | Header 2 | Header 3 | Header 4
:------: | -------: | :------- | --------
Cell 1 | Cell 2 | Cell 3 | Cell 4
Cell 5 | Cell 6 | Cell 7 | Cell 8
Cell 9 | Cell 10 | Cell 11 |