Escape a paragraph line that would reparse as a table delimiter row - #19877
Open
Kjubikstronk wants to merge 2 commits into
Open
Escape a paragraph line that would reparse as a table delimiter row#19877Kjubikstronk wants to merge 2 commits into
Kjubikstronk wants to merge 2 commits into
Conversation
β Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
β Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #19847.
Description
A GFM delimiter row indented by four or more spaces is not a table, but after formatting it becomes one, so the second run produces different output:
Cause
remark only accepts a delimiter row indented up to three spaces, so at four the two lines are a plain paragraph and arrive as a single text node with the indentation already stripped. Printing a paragraph drops leading whitespace on continuation lines, which is insignificant everywhere else, but here it turns the text into a valid table.
Change
Escaping the delimiter row so it cannot be re-parsed, which is what the same file already does for the analogous case one line up:
The issue asks for the table to be printed on the first run instead. That would change what the document renders as β the input is a paragraph, and a table is not the same output β so this keeps it a paragraph, consistent with the setext case.
The line is reconstructed from the sentence's sibling nodes rather than from
options.originalText. A delimiter row is only|,-,:and spaces, so it is always contained in one sentence, and reading it from the AST means blockquote and list markers never enter the picture.One thing I left out deliberately: GFM only forms a table when the header row and the delimiter row have the same number of cells, and this does not check that, so a delimiter row under a header with a different cell count is escaped although no table would have formed. Counting the header's cells means reconstructing a line that can span several nodes once it contains emphasis or code spans. No existing snapshot changed without it β happy to add it if you would rather have the exact rule.
Tests
tests/format/markdown/paragraph/issue-19847.md, which runs under all threeproseWrapmodes and covers the compact, spaced, aligned and no-outer-pipe delimiter shapes, a single-cell row, blockquote and list item nesting, and a trailing paragraph line. Two cases in it should not change: a three-space indent is a real table and still prints as one, and a delimiter row alone after a blank line is an indented code block.tests/format/{markdown,mdx}: 1503 snapshots, none of the existing ones changed. Full suite is unchanged against a stashed tree β same four failing suites either way,patterns-dirs.jsand threejsxsuites that fail onmainhere too.I also checked idempotency and meaning over 576 generated combinations of header shape, delimiter shape, indent width and container, comparing the parsed tree before and after formatting: no instability and no case where the escape changed what the document parses to.
Checklist
docs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.This PR was written with AI assistance, and reviewed before submitting.