import { Command, MarkExtension, markInputRule, markPasteRule, } from '@tiptap/core' export interface StrikeOptions { HTMLAttributes: { [key: string]: any }, } export const inputRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/gm export const pasteRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/gm const Strike = MarkExtension.create({ name: 'strike', defaultOptions: { HTMLAttributes: {}, }, parseHTML() { return [ { tag: 's', }, { tag: 'del', }, { tag: 'strike', }, { style: 'text-decoration=line-through', }, ] }, renderHTML({ HTMLAttributes }) { return ['s', HTMLAttributes, 0] }, addCommands() { return { /** * Toggle a strike mark */ strike: (): Command => ({ commands }) => { return commands.toggleMark('strike') }, } }, addKeyboardShortcuts() { return { 'Mod-d': () => this.editor.commands.strike(), } }, addInputRules() { return [ markInputRule(inputRegex, this.type), ] }, addPasteRules() { return [ markPasteRule(inputRegex, this.type), ] }, }) export default Strike declare module '@tiptap/core' { interface AllExtensions { Strike: typeof Strike, } }