Skip to content

Commit

Permalink
Strip text before adding blockquote markers (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
andredelft authored Mar 26, 2024
1 parent 96a25cf commit 2f9a42d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion markdownify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def convert_blockquote(self, el, text, convert_as_inline):
if convert_as_inline:
return text

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

def convert_br(self, el, text, convert_as_inline):
if convert_as_inline:
Expand Down
8 changes: 7 additions & 1 deletion tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def test_b_spaces():

def test_blockquote():
assert md('<blockquote>Hello</blockquote>') == '\n> Hello\n\n'
assert md('<blockquote>\nHello\n</blockquote>') == '\n> Hello\n\n'


def test_blockquote_with_nested_paragraph():
assert md('<blockquote><p>Hello</p></blockquote>') == '\n> Hello\n\n'
assert md('<blockquote><p>Hello</p><p>Hello again</p></blockquote>') == '\n> Hello\n> \n> Hello again\n\n'


def test_blockquote_with_paragraph():
Expand All @@ -60,7 +66,7 @@ def test_blockquote_with_paragraph():

def test_blockquote_nested():
text = md('<blockquote>And she was like <blockquote>Hello</blockquote></blockquote>')
assert text == '\n> And she was like \n> > Hello\n> \n> \n\n'
assert text == '\n> And she was like \n> > Hello\n\n'


def test_br():
Expand Down

0 comments on commit 2f9a42d

Please sign in to comment.