Skip to content

Commit 82301a1

Browse files
committed
fix(links): adjust the anchor link only in Link.js
Signed-off-by: Max <[email protected]>
1 parent aba1929 commit 82301a1

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/marks/Link.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import TipTapLink from '@tiptap/extension-link'
2424
import { domHref, parseHref } from './../helpers/links.js'
2525
import { linkClicking } from '../plugins/links.js'
2626

27+
const PROTOCOLS_TO_LINK_TO = ['http:', 'https:', 'mailto:', 'tel:']
28+
2729
const Link = TipTapLink.extend({
2830

2931
addOptions() {
@@ -58,9 +60,13 @@ const Link = TipTapLink.extend({
5860

5961
renderHTML(options) {
6062
const { mark } = options
63+
const url = new URL(mark.attrs.href, window.location)
64+
const href = PROTOCOLS_TO_LINK_TO.includes(url.protocol)
65+
? domHref(mark, this.options.relativePath)
66+
: '#'
6167
return ['a', {
6268
...mark.attrs,
63-
href: domHref(mark, this.options.relativePath),
69+
href,
6470
'data-md-href': mark.attrs.href,
6571
rel: 'noopener noreferrer nofollow',
6672
}, 0]

0 commit comments

Comments
 (0)