Skip to content

fix(ExportHtml): preserve nested ol start across sibling ul#7791

Merged
JohnMcLear merged 1 commit into
developfrom
fix/exporthtml-nested-ol-start
May 17, 2026
Merged

fix(ExportHtml): preserve nested ol start across sibling ul#7791
JohnMcLear merged 1 commit into
developfrom
fix/exporthtml-nested-ol-start

Conversation

@JohnMcLear
Copy link
Copy Markdown
Member

Summary

Round-tripping <ul>...<ul>...</ul></ul><ol><li>x<ol><li>y</li></ol></li></ol> through setHTMLgetHTML was emitting the inner <ol> as <ol class=\"number\"> instead of the expected <ol start=\"2\" class=\"number\">.

Root cause: the depth-decrease loop in getHTMLFromAtext resets olItemCounts[level] = 0 to signal "this ol level was explicitly closed, don't fall back to line.start next time it reopens" (#7470). The gate only checked depth, not list type, so closing a bullet <ul> at depth 2 was also writing olItemCounts[2] = 0. When a later, unrelated <ol> opened at depth 2, the ol-opening logic took the "counter exists but is 0" branch and dropped line.start.

Fix: only run the counter reset when the line being closed is itself a number list. UL closures no longer touch ol bookkeeping.

Trade-off

The 0-sentinel design from #7470 still applies for genuine ol-close cases — if you close an ol and reopen one later at the same depth, line.start is still ignored (per that PR's intent). This change narrows the gate; it doesn't reverse the prior decision.

Test plan

Backend sweep on a fresh develop clone (Node 24.14.0):

Note: these failures are currently invisible in CI because of the broken backend test glob — see #7789, which has to land for CI to actually run these tests.

Fixes #7786
Fixes #7787

🤖 Generated with Claude Code

When an ordered-list level was the only consumer of olItemCounts,
closing any list at that depth (including an unordered list that
happens to share the level) reset olItemCounts[level] to 0. A later,
unrelated ordered list at the same depth then took the
"counter exists but is 0" branch in the ol-opening logic and emitted
`<ol class="...">` without the start attribute that line.start would
have supplied.

Round-trip: importing
  <ul>...<ul>...</ul></ul><ol><li>x<ol><li>y</li></ol></li></ol>
exported the inner ol as `<ol class="number">` instead of
`<ol start="2" class="number">`, because the closing of the inner
bullet ul wrote olItemCounts[2]=0 before the outer ol even opened.

Gate the reset on line.listTypeName === 'number' so closing an
unordered list never touches the ol bookkeeping. Closing an actual
ordered list still resets, as #7470 intended.

Fixes #7786
Fixes #7787

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@qodo-code-review
Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Review Summary by Qodo

Prevent ul closure from poisoning ol counter at same depth

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fix nested ordered list start attribute loss when sibling unordered list closes
• Gate ordered-list counter reset on list type to prevent unordered list closures from poisoning ol
  bookkeeping
• Preserve line.start for unrelated ordered lists at same depth after unordered list closure
Diagram
flowchart LR
  A["Closing UL at depth N"] --> B["Check list type"]
  B --> C["Type is 'number'?"]
  C -->|Yes| D["Reset olItemCounts[N]"]
  C -->|No| E["Skip reset"]
  D --> F["Later OL at depth N uses line.start"]
  E --> F
Loading

Grey Divider

File Changes

1. src/node/utils/ExportHtml.ts 🐞 Bug fix +4/-1

Gate ol counter reset on list type check

• Added type check line.listTypeName === 'number' to gate the olItemCounts reset logic
• Only reset ordered-list counter when closing an actual ordered list, not unordered lists
• Updated comment to clarify that unordered list closures must not affect ol bookkeeping
• Prevents unrelated ordered lists at same depth from losing their start attribute

src/node/utils/ExportHtml.ts


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented May 17, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

@JohnMcLear JohnMcLear merged commit 8f499b4 into develop May 17, 2026
31 checks passed
@JohnMcLear JohnMcLear deleted the fix/exporthtml-nested-ol-start branch May 17, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant