add HTMLAttributes to defaultoptions

This commit is contained in:
Philipp Kühn
2020-11-13 16:44:22 +01:00
parent c840a562de
commit 2591ffe419
18 changed files with 173 additions and 26 deletions

View File

@@ -1,12 +1,16 @@
import {
Command, createMark, markPasteRule, mergeAttributes,
Command,
createMark,
markPasteRule,
mergeAttributes,
} from '@tiptap/core'
import { Plugin, PluginKey } from 'prosemirror-state'
export interface LinkOptions {
openOnClick: boolean,
target: string,
rel: string,
HTMLAttributes: {
[key: string]: any
},
}
export const pasteRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/()]*)/gi
@@ -18,8 +22,10 @@ const Link = createMark({
defaultOptions: <LinkOptions>{
openOnClick: true,
target: '_blank',
rel: 'noopener noreferrer nofollow',
HTMLAttributes: {
target: '_blank',
rel: 'noopener noreferrer nofollow',
},
},
addAttributes() {
@@ -28,7 +34,7 @@ const Link = createMark({
default: null,
},
target: {
default: this.options.target,
default: this.options.HTMLAttributes.target,
},
}
},
@@ -40,7 +46,7 @@ const Link = createMark({
},
renderHTML({ HTMLAttributes }) {
return ['a', mergeAttributes(HTMLAttributes, { rel: this.options.rel }), 0]
return ['a', mergeAttributes(HTMLAttributes, { rel: this.options.HTMLAttributes.rel }), 0]
},
addCommands() {