Allow html tags that contain only spaces
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 48/100
Research direction
Start by locating the chomp function described in the issue and reproduce how markdownify handles . Verify that the conversion preserves the space between surrounding words without changing the existing handling of leading and trailing spaces; the issue does not name a test file.
Written by the indexing model from the issue text.
Description
markdownify converts this:
one<i> </i>two
into:
oneone
because the function chomp returns the text inside the tags as an empty string.
One can argue that empty tags like this should not be allowed, but the epub The Last Dangerous Visions from Blackstone Publishing has this structure in dozens of locations and the space inside the tag is the space between two words of the text. This results in my epub reader showing a bunch of words without spaces between them when I use markdownify to convert the text of the epub files into markdown.
I don't pretend to understand how the markdownify code works in detail, but modifying chomp to look like this fixes the issue for me:
def chomp(text):
"""
If the text in an inline tag like b, a, or em contains a leading or trailing
space, strip the string and return a space as suffix of prefix, if needed.
This function is used to prevent conversions like
<b> foo</b> => ** foo**
"""
#change to allow empty tags: "<i> </i>" and maintain the space
if text.isspace():
prefix = ''
suffix = ''
text = ' '
else:
prefix = ' ' if text and text[0] == ' ' else ''
suffix = ' ' if text and text[-1] == ' ' else ''
text = text.strip()
return (prefix, suffix, text)
An unfortunate side effect of my fix is that this turns into something similar to  .
- Dominant language
- Python
- Stars
- 2.2k
- Forks
- 203
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from matthewwithanm/python-markdownify
-
RecursionError on deeply nested HTML (about 330 levels), separate from the cyclic-tree case in #256 Open
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
matthewwithanm/python-markdownify#261 · 1 comment · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
matthewwithanm/python-markdownify#259 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 50/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 50/100
All issues in matthewwithanm/python-markdownify
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100