Skip to content

Preserve buffered trailing text in html2text - #571

Closed
FanWu-ai wants to merge 1 commit into
mahmoud:masterfrom
FanWu-ai:fix/html2text-buffered-input
Closed

FanWu-ai wants to merge 1 commit into
mahmoud:masterfrom
FanWu-ai:fix/html2text-buffered-input

Conversation

@FanWu-ai

@FanWu-ai FanWu-ai commented Oct 8, 2026 •

Copy link
Copy Markdown

The change

Finish parsing the input in html2text() before collecting its text. HTMLParser.feed() can buffer a trailing character reference or ampersand-containing word until close() signals end of input. Without that call, html2text('R&D') returns '', and html2text('<p>Hello</p> R&D') returns 'Hello', silently dropping text.

Call close() after feed(). The regression cases cover a plain trailing ampersand-containing word, text after an HTML element, named/decimal/hexadecimal character references without a semicolon, complete markup, and empty input. Five of these cases failed on the unchanged implementation.

Validation on Linux:

  • Baseline uvx --with tox-uv tox -e py312: 678 passed.
  • New regression cases before the fix: 5 failed, 2 passed.
  • Final uvx --with tox-uv tox -e py312,py313: 685 passed in each environment (Python 3.12.14 and 3.13.5).
  • Final uvx --with tox-uv tox -e py314: 685 passed, 5 deprecation warnings (Python 3.14.8).
  • git diff --check: passed.

All tox runs include the complete test suite and module doctests, using the built package. Other interpreter versions and operating systems were not run locally. Searched existing open/closed issues and PRs for html2text, HTMLTextExtractor, and ampersand, and checked open PR titles; found no overlapping fix.

The HTMLParser documentation describes the end-of-input processing that this wrapper was missing.

AI assistance

Prepared and tested with OpenAI Codex assistance.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 8, 2026 05:55
@FanWu-ai FanWu-ai closed this Oct 8, 2026
@FanWu-ai
FanWu-ai deleted the fix/html2text-buffered-input branch October 13, 2026 05:46
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.

1 participant