Skip to content

fix(export): keep sibling attributes when style is empty#683

Merged
wyuc merged 2 commits into
THU-MAIC:mainfrom
ly-wang19:fix/html-stringify-empty-style-attr
Jul 1, 2026
Merged

fix(export): keep sibling attributes when style is empty#683
wyuc merged 2 commits into
THU-MAIC:mainfrom
ly-wang19:fix/html-stringify-empty-style-attr

Conversation

@ly-wang19

Copy link
Copy Markdown
Contributor

What & why

formatAttributes (lib/export/html-parser/stringify.ts) is a reduce, but the empty-style branch returns `` — which becomes the next accumulator — instead of the accumulated string:

if (key === "style" && !value) return "";   // resets the accumulator

So every attribute emitted before an empty style="" is dropped on stringify. For [{class:"foo"}, {style:""}, {id:"bar"}], toHTML produces <div id="bar">class="foo" is lost. toHTML calls formatAttributes for every element, so this hits any HTML round-trip (edit/export) where an element has an empty style after another attribute.

Closes #682.

Fix

Return the accumulator: return attrs; — still omits the empty style attribute, but keeps the others.

Test plan

New tests/export/html-stringify.test.ts (4 cases, all green): empty style no longer drops class/id; non-empty style preserved; boolean (null-value) attributes; and a toHTML round-trip keeping sibling attributes. tsc/prettier/eslint clean.

No user-facing strings (no i18n impact).

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
@wyuc wyuc merged commit eca6811 into THU-MAIC:main Jul 1, 2026
2 checks passed
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.

formatAttributes drops earlier attributes when style is empty

2 participants