diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-11-16 11:01:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-16 11:01:39 +0300 |
commit | 17cfa888a0bafe0f9b1bf8ce9f6e0fc7e376ce1e (patch) | |
tree | e775dbb7f11fc3ea78366078a9959a030e16d1e1 /src/marks/index.js | |
parent | 5dddb1cd28bfef34d575f1bafa1d96fbf7b00863 (diff) | |
parent | c6066935fbda1e2bddd886f6919f1e675b2ce1e7 (diff) |
Merge pull request #1168 from nextcloud/backport/stable18/1165v18.0.11RC2
[stable18] Validate link on click
Diffstat (limited to 'src/marks/index.js')
-rw-r--r-- | src/marks/index.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/marks/index.js b/src/marks/index.js index d66da88ca..90687401a 100644 --- a/src/marks/index.js +++ b/src/marks/index.js @@ -20,7 +20,10 @@ * */ +import { Plugin } from 'tiptap' +import { getMarkAttrs } from 'tiptap-utils' import { Bold, Italic as TipTapItalic, Strike as TipTapStrike, Link as TipTapLink } from 'tiptap-extensions' +import { markdownit } from '../EditorFactory' /** * This file maps prosemirror mark names to tiptap classes, @@ -100,6 +103,35 @@ class Link extends TipTapLink { } } + get plugins() { + if (!this.options.openOnClick) { + return [] + } + + return [ + new Plugin({ + props: { + handleClick: (view, pos, event) => { + const { schema } = view.state + const attrs = getMarkAttrs(view.state, schema.marks.link) + + if (attrs.href && event.target instanceof HTMLAnchorElement) { + event.stopPropagation() + const htmlHref = event.target.href + + if (!markdownit.validateLink(htmlHref)) { + console.error('Invalid link', htmlHref) + return + } + + window.open(htmlHref) + } + }, + }, + }), + ] + } + } /** Strike is currently unsupported by prosemirror-markdown */ |