Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dusanrad opened this issue Sep 28, 2024 · 3 comments
Open
Labels

Comments

@dusanrad
Copy link

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.

@yilihamujiang365-new
Copy link

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

@xoofx xoofx added the wontfix label Oct 15, 2024
@xoofx
Copy link
Owner

xoofx commented 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.

@snnz
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants