Skip to content

Commit 59c35e2

Browse files
authored
Merge pull request #460 from sarathfrancis90/fix/markdown-block-quote-trailing-gt
2 parents ecd435a + cff35d5 commit 59c35e2

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/mistune/renderers/markdown.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ def block_code(self, token: Dict[str, Any], state: BlockState) -> str:
131131
return marker2 + info + "\n" + code + marker2 + "\n\n"
132132

133133
def block_quote(self, token: Dict[str, Any], state: BlockState) -> str:
134-
text = indent(self.render_children(token, state), "> ", lambda _: True)
135-
text = text.rstrip("> \n")
134+
# strip the children's trailing blank lines first so the quote marker is
135+
# not added to a dangling empty line; stripping it back off afterwards
136+
# would also eat a ">" that ends the content (an autolink or HTML tag).
137+
text = self.render_children(token, state).rstrip("\n")
138+
text = indent(text, "> ", lambda _: True)
136139
return text + "\n\n"
137140

138141
def block_html(self, token: Dict[str, Any], state: BlockState) -> str:

tests/test_renderers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ def test_link_title_containing_quote(self):
7070
):
7171
self.assert_round_trip(text)
7272

73+
def test_block_quote_content_ending_in_gt(self):
74+
# a block quote whose content ends with ">" (an autolink, an inline
75+
# HTML tag, or a literal ">") must keep that character; it was being
76+
# stripped along with the trailing quote marker
77+
for text in (
78+
"> <https://example.com>\n",
79+
"> <b>raw</b>\n",
80+
"> ends with a literal &gt; >\n",
81+
"> > nested <https://example.com>\n",
82+
"> first\n>\n> <https://example.com>\n",
83+
):
84+
self.assert_round_trip(text)
85+
7386
def test_real_markers_preserved(self):
7487
for text in (
7588
"* bullet\n",

0 commit comments

Comments
 (0)