Skip to content

Commit 2f9a42d

Browse files
authored
Strip text before adding blockquote markers (#76)
1 parent 96a25cf commit 2f9a42d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

markdownify/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def convert_blockquote(self, el, text, convert_as_inline):
237237
if convert_as_inline:
238238
return text
239239

240-
return '\n' + (line_beginning_re.sub('> ', text) + '\n\n') if text else ''
240+
return '\n' + (line_beginning_re.sub('> ', text.strip()) + '\n\n') if text else ''
241241

242242
def convert_br(self, el, text, convert_as_inline):
243243
if convert_as_inline:

tests/test_conversions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ def test_b_spaces():
5252

5353
def test_blockquote():
5454
assert md('<blockquote>Hello</blockquote>') == '\n> Hello\n\n'
55+
assert md('<blockquote>\nHello\n</blockquote>') == '\n> Hello\n\n'
56+
57+
58+
def test_blockquote_with_nested_paragraph():
59+
assert md('<blockquote><p>Hello</p></blockquote>') == '\n> Hello\n\n'
60+
assert md('<blockquote><p>Hello</p><p>Hello again</p></blockquote>') == '\n> Hello\n> \n> Hello again\n\n'
5561

5662

5763
def test_blockquote_with_paragraph():
@@ -60,7 +66,7 @@ def test_blockquote_with_paragraph():
6066

6167
def test_blockquote_nested():
6268
text = md('<blockquote>And she was like <blockquote>Hello</blockquote></blockquote>')
63-
assert text == '\n> And she was like \n> > Hello\n> \n> \n\n'
69+
assert text == '\n> And she was like \n> > Hello\n\n'
6470

6571

6672
def test_br():

0 commit comments

Comments
 (0)