Skip to content

Autolink bare URLs and emails in the HTML renderer - #144

Merged
luca-chen198 merged 1 commit into
mainfrom
fix/autolink-bare-urls
Aug 10, 2026
Merged

Autolink bare URLs and emails in the HTML renderer#144
luca-chen198 merged 1 commit into
mainfrom
fix/autolink-bare-urls

Conversation

@xandaaaa

@xandaaaa xandaaaa commented Aug 7, 2026

Copy link
Copy Markdown
Member

Problem

Copying a bare URL from the editor and pasting it into Mail or Outlook produced dead text. The editor styler linkifies bare URLs with NSDataDetector, but the HTML renderer emitted them as plain text — so the pasteboard's rich flavors (HTML, RTF, web archive) carried no anchor, and rich-paste consumers take those flavors verbatim without running any link detection of their own. (Explicit [title](url) links were always fine; only bare URLs died.)

Reproducer: type https://example.com in the editor (renders clickable), select + copy, paste into Outlook/Mail → plain text instead of a hyperlink.

Fix

MarkdownHTMLRenderer now wraps detector matches in <a href> (emails as mailto:) when rendering text runs, using the same system detector as the styler so in-editor and copied-out linking agree. The RTF and web-archive flavors are derived from that HTML, so all three inherit the anchor.

Guards, both matching the styler's exclusions:

  • Text inside an explicit link's title renders with linkable: false, so a URL-shaped title never nests a second <a> inside the link's own.
  • Code spans are their own inline node and never reach the autolink path.

The detector is built once (per the styler's documented rebuild cost, ENG-8g1b).

Tests

  • Renderer: bare URL / mid-sentence URL with &-escaped query / scheme-less www. / email mailto:; autolink through bold and re-parsed blockquote content; exclusion inside code spans and link titles.
  • Writer (end-to-end): a bare URL lands on the pasteboard with a real anchor in the .html flavor and a HYPERLINK field in the derived .rtf.

All 317 tests pass.

🤖 Generated with Claude Code

The editor styler linkifies bare URLs with NSDataDetector, but the HTML
renderer emitted them as plain text, so the pasteboard's rich flavors
(HTML/RTF/web archive) carried no anchor. Rich-paste consumers — Mail,
Outlook — take those flavors verbatim and run no link detection of their
own, so a URL that is clickable in the editor pasted as dead text.

Wrap detector matches in <a href> (emails as mailto:) in the renderer's
text runs, using the same system detector as the styler so in-editor and
copied-out linking agree. RTF and web archive derive from that HTML and
inherit the anchors. Text inside an explicit link's title renders with
linkable: false so anchors never nest; code spans are their own inline
node and stay excluded, matching the styler's in-code rule.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@xandaaaa
xandaaaa requested a review from luca-chen198 August 8, 2026 09:12

@luca-chen198 luca-chen198 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@luca-chen198
luca-chen198 merged commit 2a91937 into main Aug 10, 2026
1 check passed
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