Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/lexical-link/src/LexicalAutoLinkExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import type {ElementNode, LexicalEditor, LexicalNode} from 'lexical';

import {$isCodeNode} from '@lexical/code';
import {mergeRegister} from '@lexical/utils';
import {
$createTextNode,
Expand Down Expand Up @@ -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()) ||
Expand Down
32 changes: 32 additions & 0 deletions packages/lexical-playground/__tests__/e2e/AutoLinks.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
<code
dir="auto"
spellcheck="false"
data-gutter="1"
data-highlight-language="javascript"
data-language="javascript">
<span data-lexical-text="true">http</span>
<span data-lexical-text="true">:</span>
<span data-lexical-text="true">/</span>
<span data-lexical-text="true">/</span>
<span data-lexical-text="true">example</span>
<span data-lexical-text="true">.</span>
<span data-lexical-text="true">com</span>
</code>
`,
undefined,
{ignoreClasses: true},
);
});
});