Fix #405: no spurious space between emphasis and following punctuation#442
Open
assinscreedFC wants to merge 1 commit into
Open
Fix #405: no spurious space between emphasis and following punctuation#442assinscreedFC wants to merge 1 commit into
assinscreedFC wants to merge 1 commit into
Conversation
…ctuation After a closing emphasis marker html2text inserted a separating space before anything except whitespace, brackets and `.!?`. That wrongly added a space before other punctuation, e.g. `<em>hello</em>,` produced `_hello_ ,` instead of `_hello_,`. The separating space is only needed before a word character, which would otherwise attach to the closing marker and stop Markdown from recognising the emphasis. The condition is now `re.match(r"\w", data[0])`. Adds a regression fixture (test/emphasis_punctuation.*) and a ChangeLog entry. Co-authored-by: Claude <noreply@anthropic.com>
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 #405.
After a closing emphasis marker, html2text inserted a separating space before anything except whitespace, brackets and
.!?. That wrongly added a space before other punctuation:Same for
:";etc.Change
In
handle_data, the separating space after stressed (emphasis) text is only needed before a word character — which would otherwise attach to the closing_/*marker and stop Markdown from recognising the emphasis. Punctuation never merges with the marker, so it must not get a space. The condition changes from a broad blocklist:to:
\wkeeps the needed space before letters, digits and_(all of which break a closing_), while dropping it before punctuation.This is scoped to the punctuation case (#405). The separate
**strong**+ alphanumeric case (#413) uses a different code path and is left untouched.Tests
Added a regression fixture
test/emphasis_punctuation.html/.md(the test driver auto-discovers*.html/*.mdpairs). It pins both behaviours: no space before punctuation/apostrophe, space kept before a following word or digit.All 199 tests pass;
black,isort,mypy, andflake8are clean. ChangeLog and AUTHORS updated.AI assistance (Claude) was used; I reviewed every line and ran the tests.