Fix MarkdownRenderer corrupting email autolinks on round-trip#269
Closed
gaoflow wants to merge 1 commit into
Closed
Fix MarkdownRenderer corrupting email autolinks on round-trip#269gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
AutoLink prepends "mailto:" to an email autolink's dest while keeping the original address in its children. MarkdownRenderer.render_auto_link emitted the synthetic dest, so re-rendering <mail@x.com> produced <mailto:mail@x.com>, which parses back with the wrong link text (and is no longer an email autolink). Render the children (the original text) instead. URI autolinks have children equal to dest, so they are unaffected.
Owner
|
This can be verified: before: https://spec.commonmark.org/dingus/?text=%3Cmail%40x.com%3E |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MarkdownRenderercorrupts email autolinks when re-rendering Markdown:Re-parsing that output no longer yields the original email link —
<mailto:mail@x.com>is parsed as a URI autolink, so the rendered HTML link text becomesmailto:mail@x.cominstead ofmail@x.com. TheMarkdownRendererround-trip is broken for any email autolink. URI autolinks (<http://example.org>) round-trip correctly.Cause
AutoLink.__init__prepends"mailto:"todestfor emails, but preserves the original address in the children:render_auto_linkemitted the syntheticdest:so the
mailto:prefix leaked into the Markdown output. (The HTML renderer correctly uses the children for the display text.)Fix
Render the children — the original text — instead of
dest. For URI autolinks the children equaldest, so they are unchanged:Verification
test_markdown_renderer_email_autolink: asserts<mail@x.com>re-renders unchanged and that both an email and a URI autolink round-trip to equivalent HTML. It fails before the fix and passes after.+/-/.in the local part, explicit<mailto:...>URIs, andhttpsautolinks all round-trip and are idempotent under re-rendering.ruffandmypyclean on the changed files.This pull request was prepared with the assistance of AI, under my direction and review.