import { Mark, mergeAttributes, CommandProps } from '@tiptap/core'; export const PageLink = Mark.create({ name: 'pageLink', priority: 1000, keepOnSplit: false, inclusive() { return this.options.autolink; }, addOptions() { return { autolink: true, HTMLAttributes: { target: null, rel: null } }; }, addAttributes() { return { href: { default: null }, target: { default: this.options.HTMLAttributes.target }, rel: { default: this.options.HTMLAttributes.rel } }; }, parseHTML() { return [{ tag: 'a[href]:not([href *= "javascript:" i])' }]; }, renderHTML({ HTMLAttributes }) { return ['a', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, addCommands() { return { setPageLink: (attributes: { href: string; target?: string }) => ({ chain }: CommandProps) => { return chain().setMark(this.name, attributes).setMeta('preventAutolink', true).run(); }, unsetPageLink: () => ({ chain }: CommandProps) => { return chain().unsetMark(this.name, { extendEmptyMarkRange: true }).setMeta('preventAutolink', true).run(); } }; } });