fix: preserve text nested inside <br> by html.parser (#244)#264
Open
gaoflow wants to merge 1 commit into
Open
Conversation
Python's html.parser can wrap text following <br /> (with a space) inside the <br> element as child content when the <br> is preceded by a sibling <br> without a slash. convert_br received the nested text via its `text` parameter but discarded it, silently dropping characters from the output. Append `text` to the returned line-break marker so that any accidentally nested content is always preserved. Closes matthewwithanm#244
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #244.
Python's
html.parserhas an edge case where text following<br />(written with a space before the slash) is parsed as child content of the<br>element instead of a sibling text node, when the preceding sibling is a bare<br>tag.convert_brreceived the nested text via itstextparameter but silently discarded it, causing characters to disappear from the output:Fix
Append
textto the returned line-break marker in all branches ofconvert_br. When<br>is used correctly as a void element,textis always an empty string, so the change is backward-compatible. The_inlinebranch is handled similarly for consistency.Test
Added two assertions to
test_brcovering the mixed<br>/<br />pattern that triggers the html.parser nesting behaviour.This pull request was prepared with the assistance of AI, under my direction and review.