Skip to content

[lexical-link][lexical-react] Feature: Allow custom punctuation for AutoLink boundaries#8378

Merged
etrepum merged 8 commits intofacebook:mainfrom
holly-agyei:feat-8189-autolink-custom-punctuation
Apr 24, 2026
Merged

[lexical-link][lexical-react] Feature: Allow custom punctuation for AutoLink boundaries#8378
etrepum merged 8 commits intofacebook:mainfrom
holly-agyei:feat-8189-autolink-custom-punctuation

Conversation

@holly-agyei
Copy link
Copy Markdown
Contributor

@holly-agyei holly-agyei commented Apr 20, 2026

Fixes #8189

Summary

  • add an optional punctuation setting to AutoLinkExtension and registerAutoLink
  • thread that option through AutoLinkPlugin while preserving the existing default separators
  • add coverage for colon-delimited custom matches and ensure URLs with embedded colons still autolink correctly
  • sync the published Flow declarations and React plugin docs with the new config

Test plan

  • ./node_modules/.bin/vitest --project unit --run packages/lexical-link/src/tests/unit/LexicalAutoLinkExtension.test.ts
  • ./node_modules/.bin/eslint --no-warn-ignored packages/lexical-link/src/LexicalAutoLinkExtension.ts packages/lexical-link/src/tests/unit/LexicalAutoLinkExtension.test.ts packages/lexical-react/src/LexicalAutoLinkPlugin.ts
  • ./node_modules/.bin/tsc -p tsconfig.json --noEmit

Copilot AI review requested due to automatic review settings April 20, 2026 19:50
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Apr 24, 2026 1:07am
lexical-playground Ready Ready Preview, Comment Apr 24, 2026 1:07am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 20, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a configurable punctuation boundary set for AutoLink matching so custom matchers can treat additional separators (e.g., :) as boundaries without breaking URL autolinking (including embedded colons).

Changes:

  • Thread a new optional punctuation option through registerAutoLink and the React AutoLinkPlugin.
  • Add unit tests covering colon-delimited matches and port URLs containing colons.
  • Update Flow declarations and React plugin docs to reflect the new option.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/lexical-website/docs/react/plugins.md Documents the new punctuation prop for AutoLinkPlugin.
packages/lexical-react/src/LexicalAutoLinkPlugin.ts Adds punctuation prop and passes it through to registerAutoLink.
packages/lexical-react/flow/LexicalAutoLinkPlugin.js.flow Updates Flow typings for AutoLinkPlugin props (including punctuation).
packages/lexical-link/src/LexicalAutoLinkExtension.ts Implements punctuation-driven boundary detection and threads config through core logic.
packages/lexical-link/src/tests/unit/LexicalAutoLinkExtension.test.ts Adds coverage for default/custom punctuation behavior and embedded-colon URLs.

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

Comment thread packages/lexical-website/docs/react/plugins.md Outdated
Comment thread packages/lexical-link/src/LexicalAutoLinkExtension.ts Outdated
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

pnpm run ci-check is failing

Comment thread packages/lexical-link/src/LexicalAutoLinkExtension.ts Outdated
Comment thread packages/lexical-link/src/LexicalAutoLinkExtension.ts Outdated
export type AutoLinkConfig = {
matchers: LinkMatcher[];
changeHandlers: ChangeHandler[];
excludeParents: Array<(parent: ElementNode) => boolean>;
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.

Suggested change
excludeParents: Array<(parent: ElementNode) => boolean>;
excludeParents: ((parent: ElementNode) => boolean)[];

This comment was marked as resolved.

changeHandlers: ChangeHandler[];
excludeParents: Array<(parent: ElementNode) => boolean>;
matchers: LinkMatcher[];
separatorRegex?: RegExp;
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.

Suggested change
separatorRegex?: RegExp;
separatorRegex: RegExp;

This comment was marked as resolved.

export interface AutoLinkConfig {
matchers: LinkMatcher[];
changeHandlers: ChangeHandler[];
excludeParents: Array<(parent: ElementNode) => boolean>;
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.

Suggested change
excludeParents: Array<(parent: ElementNode) => boolean>;
excludeParents: ((parent: ElementNode) => boolean)[];

This comment was marked as resolved.

* characters count as separators when validating auto-link
* boundaries. Defaults to `/[.,;\s]/`.
*/
separatorRegex?: RegExp;
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.

Configuration of extensions should always use required properties unless undefined is specifically a value that is useful to the extension.

Suggested change
separatorRegex?: RegExp;
separatorRegex: RegExp;

This comment was marked as resolved.


export function registerAutoLink(
editor: LexicalEditor,
config: AutoLinkConfig = defaultConfig,
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.

This type will have to change accordingly to something like Partial<AutoLinkConfig> (which would require some implementation changes below to provide defaults for each value) or Partial<AutoLinkConfig> & Omit<AutoLinkConfig, 'separatorRegex'>

Suggested change
config: AutoLinkConfig = defaultConfig,
config: Partial<AutoLinkConfig> & Omit<AutoLinkConfig, 'separatorRegex'> = defaultConfig,

This comment was marked as resolved.

export type {ChangeHandler, LinkMatcher};

declare export function AutoLinkPlugin(props: {
excludeParents?: Array<(parent: ElementNode) => boolean>,
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.

Suggested change
excludeParents?: Array<(parent: ElementNode) => boolean>,
excludeParents?: ((parent: ElementNode) => boolean)[],


declare export function AutoLinkPlugin(props: {
excludeParents?: Array<(parent: ElementNode) => boolean>,
matchers: Array<LinkMatcher>,
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.

Suggested change
matchers: Array<LinkMatcher>,
matchers: LinkMatcher[],

@holly-agyei
Copy link
Copy Markdown
Contributor Author

@etrepum I've pushed the updates to address your feedback regarding the Flow array syntax and the AutoLinkConfig properties. Could you please take another look when you have a chance?

Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

It doesn't look like you addressed any of the last round of suggestions?

export type AutoLinkConfig = {
matchers: LinkMatcher[];
changeHandlers: ChangeHandler[];
excludeParents: Array<(parent: ElementNode) => boolean>;

This comment was marked as resolved.

changeHandlers: ChangeHandler[];
excludeParents: Array<(parent: ElementNode) => boolean>;
matchers: LinkMatcher[];
separatorRegex?: RegExp;

This comment was marked as resolved.

export interface AutoLinkConfig {
matchers: LinkMatcher[];
changeHandlers: ChangeHandler[];
excludeParents: Array<(parent: ElementNode) => boolean>;

This comment was marked as resolved.

* characters count as separators when validating auto-link
* boundaries. Defaults to `/[.,;\s]/`.
*/
separatorRegex?: RegExp;

This comment was marked as resolved.


export function registerAutoLink(
editor: LexicalEditor,
config: AutoLinkConfig = defaultConfig,

This comment was marked as resolved.

@etrepum etrepum added this pull request to the merge queue Apr 24, 2026
Merged via the queue into facebook:main with commit a6081bb Apr 24, 2026
41 checks passed
@etrepum etrepum mentioned this pull request Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add colon to allowed separators for the AutoLinkPlugin

3 participants