Skip to content

Add URL paste autolink feature#32

Merged
wandering-logic merged 6 commits into
mainfrom
url-paste-autolink
Feb 18, 2026
Merged

Add URL paste autolink feature#32
wandering-logic merged 6 commits into
mainfrom
url-paste-autolink

Conversation

@wandering-logic
Copy link
Copy Markdown
Owner

Summary

  • Automatically create links when pasting URLs
  • Handle autolinks from other apps (where href equals display text)
  • Inline selection: selected text becomes link text, preserving marks (bold/italic)
  • Empty or multi-block selection: URL becomes both link text and href

Implementation

  • Add isSafeHref() and parseHttpUrl() URL validation utilities
  • Replace regex in link mark's parseDOM with isSafeHref()
  • Add helper functions: isInlineSelection(), addMarkToFragment()
  • Unified paste handler flow using tr.replaceSelection()

Plan Document

Design rationale documented in docs/plans/01KHRS817S0EERAW6NG7FZT1K6.md

Test plan

  • Paste plain URL with empty selection → inserts linked URL
  • Paste plain URL with inline selection → selection becomes link
  • Paste plain URL with multi-block selection → replaces with linked URL
  • Paste autolink (<a href="url">url</a>) → treated same as plain URL
  • Paste link with different href and text → falls through to default paste
  • Bold/italic text in selection is preserved when linked

🤖 Generated with Claude Code

wandering-logic and others added 6 commits February 17, 2026 21:39
When pasting content that is just an HTTP(S) URL:
- No selection: inserts URL as linked text
- With selection: applies link mark to selected text using pasted URL as href

Also adds isSafeHref() and parseHttpUrl() utilities for URL validation,
replacing the regex in link mark's parseDOM with isSafeHref().

Respects existing links in pasted content - does not override them.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Handle autolinks from other apps (link where href === text)
- Unified code path: detect URL, construct link slice, replaceSelection
- Inline selection preserves existing marks (bold/italic)
- Empty or multi-block selection uses URL as link text
- Add helper functions: isInlineSelection, addMarkToFragment
- Remove complex "Case 2b" link extension logic

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When pasting a URL onto a selection that includes images, the images
now become part of the link. Changes:

- addMarkToFragment: Add marks to all nodes, not just text nodes
- image toDOM: Wrap in <a> tag when image has a link mark

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Instead of extracting a slice, adding marks to all nodes, and replacing,
just use tr.addMark() directly on the document range. This is the
idiomatic ProseMirror approach for adding marks to existing content.

Removes the addMarkToFragment helper function entirely.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
An autolink must be a single text node that:
- Parses as a valid HTTP(S) URL
- Has either no marks, or exactly one link mark where href === text

This rejects structured content, partial links, text outside links,
URLs with extra formatting, and encoding mismatches.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
ProseMirror wraps pasted text in a paragraph node. The autolink
detection now unwraps single-paragraph slices to find the text
node inside, fixing URL detection for normal paste operations.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@wandering-logic wandering-logic merged commit f482473 into main Feb 18, 2026
2 checks 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.

1 participant