Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix, and document, some table/paragraph interrupt corner cases #672

Merged

Conversation

notriddle
Copy link
Collaborator

Fixes #540

interrupting paragraphs with tables

Pulldown-cmark gives "heavy" tables (with a leading |) higher priority than "light" tables for paragraph interruption. This is compatible with older versions of GitHub, but 2023-06-21 GitHub treats them the same.

A quick run through https://babelmark.github.io shows, of the implementations that support pipe tables at all1:

Implementation -> a b c d e f g h i j
pulldown-cmark x x x x x x x
github/cmark-gfm x x x
pycmarkgfm x x x
DFM2 - - x
league/commonmark GFM x x
s9e/TextFormatter x x x
markdown-it34 x x x - -
php-markdown-extra x x x x x
markdig x x x x x x x x x x
MD4C x x x x x x x x x x
parsedown x x x x x x x x x x
maruku3 x x x x x x x x x -
cebe x x x x x x x x x x
pandoc x x x x x x x x x x
multimarkdown x x x x x x x x x x
  • A lot of Extended Markdown parsers don't allow tables to interrupt paragraphs at all, even if they support pipe tables in general.

  • Out of the ones that do, about half of them do what GitHub does and disallow it when the table is indented by four or more spaces.

ambiguity between "light" tables and h2

This PR also changes scan_table_head to refuse any table with zero pipes at all in its header line. This resolves an ambiguity with settext-style <h2>, and matches every other Markdown implementation I could fine in Babelmark (see interrupting paragraphs with tables, "table j"), except maruku and markdown-it, which behave very strangely.

ambiguity with "light" tables and bulleted lists with -

This PR adds a test case for the existing behavior on tables like this:

a | b
- | -
1 | 2

It doesn't change the behavior, but it does document it.

Implementation -> parsed as
pulldown-cmark table
github/cmark-gfm list
pycmarkgfm list
markdown-it table
php-markdown-extra table
DFM table
league/commonmark GFM list
s9e/TextFormatter table
markdig table
MD4C list
parsedown table
maruku table
cebe table
pandoc table
multimarkdown table
hard line breaks are not allowed at the end of table header lines

Hard line breaks are not allowed at the end of table header lines. It's about a 50:50 split on babelmark, but this change makes pulldown-cmark consistent with GFM and Pandoc.

Implementation -> parsed as
pulldown-cmark paragraph
github/cmark-gfm paragraph
pycmarkgfm paragraph
markdown-it table
php-markdown-extra table
DFM table
league/commonmark GFM paragraph
s9e/TextFormatter table
markdig paragraph
MD4C paragraph
parsedown table
maruku table
cebe paragraph
pandoc paragraph
multimarkdown table

Footnotes

  1. Implementations that "support pipe tables at all" were identified by
    including "table a" without a preceding paragraph and seeing if it
    produced an HTML table for that.

  2. On "table h" and "table i", DFM sees a table with no cells, followed
    by a paragraph with b in it.

  3. On "table j", maruku and markdown-it see a table with no cells, followed
    by a paragraph with b in it. 2

  4. On "table i", markdown-it sees a table with no cells, followed
    by a paragraph with b in it.

@Martin1887
Copy link
Collaborator

Thanks!, I will try to review it this week.

@Martin1887
Copy link
Collaborator

It looks fine, thanks!

@Martin1887 Martin1887 merged commit 33d4fbb into pulldown-cmark:master Jun 22, 2023
@notriddle notriddle deleted the notriddle/table-paragraph-interrupt branch June 22, 2023 16:43
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.

GFM tables without leading empty lines inside list items are interpreted incorrectly as plain text
2 participants