import { Mark, mergeAttributes } from '@tiptap/core'; export interface HtmlsourceOptions { HTMLAttributes: Record; } declare module '@tiptap/core' { interface Commands { htmlsource: { /** * Set an htmlsource mark */ setHtmlsource: () => ReturnType; /** * Toggle an htmlsource mark */ toggleHtmlsource: () => ReturnType; /** * Unset an htmlsource mark */ unsetHtmlsource: () => ReturnType; }; } } export const Htmlsource = Mark.create({ name: 'htmlsource', addOptions() { return { HTMLAttributes: {} }; }, parseHTML() { return [ { tag: 'htmlsource' } ]; }, renderHTML({ HTMLAttributes }) { return ['htmlsource', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]; }, addCommands() { return { setHtmlsource: () => ({ commands }) => { return commands.setMark(this.name); }, toggleHtmlsource: () => ({ commands }) => { return commands.toggleMark(this.name); }, unsetHtmlsource: () => ({ commands }) => { return commands.unsetMark(this.name); } }; } });