summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTzu-ping Chung <uranusjr@gmail.com>2015-05-16 00:51:50 +0800
committerTzu-ping Chung <uranusjr@gmail.com>2015-05-16 00:54:24 +0800
commit2297a4e20beafadd3338ce4e08d166937dbed21d (patch)
treeb135feecdbb67b54d54d540cf8df00b25af3597d
parent365ad578e7b767ffe7126f029c184d727a3e95b3 (diff)
downloadrust-hoedown-2297a4e20beafadd3338ce4e08d166937dbed21d.tar.gz
Fix rendering in table with empty cells
`find_emph_char` returns 0 if the char specified is not found in the current line, but this is also what happens when there's an empty cell. This patch adds logic to work around this problem. See uranusjr/macdown#321
-rw-r--r--src/document.c10
-rw-r--r--test/Tests/Table.html66
-rw-r--r--test/Tests/Table.text21
-rw-r--r--test/config.json5
4 files changed, 101 insertions, 1 deletions
diff --git a/src/document.c b/src/document.c
index 27c17b2..99596e9 100644
--- a/src/document.c
+++ b/src/document.c
@@ -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;
diff --git a/test/Tests/Table.html b/test/Tests/Table.html
new file mode 100644
index 0000000..f434598
--- /dev/null
+++ b/test/Tests/Table.html
@@ -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>
diff --git a/test/Tests/Table.text b/test/Tests/Table.text
new file mode 100644
index 0000000..37df539
--- /dev/null
+++ b/test/Tests/Table.text
@@ -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|
diff --git a/test/config.json b/test/config.json
index d3e170e..365c7bc 100644
--- a/test/config.json
+++ b/test/config.json
@@ -106,6 +106,11 @@
"input": "Tests/Underline.text",
"output": "Tests/Underline.html",
"flags": ["--underline"]
+ },
+ {
+ "input": "Tests/Table.text",
+ "output": "Tests/Table.html",
+ "flags": ["--tables"]
}
]
}