diff --git a/packages/lexical-link/src/LexicalAutoLinkExtension.ts b/packages/lexical-link/src/LexicalAutoLinkExtension.ts index 9277f1df851..066206c7d51 100644 --- a/packages/lexical-link/src/LexicalAutoLinkExtension.ts +++ b/packages/lexical-link/src/LexicalAutoLinkExtension.ts @@ -8,6 +8,7 @@ import type {ElementNode, LexicalEditor, LexicalNode} from 'lexical'; +import {$isCodeNode} from '@lexical/code'; import {mergeRegister} from '@lexical/utils'; import { $createTextNode, @@ -475,7 +476,7 @@ export function registerAutoLink( const previous = textNode.getPreviousSibling(); if ($isAutoLinkNode(parent) && !parent.getIsUnlinked()) { handleLinkEdit(parent, matchers, onChange); - } else if (!$isLinkNode(parent)) { + } else if (!$isLinkNode(parent) && !$isCodeNode(parent)) { if ( textNode.isSimpleText() && (startsWithSeparator(textNode.getTextContent()) || diff --git a/packages/lexical-playground/__tests__/e2e/AutoLinks.spec.mjs b/packages/lexical-playground/__tests__/e2e/AutoLinks.spec.mjs index abf9e8ad8eb..7cc9677014d 100644 --- a/packages/lexical-playground/__tests__/e2e/AutoLinks.spec.mjs +++ b/packages/lexical-playground/__tests__/e2e/AutoLinks.spec.mjs @@ -752,4 +752,36 @@ test.describe.parallel('Auto Links', () => { {ignoreClasses: true}, ); }); + + test('Does not convert URLs inside code blocks to links', async ({ + page, + isPlainText, + }) => { + test.skip(isPlainText); + await focusEditor(page); + + await page.keyboard.type('``` http://example.com'); + + await assertHTML( + page, + html` + + http + : + / + / + example + . + com + + `, + undefined, + {ignoreClasses: true}, + ); + }); });