Skip to content

Commit 98ff746

Browse files
committed
fix(richtext-lexical): auto link node escapes on second "."
Ports over facebook/lexical#6146
1 parent dfa6b08 commit 98ff746

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/richtext-lexical/src/features/link/plugins/autoLink/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ function startsWithSeparator(textContent: string): boolean {
7878
return isSeparator(textContent[0])
7979
}
8080

81+
function startsWithFullStop(textContent: string): boolean {
82+
return /^\.[a-z\d]+/i.test(textContent)
83+
}
84+
8185
function isPreviousNodeValid(node: LexicalNode): boolean {
8286
let previousNode = node.getPreviousSibling()
8387
if ($isElementNode(previousNode)) {
@@ -340,7 +344,10 @@ function handleBadNeighbors(
340344
const nextSibling = textNode.getNextSibling()
341345
const text = textNode.getTextContent()
342346

343-
if ($isAutoLinkNode(previousSibling) && !startsWithSeparator(text)) {
347+
if (
348+
$isAutoLinkNode(previousSibling) &&
349+
(!startsWithSeparator(text) || startsWithFullStop(text))
350+
) {
344351
previousSibling.append(textNode)
345352
handleLinkEdit(previousSibling, matchers, onChange)
346353
onChange(null, previousSibling.getFields()?.url ?? null)
@@ -418,7 +425,7 @@ function useAutoLink(
418425
}
419426

420427
const URL_REGEX =
421-
/((https?:\/\/(www\.)?)|(www\.))[-\w@:%.+~#=]{1,256}\.[a-zA-Z\d()]{1,6}\b([-\w()@:%+.~#?&/=]*)/
428+
/((https?:\/\/(www\.)?)|(www\.))[-\w@:%.+~#=]{1,256}\.[a-zA-Z\d()]{1,6}\b([-\w()@:%+.~#?&/=]*)(?<![-.+():%])/
422429

423430
const EMAIL_REGEX =
424431
/(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-z\-\d]+\.)+[a-z]{2,}))/i

0 commit comments

Comments
 (0)