diff --git a/packages/richtext-lexical/src/features/link/plugins/autoLink/index.tsx b/packages/richtext-lexical/src/features/link/plugins/autoLink/index.tsx index 7f97e20ef8..b89a425f31 100644 --- a/packages/richtext-lexical/src/features/link/plugins/autoLink/index.tsx +++ b/packages/richtext-lexical/src/features/link/plugins/autoLink/index.tsx @@ -78,6 +78,10 @@ function startsWithSeparator(textContent: string): boolean { return isSeparator(textContent[0]) } +function startsWithFullStop(textContent: string): boolean { + return /^\.[a-z\d]+/i.test(textContent) +} + function isPreviousNodeValid(node: LexicalNode): boolean { let previousNode = node.getPreviousSibling() if ($isElementNode(previousNode)) { @@ -340,7 +344,10 @@ function handleBadNeighbors( const nextSibling = textNode.getNextSibling() const text = textNode.getTextContent() - if ($isAutoLinkNode(previousSibling) && !startsWithSeparator(text)) { + if ( + $isAutoLinkNode(previousSibling) && + (!startsWithSeparator(text) || startsWithFullStop(text)) + ) { previousSibling.append(textNode) handleLinkEdit(previousSibling, matchers, onChange) onChange(null, previousSibling.getFields()?.url ?? null) @@ -418,7 +425,7 @@ function useAutoLink( } const URL_REGEX = - /((https?:\/\/(www\.)?)|(www\.))[-\w@:%.+~#=]{1,256}\.[a-zA-Z\d()]{1,6}\b([-\w()@:%+.~#?&/=]*)/ + /((https?:\/\/(www\.)?)|(www\.))[-\w@:%.+~#=]{1,256}\.[a-zA-Z\d()]{1,6}\b([-\w()@:%+.~#?&/=]*)(?()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-z\-\d]+\.)+[a-z]{2,}))/i