From b24df3aa4c2f3fdb2ed6122d2d32fb7c4e07f2af Mon Sep 17 00:00:00 2001 From: Ricardo Amaral Date: Fri, 7 Jul 2023 10:05:34 +0100 Subject: [PATCH] fix(link): Prevent auto-linking when typing URL inside inline code mark (#4160) --- .../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 9e00f5756..9a1f357d6 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)) {