Fix pipe table parsing with a leading paragraph#905
Conversation
|
Alternative approach that'd get us the expected syntax tree shape and avoids modifying the renderer: master...MihaZupan:table-para2 Could theoretically break someone that wanted to look at the table shape from a different parser (since the table isn't inserted until later), but that seems less likely? |
Yes, maybe that workaround is ok. Table parsing is a bit awful unfortunately, so this new code doesn't change that 😅 |
|
Can the same logic that's used for GridTable parsing to find the start of the block? GridTables seem to have the correct behavior. ps. I haven't had time to look at the code beyond what was posted here, just going on the rendering behavior in the current 0.42 release. |
|
Maybe. I haven't been bored enough yet to look at what it'd take to turn it into a block parser instead 😄 |
|
Yeah I know what you mean - I took a look at the code a few days ago thinking I could help in a hurry, but without setting aside a good chunk of time to understand the flow these block parsers are easy to mess up. I made a custom fix a few years ago and discovered months later it was breaking in completely unexpected ways. Thanks for your effort here - really appreciate you taking the time! Aloha. |
|
Note that this change makes it work when you have leading text before the table. |
NOTE: This doesn't include the current newest `Markdig` version 0.43.0, as this has introduced some rendering issues with pipe tables. - A fix made for "tables with leading paragraphs" results in *adding* a leading paragraph to tables which shouldn't have one. xoofx/markdig#905 Notable changes in the test project: - `MSTest.TestFramework` upgrades deprecated and removed the "ExpectedException" attribute, in favor of `Assert.Throws...()` test assertions. - It's also deprecated assertions on enumerable/collection Count values, in favor of countable assertion methods like `IsEmpty()` and `HasCount()`. - AND, its analyzer now throws an error if there's no explicit Parallelize setting.
Closes #818
Addresses issues referenced in #885 (comment), #885 (comment)
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" would be lost.
Instead I relaxed the table validation to no longer enforce starting on the first line (
localLineIndex > 0anddeltaLine > 0checks), 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
we're instead producing
Since
TableRowis a public type, this does risk breaking code that was walking the AST and assuming that all children of aTableareTableRows - this seems plausible given our own renderer did that.I'm open to alternative suggestions.