Allow paragraphs before tables#420
Conversation
|
The behaviour of pulldown-cmark is the same as github. It's just how Github-flavoured Markdown (GFM) defines tables. Text
|foo|bar|
--- | ---
baz | quxconverts to Text
while Text
|foo|bar|
--- | ---
baz | quxconverts to Text
|
|
Thank you for the pull request. It's not clear to me whether the GFM spec or CommonMark actually prescribe how to handle this. If not, we should probably ask for explicit clarification. @oberien: while we are targeting GFM for tables, we try to comply with the spec and not match their implementation per se. |
Notice that each other Leaf Block type has at least one specific example that tells whether or not that type can interrupt a paragraph. The authors of the GFM tables extension failed to state whether that type can interrupt a paragraph or not. |
|
See also this: github/cmark-gfm#141 Apparently some time ago cmark-gfm tried to allow that tables can interrupt the preceding paragraph but my testing shows they still have some bugs related to it. |
|
My older comment (#420 (comment)) didn't seem to age too well. Apparently now it just works in GFM on github?! |
|
@oberien It works sometimes. This works:
This does not:
|
|
@mity it seem like Github has updated once again: your comment now renders a paragraph followed by a table both times. (screenshot below) |
|
Interesting. Do they still use cmark-gfm? Because https://github.com/github/cmark-gfm has seen the last commit in September 2019. EDIT: There is also still opened github/cmark-gfm#180 and according to my current test, it is still valid. |
|
I see here different features in the same pull request, @terhechte. Tables interrupting paragraphs is a feature to be included in the 0.10 release, since it is the GitHub Flavor Markdown behavior, but the other three commits should be removed before merging. The best approach is probably to create a new pull request from the current master branch and to close this pull request without merging. Thanks. |

I'm running into all kinds of corner cases with one of my projects, this being another one. It is even more tricky because tables are not part of CommonMark so it is less clear what the right behavior is. The problem this PR solves is that a table that has a paragraph right before it will not be parsed:
Becomes a long paragraph the table syntax as part of the paragraph.
This PR fixes that and inserts a
Helloparagraph before the table in the parsed markdown. In my project, I kind of rely on the possibility of having a paragraph before an element which is how I ran into this issue. I did some research to see how other projects, notably GitHub render the example above.Interestingly, GitHub exhibits the same issue in their markdown parsing, while this online editor supports it just fine.
However, other examples, such as
render correctly on GitHub. It is only paragraphs, that are not supported right before a table. Therefore, at least to me, this feels more like an accidental bug than correct behavior.
Personally, for me, it would be great if this would be merged, as I'd need to continue using a fork otherwise. Another, maybe, viable option might be to have this behavior be optional via a feature flag (although I can see that this is a road that, once taken, can lead to madness if more and more of the non-standardized idiosyncratic markdown features end up as feature flags).
This PR also contains tests, and I'd be more than happy to improve the code if it is not up to the quality standards of pulldown-cmark.