From dde09dd632fe4de086db7c0281836473ad0c31d9 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 16 Sep 2024 18:57:43 +0200 Subject: [PATCH] fix(links): adjust the anchor link only in Link.js Signed-off-by: Max --- src/marks/Link.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/marks/Link.js b/src/marks/Link.js index 70a9f48c8bc..086e82419bd 100644 --- a/src/marks/Link.js +++ b/src/marks/Link.js @@ -24,6 +24,8 @@ import TipTapLink from '@tiptap/extension-link' import { domHref, parseHref, openLink } from './../helpers/links.js' import { clickHandler, clickPreventer } from '../plugins/link.js' +const PROTOCOLS_TO_LINK_TO = ['http:', 'https:', 'mailto:', 'tel:'] + const Link = TipTapLink.extend({ addOptions() { @@ -59,10 +61,13 @@ const Link = TipTapLink.extend({ renderHTML(options) { const { mark } = options - + const url = new URL(mark.attrs.href, window.location) + const href = PROTOCOLS_TO_LINK_TO.includes(url.protocol) + ? domHref(mark, this.options.relativePath) + : '#' return ['a', { ...mark.attrs, - href: domHref(mark, this.options.relativePath), + href, rel: 'noopener noreferrer nofollow', }, 0] },