Skip to content

Fix indentation of nested elements in preserved mixed content - #1047

Open
Kaiserunix wants to merge 1 commit into
prettier:mainfrom
Kaiserunix:codex/preserve-mixed-content-indent
Open

Fix indentation of nested elements in preserved mixed content#1047
Kaiserunix wants to merge 1 commit into
prettier:mainfrom
Kaiserunix:codex/preserve-mixed-content-indent

Conversation

@Kaiserunix

Copy link
Copy Markdown

Fixes #995.

With xmlWhitespaceSensitivity: "preserve", an element following a text sibling loses one indentation level inside its body. Wrap the preserved fragments in the existing indent document builder, so child documents retain their parent indentation. Literal text whitespace continues to use literalline and remains unchanged.

Add regression coverage for nested mixed content with 2- and 4-space indentation, tabs, formatting stability, inline text whitespace, and xml:space="preserve" across all whitespace modes. Update only the two affected indentation lines in the existing preserve snapshot.

Validation on Windows, Node 25.8.1, Prettier 3.9.6:

  • Three regression tests fail before the fix; all 24 tests and 11 snapshots pass afterward (npm test -- --runInBand).
  • The original public prettier.format reproduction passes with unchanged assertions, including strict and element-only controls.
  • npm run lint, formatting checks for the changed files, and git diff --check pass.
  • Full formatting passes with --end-of-line auto. The default full check flags pre-existing Windows CRLF checkout files; their HEAD blobs and LF-normalized contents pass the formatter. Unrelated files were not rewritten.

Linux/CI Node 20 was not run locally. This patch and its tests were prepared with AI assistance.

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.

Incorrect indentation with xmlWhitespaceSensitivity "preserve" inside a sibling of a text node

1 participant