-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(export): keep sibling attributes when style is empty#683
Open
ly-wang19 wants to merge 1 commit into
Open
Conversation
formatAttributes is a reduce; the empty-style branch returned '' instead of the accumulator, so every attribute emitted before an empty `style=""` attribute was dropped on stringify (e.g. `<div class="x" style=""> -> <div>`). Return `attrs` to omit the empty style while keeping the rest. Closes THU-MAIC#682
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.
What & why
formatAttributes(lib/export/html-parser/stringify.ts) is areduce, but the empty-stylebranch returns `` — which becomes the next accumulator — instead of the accumulated string:So every attribute emitted before an empty
style=""is dropped on stringify. For[{class:"foo"}, {style:""}, {id:"bar"}],toHTMLproduces<div id="bar">—class="foo"is lost.toHTMLcallsformatAttributesfor every element, so this hits any HTML round-trip (edit/export) where an element has an emptystyleafter another attribute.Closes #682.
Fix
Return the accumulator:
return attrs;— still omits the emptystyleattribute, but keeps the others.Test plan
New
tests/export/html-stringify.test.ts(4 cases, all green): emptystyleno longer dropsclass/id; non-emptystylepreserved; boolean (null-value) attributes; and atoHTMLround-trip keeping sibling attributes.tsc/prettier/eslintclean.No user-facing strings (no i18n impact).