import { AutoLinkPlugin, createLinkMatcherWithRegExp } from "@lexical/react/LexicalAutoLinkPlugin"; /** * Original create an URL with http://mydomain.c * const URL_REGEX = * /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)(?()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/; * * I'm aware that for tech users with an email in *.me this autolink doesn't trigger * but for the majority of users the first tld is 3 chars minimum and trigger an autolink after * 1 character can be disturbing */ const URL_REGEX = /((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{3,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)(?()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{3,}))/; const MATCHERS = [ createLinkMatcherWithRegExp(URL_REGEX, (text) => { return text.startsWith("http") ? text : `https://${text}`; }), createLinkMatcherWithRegExp(EMAIL_REGEX, (text) => { return `mailto:${text}`; }), ]; export function CustomAutoLinkPlugin() { return ; }