Skip to content

Allow paragraphs before tables#420

Closed
terhechte wants to merge 5 commits intopulldown-cmark:masterfrom
terhechte:master
Closed

Allow paragraphs before tables#420
terhechte wants to merge 5 commits intopulldown-cmark:masterfrom
terhechte:master

Conversation

@terhechte
Copy link

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:

Hello
| abc | def |
| --- | --- |
| bar | baz |

Becomes a long paragraph the table syntax as part of the paragraph.

This PR fixes that and inserts a Hello paragraph 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

# Hello
| abc | def |
| --- | --- |
| bar | baz |

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.

@oberien
Copy link
Contributor

oberien commented Jan 4, 2020

The behaviour of pulldown-cmark is the same as github. It's just how Github-flavoured Markdown (GFM) defines tables.
In general, things in pulldown-cmark that are not part of CommonMark are usually part of GFM.

Text
|foo|bar|
--- | ---
baz | qux

converts to

Text

foo bar
baz qux

while

Text

|foo|bar|
--- | ---
baz | qux

converts to

Text

foo bar
baz qux

@marcusklaas
Copy link
Collaborator

marcusklaas commented Jan 6, 2020

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.

@ScottAbbey
Copy link
Collaborator

If not, we should probably ask for explicit clarification.

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.

@mity
Copy link

mity commented Feb 24, 2020

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.

@oberien
Copy link
Contributor

oberien commented Feb 24, 2020

My older comment (#420 (comment)) didn't seem to age too well. Apparently now it just works in GFM on github?!

@mity
Copy link

mity commented Feb 24, 2020

@oberien It works sometimes.

This works:

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

foo

a b
c d

This does not:

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

foo

a b
c d

@expectocode
Copy link
Contributor

@mity it seem like Github has updated once again: your comment now renders a paragraph followed by a table both times. (screenshot below)
image

@mity
Copy link

mity commented May 14, 2020

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.

@Martin1887
Copy link
Collaborator

Martin1887 commented May 18, 2023

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants