Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
ly-wang19 wants to merge 1 commit into
THU-MAIC:main from
ly-wang19:fix/html-stringify-empty-style-attr
Open

fix(export): keep sibling attributes when style is empty #683
ly-wang19 wants to merge 1 commit into
THU-MAIC:main from
ly-wang19:fix/html-stringify-empty-style-attr

Conversation

@ly-wang19

@ly-wang19 ly-wang19 commented Jun 7, 2026

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 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

formatAttributes drops earlier attributes when style is empty

1 participant

AltStyle によって変換されたページ (->オリジナル) /