Skip to content

Preserve spaces after removed inlines - #29

Merged
j9t merged 1 commit into
mainfrom
fix/removed-element-space
Nov 24, 2026
Merged

j9t merged 1 commit into
mainfrom
fix/removed-element-space

Conversation

@j9t

@j9t j9t commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where removing an empty inline element could also remove the space before following content. Whitespace is now preserved when the preceding content does not render, including when that content is a script. This applies whether or not the original markup included whitespace around the empty element.

Keep whitespace when `removeEmptyElements` removes an inline element after an element that doesn’t render, such as a non-empty `script`. Add regression coverage and document the fix in the changelog.

(This commit message was AI-generated.)
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The minifier now treats a removed empty element after a non-rendering element as affecting whitespace. Regression assertions cover spacing after a non-empty script, and the changelog records the fix.

Changes: Whitespace preservation

Layer / File(s) Summary
Removed-element whitespace handling
src/htmlminifier.js, test/html.test.js, CHANGELOG.md
The removal logic now sets followsRemovedBlock when the preceding tag is in inlineElementsTransparentAfter. Regression assertions check spacing after a non-empty script, and the changelog documents the issue.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: Minimal · up to 27330

This fix preserves spaces after an empty inline element is removed following a non-rendering element such as a script. It has no identified merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Preserve spaces after removed inlines" matches the main change. The changeset fixes whitespace loss: when removeEmptyElements and collapseWhitespace remove an empty inline element after a n…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Preserve spaces after removed inlines" matches the main change. The changeset fixes whitespace loss: when removeEmptyElements and collapseWhitespace remove an empty inline element after a non-rendering element, the following space was dropped. The htmlminifier.js change and the regression tests address this, and the title names that behavior. It is concise, specific, and consistent with the PR objectives.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.3)

test/html.test.js

ast-grep timed out on this file

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5bb8d505-ca59-4cc9-9755-b059e54837e1
Commits

Reviewing files that changed from the base of the PR and between 272866c and 273304a.

Files selected for processing: 3

  • CHANGELOG.md
  • src/htmlminifier.js
  • test/html.test.js

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@j9t
j9t merged commit 86b916d into main Nov 24, 2026
10 checks passed
@j9t
j9t deleted the fix/removed-element-space branch November 24, 2026 15:29
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.

1 participant