Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert whitespace at most once with multpile emphasis #333

Merged
merged 6 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The AUTHORS/Contributors are (and/or have been):
* Jacek Kołodziej <kolodziejj@gmail.com>
* Jonathan Vanasco <jonathan@findmeon.com>
* Jon Dufresne <jon.dufresne@gmail.com>
* Edward Ross <edward@skeptric.com>
* Mike Borsetti

Maintainer:
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ UNRELEASED
==========
----

* Fix #332: Insert at most one space for multiple emphasis
* Feature #318: Make padded tables more similar to pandoc's pipe_tables.
* Add support for Python 3.9.
* Fix extra line breaks inside html link text (between '[' and ']')
Expand Down
3 changes: 3 additions & 0 deletions html2text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ def no_preceding_space(self: HTML2Text) -> bool:
if tag in ["em", "i", "u"] and not self.ignore_emphasis:
if start and no_preceding_space(self):
emphasis = " " + self.emphasis_mark
self.preceding_data += " "
else:
emphasis = self.emphasis_mark

Expand All @@ -422,6 +423,7 @@ def no_preceding_space(self: HTML2Text) -> bool:
if tag in ["strong", "b"] and not self.ignore_emphasis:
if start and no_preceding_space(self):
strong = " " + self.strong_mark
self.preceding_data += " "
else:
strong = self.strong_mark

Expand All @@ -432,6 +434,7 @@ def no_preceding_space(self: HTML2Text) -> bool:
if tag in ["del", "strike", "s"]:
if start and no_preceding_space(self):
strike = " ~~"
self.preceding_data += " "
else:
strike = "~~"

Expand Down
31 changes: 31 additions & 0 deletions test/emphasis_whitespace.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<p> <em><strong>ib</strong></em></p>

<p>.<em><strong>ib</strong></em></p>

<p> <strong><em>bi</em></strong></p>

<p>.<strong><em>bi</em></strong></p>

<p> <em><strike>is</strike></em></p>

<p>.<em><strike>is</strike></em></p>

<p> <em><strike>si</strike></em></p>

<p>.<em><strike>si</strike></em></p>

<p> <strong><strike>bs</strike></strong></p>

<p>.<strong><strike>bs</strike></strong></p>

<p> <strike><strong>sb</strong></strike></p>

<p>.<strike><strong>sb</strong></strike></p>

<p> <strike><strong><em>sbi</em></strong></strike></p>

<p>.<strike><strong><em>sbi</em></strong></strike></p>

<p> <strong><em><strike>bis</strike></em></strong></p>

<p>.<strong><em><strike>bis</strike></em></strong></p>
32 changes: 32 additions & 0 deletions test/emphasis_whitespace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
_**ib**_

. _**ib**_

**_bi_**

. **_bi_**

_~~is~~_

. _~~is~~_

_~~si~~_

. _~~si~~_

**~~bs~~**

. **~~bs~~**

~~**sb**~~

. ~~**sb**~~

~~**_sbi_**~~

. ~~**_sbi_**~~

**_~~bis~~_**

. **_~~bis~~_**

2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ skip_install = true
[testenv:isort]
basepython = python3
commands =
isort --check --diff .
isort --check-only --diff .
deps =
isort >= 5.0.1
skip_install = true
Expand Down