Tables are not rendered properly unless there is a new line before them #697

Closed
opened 2026-01-29 14:43:10 +00:00 by claunia · 3 comments
Owner

Originally created by @dusanrad on GitHub (Sep 28, 2024).

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.

Originally created by @dusanrad on GitHub (Sep 28, 2024). Consider a following piece of code: ``` c# 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: ``` 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: ``` c# 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: ``` html <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.
claunia added the wontfix label 2026-01-29 14:43:10 +00:00
Author
Owner

@ghost commented on GitHub (Oct 10, 2024):

希望修复这个问题,先谢谢你,我一直在找这个问题,现在找到了,谢谢你,希望赶紧修改这个问题

@ghost commented on GitHub (Oct 10, 2024): 希望修复这个问题,先谢谢你,我一直在找这个问题,现在找到了,谢谢你,希望赶紧修改这个问题
Author
Owner

@xoofx commented on GitHub (Oct 15, 2024):

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.

@xoofx commented on GitHub (Oct 15, 2024): 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.
Author
Owner

@snnz commented on GitHub (Nov 24, 2024):

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)?

@snnz commented on GitHub (Nov 24, 2024): There is an explicit rule in the [specs](https://github.com/xoofx/markdig/blob/master/src/Markdig.Tests/Specs/PipeTableSpecs.md): > 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)?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#697