Add URL paste autolink feature#32
Merged
Merged
Conversation
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>
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
Implementation
isSafeHref()andparseHttpUrl()URL validation utilitiesparseDOMwithisSafeHref()isInlineSelection(),addMarkToFragment()tr.replaceSelection()Plan Document
Design rationale documented in
docs/plans/01KHRS817S0EERAW6NG7FZT1K6.mdTest plan
<a href="url">url</a>) → treated same as plain URL🤖 Generated with Claude Code