mity / md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
MIT License
785 stars 146 forks source link

Table with numbers #161

Closed ProkopRandacek closed 3 years ago

ProkopRandacek commented 3 years ago

Table with only numbers in the first column does not get recognized as a table and is translated into regular <p> block

1 | test1
---------
2 | test2
3 | test3
4 | test4

gives

<p>1 | test1
--|------
2 | test2
3 | test3
4 | test4</p>

but

t1 | test1
---|------
t2 | test2
t3 | test3
t4 | test4

gives

<table>
<thead>
<tr>
<th>t1</th>
<th>test1</th>
</tr>
</thead>
<tbody>
<tr>
<td>t2</td>
<td>test2</td>
</tr>
<tr>
<td>t3</td>
<td>test3</td>
</tr>
<tr>
<td>t4</td>
<td>test4</td>
</tr>
</tbody>
</table>
mity commented 3 years ago

It has nothing to do with the numbers.

There is an ambiguity of the 2nd line --------- which can be interpreted either as a delimiter of a table header (assuming the a table of a single column) or as an underline of a Setext heading.

MD4C prefers the latter.

EDIT: You need to use at least one pipe | on that line to suppress the heading interpretation.

mity commented 3 years ago

Sorry disregard the previous post. It does not help here, so likely an actual bug indeed. Will take a closer look.

mity commented 3 years ago

Yes, it does work as advertise after all:

The underline of the table is crucial for recognition of the table, count of its columns and their alignment: The line has to contain at least one pipe, and it has provide at least three dash (-) characters for every column in the table.

(from test/tables.txt)

Therefore:

1 | test1
---------
2 | test2
3 | test3
4 | test4

is not a proper table, because there is no pipe at the 2nd line.

Also

1 | test1
--|------
2 | test2
3 | test3
4 | test4

is not a proper table because there are only two dashes on the second line for the 1st column.

But

1 | test1
---|------
2 | test2
3 | test3
4 | test4

is a valid table.