Skip to content

feat(web): automatic links#598

Open
pkaramon wants to merge 26 commits into
mainfrom
@pkaramon/feat-web-autolink
Open

feat(web): automatic links#598
pkaramon wants to merge 26 commits into
mainfrom
@pkaramon/feat-web-autolink

Conversation

@pkaramon

@pkaramon pkaramon commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • implemented automatic links on web
  • handled linkRegex prop
  • wrote e2e tests for automatic links
  • refactored useOnLinkDetected so it uses a shared LinkEmitter with autolink plugin, because we want to emit an event when an automatic link is created, but we also do no want to send the same event twice.
  • this PR doesn't use automatic link functionality from Link extensions from Tiptap, as it doesn't allow passing any regex, and it also struggles with extending automatic links on the right. I've implemented a custom plugin that looks at changed rages and research using a regex for texts where we should applied the automatic link mark.

Test Plan

  • Run yarn test:e2e:web to see if all the tests pass
  • Run yarn example-web dev and play around with automatic links, change LINK_REGEX in apps/example-web/App.tsx

Screenshots / Videos

Compatibility

OS Implemented
iOS
Android
Web

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

@pkaramon pkaramon changed the title feat(web): autolink feat(web): automatic links May 13, 2026
@pkaramon pkaramon marked this pull request as ready for review May 13, 2026 17:11
pkaramon added a commit that referenced this pull request May 14, 2026
- Add experimental web platform note; EnrichedText is iOS/Android only for now
- Replace all "Both" platform cells with explicit iOS/Android/Web labels
- cursorColor: Android, Web only (iOS uses selectionColor for cursor color)
- useHtmlNormalizer: iOS, Android only — ignored on web
- contextMenuItems: iOS, Android only — not available on web
- linkRegex: update default value label to "platform default regex"
- onPasteImages: add web note about blob URLs and URL.revokeObjectURL()
- Add onSubmitEditing, returnKeyLabel, returnKeyType, submitBehavior props
- returnKeyLabel: iOS/Android only — browsers don't allow customizing return key label
- returnKeyType: web supports only enterkeyhint-compatible values
- Add Keyboard Shortcuts (Web only) section with full shortcut table

Assumes PRs #600 (submit props), #598 (automatic links),
#584 (image paste), #603 (shortcuts) will be merged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@kacperzolkiewski kacperzolkiewski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When we type swmansion.com, in HTML I can see that https:// is automatically added to the href. Is this the intended behavior?

Screen.Recording.2026-05-26.at.09.02.49.mov

@kacperzolkiewski

Copy link
Copy Markdown
Collaborator

When we paste text containing a link, it is treated as a manually added link, which allows inserting new lines inside it:

Screen.Recording.2026-05-26.at.09.42.49.mov

@hejsztynx hejsztynx force-pushed the @pkaramon/feat-web-autolink branch from 208c368 to 39080f7 Compare June 10, 2026 16:25
@hejsztynx

Copy link
Copy Markdown
Collaborator

When we type swmansion.com, in HTML I can see that https:// is automatically added to the href. Is this the intended behavior?

Screen.Recording.2026-05-26.at.09.02.49.mov

removed automatic https prefix addition

@hejsztynx

Copy link
Copy Markdown
Collaborator

When we paste text containing a link, it is treated as a manually added link, which allows inserting new lines inside it:

Screen.Recording.2026-05-26.at.09.42.49.mov

now it checks if href equals to the text value of the html node - if so, we treat it as an autolink, just like in the native

Comment thread src/web/pmPlugins/AutolinkPlugin/index.ts Outdated

@kacperzolkiewski kacperzolkiewski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Works good!

@exploIF

exploIF commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

It looks to me like linkRegex prop is not working properly. Whenever I paste some valid URL, it is recognized as a link, even if I pass linkRegex={null}

Comment thread apps/example-web/src/testScreens/TestLinks.tsx Outdated
Comment thread src/web/pmPlugins/AutolinkPlugin/autolinkRegex.ts Outdated
Comment thread src/web/pmPlugins/AutolinkPlugin/index.ts
Comment thread src/web/pmPlugins/AutolinkPlugin/index.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds automatic link detection for the web EnrichedTextInput by introducing a custom ProseMirror/Tiptap plugin that applies link marks based on a configurable linkRegex, while sharing a single link-detection emitter to avoid duplicate onLinkDetected events.

Changes:

  • Added a custom AutolinkPlugin that scans edited blocks and applies/removes link marks based on a default URL regex or a provided linkRegex prop.
  • Refactored useOnLinkDetected to emit through a shared LinkEmitterState (emitLinkDetected) so autolink and selection-based detection dedupe properly.
  • Added/updated example UI + Playwright E2E coverage for autolink typing and paste flows, plus updated web docs.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/web/useOnLinkDetected.ts Refactors link detection to use a shared emitter state and improved range detection at cursor boundaries.
src/web/pmPlugins/StripBoldInStyledHeadingsPlugin.ts Types Extension.create options for the plugin configuration.
src/web/pmPlugins/AutolinkPlugin/index.ts Adds the main autolink detection + mark application ProseMirror plugin.
src/web/pmPlugins/AutolinkPlugin/autolinkRegex.ts Adds default URL matching + helper to globalize custom regex.
src/web/formats/EnrichedLink.ts Adds an internal-only auto attribute to link marks.
src/web/EnrichedTextInput.tsx Wires linkRegex + AutolinkPlugin + shared LinkEmitterState into the editor.
src/web/emitLinkDetected.ts Introduces shared emitter state + dedupe logic for link-detected events.
docs/WEB.md Documents automatic link detection as supported on web.
apps/example-web/src/testScreens/TestLinks.tsx Adds controls for testing default/disabled/custom linkRegex modes.
apps/example-web/src/App.tsx Demonstrates passing a LINK_REGEX prop on web example app.
.playwright/tests/links.spec.ts Adds E2E tests for autolink while typing and pasting, and for disabling autolink.
.playwright/playwright.config.ts Enables clipboard permissions needed for paste tests.
.playwright/helpers/clipboard.ts Adds helper to dispatch a plain-text paste event into the editor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/web/pmPlugins/AutolinkPlugin/index.ts Outdated
Comment thread src/web/pmPlugins/AutolinkPlugin/index.ts
Comment thread src/web/useOnLinkDetected.ts
Comment thread src/web/formats/EnrichedLink.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Comment thread src/web/emitLinkDetected.ts
Comment thread src/web/pmPlugins/AutolinkPlugin/autolinkRegex.ts Outdated
Comment thread src/web/pmPlugins/AutolinkPlugin/index.ts Outdated
Comment thread src/web/pmPlugins/AutolinkPlugin/index.ts
Comment thread src/web/pmPlugins/AutolinkPlugin/index.ts
hejsztynx and others added 2 commits June 12, 2026 17:35
…anges

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@hejsztynx hejsztynx requested a review from exploIF June 12, 2026 15:41
@exploIF

exploIF commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Functionally works well, however there are failing e2e tests:

[chromium] › .playwright/tests/codeblockInlineStyles.spec.ts:60:7 › codeblock inline styles › paste into code block strips copied inline styles 
[chromium] › .playwright/tests/headingBoldFromStyle.spec.ts:45:7 › h1 bold from htmlStyle (h1.bold true) › paste into h1 strips copied bold mark 
[chromium] › .playwright/tests/headingBoldFromStyle.spec.ts:100:7 › h1 bold from htmlStyle (h1.bold false) › paste into h1 keeps copied bold mark when htmlStyle h1.bold is false

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.

5 participants