Skip to content

Add support for a table without an extra new line before it - #885

Merged
xoofx merged 1 commit into
xoofx:masterfrom
dannyp32:supportTableWithoutExtraLine
Aug 28, 2025
Merged

Add support for a table without an extra new line before it#885
xoofx merged 1 commit into
xoofx:masterfrom
dannyp32:supportTableWithoutExtraLine

Conversation

@dannyp32

@dannyp32 dannyp32 commented Aug 9, 2025

Copy link
Copy Markdown
Contributor

Fixes the following issue where a table will not be rendered if there isn't an extra line before the table.
#818

For example this will not render correctly

Here is the table:
| Key   | Value    |
| ----  | -------- |
| Color | Blue     |
| Size  | Medium   |

But this will because there's an extra new line before the table starts

Here is the table:

| Key   | Value    |
| ----  | -------- |
| Color | Blue     |
| Size  | Medium   |

Not handled in this change - whitespace between the new line and the pipe

@dannyp32

Copy link
Copy Markdown
Contributor Author

@xoofx hoping you can take a look. Open to any suggestions

@xoofx
xoofx merged commit c436465 into xoofx:master Aug 28, 2025
1 check passed
@xoofx

xoofx commented Aug 28, 2025

Copy link
Copy Markdown
Owner

Thanks for this. I will have to double check some stuffs but it could be enough.

@RickStrahl

Copy link
Copy Markdown
Contributor

Checking in 0.42.0 - looks like this works for Grid Tables but not for Pipe Tables.

image

@MihaZupan

Copy link
Copy Markdown
Collaborator

Possibly an issue with how we're dealing with new lines in this change.
The PR added tests for a\r|... and a\n|... - if I change that to \r\n instead it fails.

@MihaZupan

Copy link
Copy Markdown
Collaborator

Looks like this change is also removing the content before the table

string md =
    """
    Some text
    | A |
    |---|
    | B |
    """.ReplaceLineEndings("\n");
    
var pipeline = new MarkdownPipelineBuilder()
    .UsePipeTables()
    .Build();

Console.WriteLine(Markdown.ToHtml(md, pipeline));

(note the missing "some text")

<table>
<thead>
<tr>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>B</td>
</tr>
</tbody>
</table>

And it doesn't match the table if the text before it is more than one line (not sure if this was intentional).

@RickStrahl

Copy link
Copy Markdown
Contributor

FWIW - I normalize my linefeeds to LF before sending to Markdig, so that's not the issue I'm seeing...

@MihaZupan

Copy link
Copy Markdown
Collaborator

I suspect that your case hit this

And it doesn't match the table if the text before it is more than one line (not sure if this was intentional).

Should be fixed with #905 to allow multiple lines of text to precede the table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants