[PR #905] Fix pipe table parsing with a leading paragraph #1301

Closed
opened 2026-01-29 14:52:49 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/xoofx/markdig/pull/905

State: closed
Merged: Yes


Closes #818
Addresses issues referenced in https://github.com/xoofx/markdig/pull/885#issuecomment-3419948799, https://github.com/xoofx/markdig/pull/885#issuecomment-3419969194

This PR effectively reverts #885 as that change was swallowing whatever information was there in the paragraph before the table.
E.g. for

Some text
| A |
|---|
| B |

"Some text" would be lost.

Instead I relaxed the table validation to no longer enforce starting on the first line (localLineIndex > 0 and deltaLine > 0 checks), and also save the current block in the AST before we replace it with a table.

Given this is happening while we're parsing inlines, I don't think we can easily insert an extra block at the current layer, so I instead added the leading paragrah as the first child of the table, and the first element is special-cased in the renderer.
That is, instead of

document
  paragraph
    some text
  table
    A ...

we're instead producing

document
  table
    paragraph
      some text
    A ...

Since TableRow is a public type, this does risk breaking code that was walking the AST and assuming that all children of a Table are TableRows - this seems plausible given our own renderer did that.
I'm open to alternative suggestions.

**Original Pull Request:** https://github.com/xoofx/markdig/pull/905 **State:** closed **Merged:** Yes --- Closes #818 Addresses issues referenced in https://github.com/xoofx/markdig/pull/885#issuecomment-3419948799, https://github.com/xoofx/markdig/pull/885#issuecomment-3419969194 This PR effectively reverts #885 as that change was swallowing whatever information was there in the paragraph before the table. E.g. for ```md Some text | A | |---| | B | ``` "Some text" would be lost. Instead I relaxed the table validation to no longer enforce starting on the first line (`localLineIndex > 0` and `deltaLine > 0` checks), and also save the current block in the AST before we replace it with a table. Given this is happening while we're parsing inlines, I don't think we can easily insert an extra block at the current layer, so I instead added the leading paragrah as the first child of the table, and the first element is special-cased in the renderer. That is, instead of ``` document paragraph some text table A ... ``` we're instead producing ``` document table paragraph some text A ... ``` Since `TableRow` is a public type, this does risk breaking code that was walking the AST and assuming that all children of a `Table` are `TableRow`s - this seems plausible given our own renderer did that. I'm open to alternative suggestions.
claunia added the pull-request label 2026-01-29 14:52:50 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#1301