Issue rendering tables with leading paragraph #325

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

Originally created by @olipo186 on GitHub (Sep 23, 2019).

Hi,

I noticed this different while rendering some markdown markup into HTML. Is this expected behavior? Shouldn't tables be rendered properly regardless of whether there's text just before it or not?

I'm converting using the following;

var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
var html = Markdown.ToHtml(markdown, pipeline);

Test case 1: No extra line break added

Input

Hello world
| a | b |
|---|---|
| c | d |

Output

<p>Hello world | a | b | |---|---| | c | d |</p>

Test case 2: Extra line break added

Input

Hello world

| a | b |
|---|---|
| c | d |

Output

<p>Hello world</p>
<table>
    <thead>
        <tr>
            <th>a</th>
            <th>b</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>c</td>
            <td>d</td>
        </tr>
    </tbody>
</table>
Originally created by @olipo186 on GitHub (Sep 23, 2019). Hi, I noticed this different while rendering some markdown markup into HTML. Is this expected behavior? Shouldn't tables be rendered properly regardless of whether there's text just before it or not? I'm converting using the following; ``` var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); var html = Markdown.ToHtml(markdown, pipeline); ``` **Test case 1: No extra line break added** Input ``` Hello world | a | b | |---|---| | c | d | ``` Output ``` <p>Hello world | a | b | |---|---| | c | d |</p> ``` **Test case 2: Extra line break added** Input ``` Hello world | a | b | |---|---| | c | d | ``` Output ``` <p>Hello world</p> <table> <thead> <tr> <th>a</th> <th>b</th> </tr> </thead> <tbody> <tr> <td>c</td> <td>d</td> </tr> </tbody> </table> ```
claunia added the questionwontfix labels 2026-01-29 14:33:50 +00:00
Author
Owner

@xoofx commented on GitHub (Sep 23, 2019):

It is the behavior of GitHub Flavored Markdown as well, check on babelmark here

Here is the text:

Hello world

a b
c d

And you can see that it doesn't show up correctly, while

Hello world

a b
c d

is working.

Let's say that it is by design 😅

The underlying story is that it complicates a lot the parsing story if we support attached paragraph, because under the hood, Markdig is actually working on a paragraph level to detect a table, and it would likely complicate the parsing to do it in the middle.

@xoofx commented on GitHub (Sep 23, 2019): It is the behavior of GitHub Flavored Markdown as well, check on babelmark [here](https://babelmark.github.io/?text=Hello+world%0A%7C+a+%7C+b+%7C%0A%7C---%7C---%7C%0A%7C+c+%7C+d+%7C) Here is the text: Hello world | a | b | |---|---| | c | d | And you can see that it doesn't show up correctly, while Hello world | a | b | |---|---| | c | d | is working. Let's say that it is by design 😅 The underlying story is that it complicates a lot the parsing story if we support attached paragraph, because under the hood, Markdig is actually working on a paragraph level to detect a table, and it would likely complicate the parsing to do it in the middle.
Author
Owner

@olipo186 commented on GitHub (Oct 24, 2019):

I agree with your conclusion. This seems to be an edge case that is handled slightly different by various markdown parsers. Most of the parsers seem to align with the behavior of Markdig however, and I haven't been able to find any "spec" for the markdown table syntax that covers this.

Thanks for your reply @xoofx, feel free to close the issue!

@olipo186 commented on GitHub (Oct 24, 2019): I agree with your conclusion. This seems to be an edge case that is handled slightly different by various markdown parsers. Most of the parsers seem to align with the behavior of Markdig however, and I haven't been able to find any "spec" for the markdown table syntax that covers this. Thanks for your reply @xoofx, feel free to close the issue!
Author
Owner

@ecooke-macu commented on GitHub (Jul 19, 2023):

Now that github renders the tables with a leading line with text as expected, a table underneath it, is this something worth looking into?

For example

sometext
|col1|col2|
|-|-|
|a|line|

Markdig rendered output:

<p>sometext
|col1|col2|
|-|-|
|a|line|</p>

Github:

sometext

col1 col2
a line
@ecooke-macu commented on GitHub (Jul 19, 2023): Now that github renders the tables with a leading line with text as expected, a table underneath it, is this something worth looking into? For example ```markdown sometext |col1|col2| |-|-| |a|line| ``` ## Markdig rendered output: ```html <p>sometext |col1|col2| |-|-| |a|line|</p> ``` ## Github: sometext |col1|col2| |-|-| |a|line|
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#325