converter = html2text.HTML2Text()
converter.emphasis_mark = "_"
converter.strong_mark = "**"
string = "A <b>B</b> <i>C</i>."
result = converter.handle(string)
print(result)
# output: A **B** _C_.
✅ emphasis emptied ''
converter = html2text.HTML2Text()
converter.emphasis_mark = ""
converter.strong_mark = "**"
string = "A <b>B</b> <i>C</i>."
result = converter.handle(string)
print(result)
# output: A **B** C.
❌ strong emptied ''
converter = html2text.HTML2Text()
converter.emphasis_mark = "_"
converter.strong_mark = ""
string = "A <b>B</b> <i>C</i>."
result = converter.handle(string)
print(result)
# expected output: A B _C_.
Traceback (most recent call last):
File "script.py", line 29, in <module>
main()
File "script.py", line 24, in main
result = converter.handle(string)
File "test/venv/lib/python3.9/site-packages/html2text/__init__.py", line 145, in handle
self.feed(data)
File "test/venv/lib/python3.9/site-packages/html2text/__init__.py", line 141, in feed
super().feed(data)
File "/opt/homebrew/Cellar/python@3.9/3.9.18_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/html/parser.py", line 110, in feed
self.goahead(0)
File "/opt/homebrew/Cellar/python@3.9/3.9.18_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/html/parser.py", line 170, in goahead
k = self.parse_starttag(i)
File "/opt/homebrew/Cellar/python@3.9/3.9.18_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/html/parser.py", line 344, in parse_starttag
self.handle_starttag(tag, attrs)
File "test/venv/lib/python3.9/site-packages/html2text/__init__.py", line 194, in handle_starttag
self.handle_tag(tag, dict(attrs), start=True)
File "test/venv/lib/python3.9/site-packages/html2text/__init__.py", line 441, in handle_tag
and self.preceding_data[-1] == self.strong_mark[0]
IndexError: string index out of range
Test script
✅ default
✅ emphasis emptied
''
❌ strong emptied
''