Skip to content

Escape indented table delimiter rows - #19929

Open
fahadhewad wants to merge 1 commit into
prettier:mainfrom
fahadhewad:escape-indented-table-delimiter-row
Open

Escape indented table delimiter rows#19929
fahadhewad wants to merge 1 commit into
prettier:mainfrom
fahadhewad:escape-indented-table-delimiter-row

Conversation

@fahadhewad

Copy link
Copy Markdown

Description

Fixes #19847.

A table delimiter row that is indented by four spaces or more is a lazy continuation line of the paragraph above it, not part of a table. Prettier dropped that indentation without escaping the row, so the paragraph was parsed as a table on the next run, and formatting was not idempotent.

<!-- Input -->
| a | b |
        | - | - |
| 1 | 2 |

<!-- Prettier stable, first run -->
| a | b |
| - | - |
| 1 | 2 |

<!-- Prettier stable, second run -->
| a   | b   |
| --- | --- |
| 1   | 2   |

<!-- Prettier main -->
| a | b |
\| - | - |
| 1 | 2 |

Such a row is now escaped, the same way an indented pseudo setext header is already escaped in printWord. The escape applies only with proseWrap set to preserve, because the other modes join the line with the previous one, and it is skipped when the line starts with a marker that already makes the two lines join. Delimiter rows written without outer pipes, such as --- | ---, drift in the same way and are covered as well.

The leading marker pattern that decides whether two lines are joined now lives in utilities.js, so both call sites share it.

The full test suite passes, the existing markdown and mdx snapshots are unchanged, and --debug-check reports no AST change for the affected inputs.

This change was written with AI assistance, so the box about not using AI is left unchecked.

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.
  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.
A table delimiter row indented by four spaces or more is part of a
paragraph rather than of a table. Its indentation was dropped without
escaping the row, so the paragraph was parsed as a table the next time
the file was formatted, which made formatting not idempotent.

Escape such a row instead, the way an indented pseudo setext header is
already escaped.
@netlify

netlify Bot commented Aug 28, 2026

Copy link
Copy Markdown

Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 2f855ce
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a9159f7c0ece40008ad5fb3
😎 Deploy Preview https://deploy-preview-19929--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

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

Labels

None yet

1 participant