Skip to content

fix: normalizer adding empty list items for whitespace around blocks - #830

Open
RaphaelFakhri wants to merge 1 commit into
software-mansion:mainfrom
RaphaelFakhri:fix/normalizer-li-whitespace
Open

RaphaelFakhri wants to merge 1 commit into
software-mansion:mainfrom
RaphaelFakhri:fix/normalizer-li-whitespace

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Summary

Fixes #829.

When a list item contains block children separated by whitespace, the HTML normalizer turns each whitespace run into its own empty list item. This is the shape CommonMark renderers produce for loose lists (<li>\n<p>a</p>\n</li>), and it is common in pretty-printed HTML. With useHtmlNormalizer enabled (the default), a two-item list gets four extra empty list items.

flush_li_buffer (C) and flushLiBuffer (web port) only skipped an empty buffer. They now also skip a whitespace-only buffer, the same check flush_inline_p already uses for inter-block whitespace. Intentionally empty <li></li> items are still emitted, as covered by EmptyListItems.

Impacts the HTML normalizer on iOS, Android (shared cpp/parser/GumboNormalizer.c) and web (src/web/normalization/htmlNormalizer.ts).

Test Plan

  • cd cpp && cmake -B build && cmake --build build && ctest --test-dir build: InterBlockWhitespace has two new cases. Without the fix it fails with <ul><li>\n</li><li>a</li><li>\n</li><li>\n</li><li>b</li><li>\n</li></ul>; with the fix all 15 tests pass.
  • yarn jest --selectProjects web src/web/__tests__/htmlNormalizer.test.ts: the same two cases fail without the fix (2 failed, 425 passed) and pass with it (427 passed).

Screenshots / Videos

Not applicable. The change is covered by the normalizer unit tests.

Compatibility

OS Implemented
iOS ✅
Android ✅
Web ✅

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

Copilot AI balanced review requested due to automatic review settings October 21, 2026 08:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused changes are consistent across platforms, have matching regression coverage, and leave no unresolved review findings.

No open issues 🎉

Review effort: Balanced

@exploIF exploIF self-assigned this Oct 23, 2026

This branch has not been deployed

No deployments
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.

HTML normalizer adds empty list items for whitespace around blocks inside <li>

3 participants