Tables are not rendered properly unless there is a new line before them
Consider a following piece of code:
using Markdig;
var input = @"
Here is the table:
| Key | Value |
| ---- | -------- |
| Color | Blue |
| Size | Medium |
";
var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build();
var html = Markdown.ToHtml(input, pipeline);
Console.WriteLine(html);
It prints single paragraph without converting the table to html:
<p>Here is the table:
| Key | Value |
| ---- | -------- |
| Color | Blue |
| Size | Medium |</p>
If we just add new line after the Here is the table: part:
using Markdig;
var input = @"
Here is the table:
| Key | Value |
| ---- | -------- |
| Color | Blue |
| Size | Medium |
";
var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build();
var html = Markdown.ToHtml(input, pipeline);
Console.WriteLine(html);
then everything gets converted properly:
<p>Here is the table:</p>
<table>
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Color</td>
<td>Blue</td>
</tr>
<tr>
<td>Size</td>
<td>Medium</td>
</tr>
</tbody>
</table>
This is different from how other Markdown libraries are rendering it. It is also different from how Github renders it. If I just paste Markdown code from the first example in the text of this issue we properly rendered table:
Here is the table:
| Key | Value |
|---|---|
| Color | Blue |
| Size | Medium |
Let me know if more information is needed.
希望修复这个问题,先谢谢你,我一直在找这个问题,现在找到了,谢谢你,希望赶紧修改这个问题
When markdig was implemented, it was based on pandoc behavior. The parsing of pipe tables is a complicated beast, and as this library is mainly in maintenance mode, I won't take the time to fix it, but if someone is brave enough, a PR is welcome.
There is an explicit rule in the specs:
But if a table doesn't start with a column delimiter, it is not interpreted as a table, even if following lines have a column delimiter
But I can't find where it could possibly come from in the pandoc specs.
GFM is different, and not only in this aspect:
- It requires the header row to match the delimiter row in the number of cells. All subsequent rows are normalized to this number, not the maximum number of cells. If a row contains more cells than the header, extra cells are simply ignored, with all their contents.
- Once started with the header and the delimiter row, the table ends only with an empty line or at the beginning of another block structure. Thus, it accepts lines that contain no pipes as single cells.
So what behavior is currently expected (or desired)?