Skip to content

Commit

Permalink
Merge pull request hoedown#159 from uranusjr/table-fix
Browse files Browse the repository at this point in the history
Fix rendering in table with empty cells
  • Loading branch information
mildsunrise committed May 16, 2015
2 parents 365ad57 + 2297a4e commit d01eba9
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,15 @@ parse_table_row(
cell_start = i;

len = find_emph_char(data + i, size - i, '|');
i += len ? len : size - i;

/* Two possibilities for len == 0:
1) No more pipe char found in the current line.
2) The next pipe is right after the current one, i.e. empty cell.
For case 1, we skip to the end of line; for case 2 we just continue.
*/
if (len == 0 && data[i] != '|')
len = size - i;
i += len;

cell_end = i - 1;

Expand Down
66 changes: 66 additions & 0 deletions test/Tests/Table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<h1>Standard table</h1>

<table>
<thead>
<tr>
<th>headline1</th>
<th>headline2</th>
</tr>
</thead>
<tbody>
<tr>
<td>123</td>
<td></td>
</tr>
</tbody>
</table>


<h1>Cell alignment</h1>

<table>
<thead>
<tr>
<th style="text-align: left">headline1</th>
<th style="text-align: center">headline2</th>
<th style="text-align: right">headline3</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">123</td>
<td style="text-align: center"></td>
<td style="text-align: right"></td>
</tr>
</tbody>
</table>


<h1>Malformed table: missing cell at row in body</h1>

<table>
<thead>
<tr>
<th>headline1</th>
<th>headline2</th>
<th>headline3</th>
</tr>
</thead>
<tbody>
<tr>
<td>12</td>
<td></td>
<td></td>
</tr>
<tr>
<td>34</td>
<td></td>
<td></td>
</tr>
<tr>
<td>56</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
21 changes: 21 additions & 0 deletions test/Tests/Table.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Standard table

|headline1|headline2|
|---------|---------|
|123 | |


# Cell alignment

|headline1|headline2|headline3|
|:-------|:------:|------:|
|123|||


# Malformed table: missing cell at row in body

|headline1|headline2|headline3|
|-------|-------|-------|
|12
|34||
|56|
5 changes: 5 additions & 0 deletions test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@
"input": "Tests/Underline.text",
"output": "Tests/Underline.html",
"flags": ["--underline"]
},
{
"input": "Tests/Table.text",
"output": "Tests/Table.html",
"flags": ["--tables"]
}
]
}

0 comments on commit d01eba9

Please sign in to comment.