From 7cc96b617cc1388419e01f4a43db176487237485 Mon Sep 17 00:00:00 2001 From: Ricardo Amaral Date: Mon, 26 Jun 2023 16:59:41 +0000 Subject: [PATCH] fix: Prevent auto-linking when typing URL inside inline code mark --- .../extension-link/src/helpers/autolink.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/extension-link/src/helpers/autolink.ts b/packages/extension-link/src/helpers/autolink.ts index 9e00f57567e..9a1f357d615 100644 --- a/packages/extension-link/src/helpers/autolink.ts +++ b/packages/extension-link/src/helpers/autolink.ts @@ -112,18 +112,27 @@ export function autolink(options: AutolinkOptions): Plugin { find(lastWordBeforeSpace) .filter(link => link.isLink) - .filter(link => { - if (options.validate) { - return options.validate(link.value) - } - return true - }) // Calculate link position. .map(link => ({ ...link, from: lastWordAndBlockOffset + link.start + 1, to: lastWordAndBlockOffset + link.end + 1, })) + // ignore link inside code mark + .filter(link => { + return !newState.doc.rangeHasMark( + link.from, + link.to, + newState.schema.marks.code, + ) + }) + // validate link + .filter(link => { + if (options.validate) { + return options.validate(link.value) + } + return true + }) // Add link mark. .forEach(link => { if (getMarksBetween(link.from, link.to, newState.doc).some(item => item.mark.type === options.type)) {