Skip to content

fix(mail): keep list markers next to block content in plain-text bodies - #610

Open
Suyog007 wants to merge 1 commit into
tokio-rs:mainfrom
Suyog007:fix/mail-list-marker-breaks
Open

Suyog007 wants to merge 1 commit into
tokio-rs:mainfrom
Suyog007:fix/mail-list-marker-breaks

Conversation

@Suyog007

Copy link
Copy Markdown

Summary

The plain-text body that topcoat-mail derives from HTML breaks when a list item wraps its content in a block element. <ul><li><p>One</p></li><li><p>Two</p></li></ul> came out as "- \n\nOne\n\n- \n\nTwo", and the <ol>/<div> version came out as "1. \nFirst\n2. \nSecond". The li branch writes the marker right away, then the inner <p>/<div> asks for line breaks via separate(), and those get flushed between the marker and the text.

Fix: PlainText now tracks whether a marker was just written with no item content yet, and separate() skips block breaks while that's the case. The flag clears as soon as content is flushed. Nested ul/ol/li don't go through separate(), so a nested list still starts on its own line. Now these give "- One\n\n- Two" and "1. First\n2. Second".

Added tests for both cases, plus one pinning the nested list output ("- Parent\n\n- Child", same as before). No existing expectations changed.

Closes #609

Testing

  • cargo test -p topcoat-mail --lib: the new test fails on main with the output above, and all 41 tests pass with the fix
  • cargo +nightly fmt --all: no changes
  • cargo topcoat fmt: 0 files modified (the only failures are the known Leptos benchmark files)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test --workspace --all-features: 3477 passed, 0 failed
  • RUSTDOCFLAGS="--cfg docsrs -Dwarnings" cargo +nightly doc --workspace --all-features --no-deps --locked: clean

My sandbox blocks the downloads made by the Tailwind/iconify build scripts, so I ran the workspace clippy/test/doc commands with --exclude topcoat-ui-registry --exclude ui --exclude admin --exclude icon --exclude tailwind --exclude storefront-topcoat. None of those depend on topcoat-mail's text conversion.

Disclaimer

Made with Claude Code (Claude Opus 5.5). It traced the bug in text.rs, reproduced it with failing tests, wrote the fix and tests, and ran the checks above. I reviewed and verified the diff.

A block element inside a list item, such as `<li><p>One</p></li>`, owed
line breaks after the marker was already written, so the derived text
body put the item text on its own line under an empty marker. Block
separation is now skipped until the item's content starts; nested lists
still start on their own line.

Closes tokio-rs#609
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.

mail: list markers get separated from block content in plain-text bodies

1 participant