Skip to content

Codex/issue 2376 preserve self closing tags#2452

Open
SarthakDudhe wants to merge 11 commits into
beautifier:mainfrom
SarthakDudhe:codex/issue-2376-preserve-self-closing-tags
Open

Codex/issue 2376 preserve self closing tags#2452
SarthakDudhe wants to merge 11 commits into
beautifier:mainfrom
SarthakDudhe:codex/issue-2376-preserve-self-closing-tags

Conversation

@SarthakDudhe
Copy link
Copy Markdown

Fixed #2376 by adding a new HTML option, preserve_self_closing_tags, that keeps the no-space self-closing form like
and <path .../> instead of normalizing it to
.

What changed:
Added preserve_self_closing_tags to js/src/html/options.js
Updated the HTML tag-close printer in js/src/html/beautifier.js so it skips inserting the extra space before /> when this option is enabled
Registered the new CLI option in js/src/cli.js
Documented the option in README.md
Added regression coverage in test/data/html/tests.js
Behavior now:

Default behavior stays the same, so
still formats as

With preserve_self_closing_tags=true, the formatter keeps
as

The same applies to SVG-style self-closing tags like
Validation:
Ran node test/generate-tests.js
Verified both HTML and SVG examples locally

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.

Trim trailing commas and don't add spaces before/after brackets with inline objects

1 participant