Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/marks
diff options
context:
space:
mode:
Diffstat (limited to 'src/marks')
-rw-r--r--src/marks/index.js32
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 */