Skip to content

Commit 3311f4d

Browse files
authored
Avoid stripping nonbreaking spaces (#188)
1 parent 5655f27 commit 3311f4d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Diff for: markdownify/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def process_text(self, el, parent_tags=None):
313313
if (should_remove_whitespace_outside(el.previous_sibling)
314314
or (should_remove_whitespace_inside(el.parent)
315315
and not el.previous_sibling)):
316-
text = text.lstrip()
316+
text = text.lstrip(' \t\r\n')
317317
if (should_remove_whitespace_outside(el.next_sibling)
318318
or (should_remove_whitespace_inside(el.parent)
319319
and not el.next_sibling)):
@@ -399,7 +399,7 @@ def convert_a(self, el, text, parent_tags):
399399

400400
def convert_blockquote(self, el, text, parent_tags):
401401
# handle some early-exit scenarios
402-
text = (text or '').strip()
402+
text = (text or '').strip(' \t\r\n')
403403
if '_inline' in parent_tags:
404404
return ' ' + text + ' '
405405
if not text:
@@ -567,8 +567,8 @@ def _indent_for_li(match):
567567

568568
def convert_p(self, el, text, parent_tags):
569569
if '_inline' in parent_tags:
570-
return ' ' + text.strip() + ' '
571-
text = text.strip()
570+
return ' ' + text.strip(' \t\r\n') + ' '
571+
text = text.strip(' \t\r\n')
572572
if self.options['wrap']:
573573
# Preserve newlines (and preceding whitespace) resulting
574574
# from <br> tags. Newlines in the input have already been
@@ -577,7 +577,7 @@ def convert_p(self, el, text, parent_tags):
577577
lines = text.split('\n')
578578
new_lines = []
579579
for line in lines:
580-
line = line.lstrip()
580+
line = line.lstrip(' \t\r\n')
581581
line_no_trailing = line.rstrip()
582582
trailing = line[len(line_no_trailing):]
583583
line = fill(line,

Diff for: tests/test_conversions.py

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_b_spaces():
5959
def test_blockquote():
6060
assert md('<blockquote>Hello</blockquote>') == '\n> Hello\n\n'
6161
assert md('<blockquote>\nHello\n</blockquote>') == '\n> Hello\n\n'
62+
assert md('<blockquote>&nbsp;Hello</blockquote>') == '\n> \u00a0Hello\n\n'
6263

6364

6465
def test_blockquote_with_nested_paragraph():
@@ -266,6 +267,7 @@ def test_p():
266267
assert md('<p>1234 5678 9012<br />67890</p>', wrap=True, wrap_width=10, newline_style=BACKSLASH) == '\n\n1234 5678\n9012\\\n67890\n\n'
267268
assert md('<p>1234 5678 9012<br />67890</p>', wrap=True, wrap_width=10, newline_style=SPACES) == '\n\n1234 5678\n9012 \n67890\n\n'
268269
assert md('First<p>Second</p><p>Third</p>Fourth') == 'First\n\nSecond\n\nThird\n\nFourth'
270+
assert md('<p>&nbsp;x y</p>', wrap=True, wrap_width=80) == '\n\n\u00a0x y\n\n'
269271

270272

271273
def test_pre():

0 commit comments

Comments
 (0)