Skip to content

Keep a trailing ">" when reformatting block quotes#460

Merged
lepture merged 1 commit into
lepture:mainfrom
sarathfrancis90:fix/markdown-block-quote-trailing-gt
Jun 28, 2026
Merged

Keep a trailing ">" when reformatting block quotes#460
lepture merged 1 commit into
lepture:mainfrom
sarathfrancis90:fix/markdown-block-quote-trailing-gt

Conversation

@sarathfrancis90

Copy link
Copy Markdown
Contributor

Reformatting a block quote through MarkdownRenderer drops the last > of its content, so an autolink, an inline HTML tag, or a literal > comes out broken:

>>> import mistune
>>> from mistune.renderers.markdown import MarkdownRenderer
>>> md = mistune.create_markdown(renderer=MarkdownRenderer())
>>> md("> <https://example.com>\n")
'> <https://example.com\n'

block_quote indents every line with > (including the blank line a paragraph leaves at the end) and then calls rstrip("> \n") to remove that dangling marker. Since rstrip strips a character set, it also peels off a > that ends the content itself, so the reparse turns <https://example.com> into escaped text.

I strip the children's trailing blank lines before indenting, so the marker is never added to an empty trailing line and there's nothing to strip back off. Existing empty-line-inside-quote handling is unchanged.

Added round-trip cases for content ending in > (autolink, HTML tag, literal >, nested quote). Full test suite and mypy --strict pass.

MarkdownRenderer.block_quote indented every line with '> ' (including the
blank line a paragraph leaves behind) and then ran rstrip('> \n') to drop
that dangling marker. Because rstrip strips a character set, it also ate a
'>' that ended the quote's own content, so an autolink, an inline HTML tag,
or a literal '>' lost its final character (e.g. '> <https://x.com>' became
'> <https://x.com', which reparses as escaped text).

Strip the children's trailing blank lines before indenting instead, so the
marker is never added to an empty trailing line and there is nothing to peel
back off.
@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.05%. Comparing base (ecd435a) to head (cff35d5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #460   +/-   ##
=======================================
  Coverage   91.05%   91.05%           
=======================================
  Files          34       34           
  Lines        3409     3409           
  Branches      672      672           
=======================================
  Hits         3104     3104           
  Misses        184      184           
  Partials      121      121           
Flag Coverage Δ
unittests 91.02% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lepture lepture merged commit 59c35e2 into lepture:main Jun 28, 2026
27 checks passed
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants