diff --git a/packages/extension-bold/index.ts b/packages/extension-bold/index.ts index e4e7b0a62..ca93bd55b 100644 --- a/packages/extension-bold/index.ts +++ b/packages/extension-bold/index.ts @@ -29,7 +29,7 @@ export default new Mark() ], toDOM: () => ['strong', 0], })) - .commands(({ editor, name, type }) => ({ + .commands(({ editor, name }) => ({ bold: next => () => { editor.toggleMark(name) next() diff --git a/packages/extension-strike/index.ts b/packages/extension-strike/index.ts new file mode 100644 index 000000000..350648c4e --- /dev/null +++ b/packages/extension-strike/index.ts @@ -0,0 +1,47 @@ +import { Mark, markInputRule, markPasteRule } from '@tiptap/core' + +declare module '@tiptap/core/src/Editor' { + interface Editor { + strike(): Editor, + } +} + +export const inputRegex = /(?:^|\s)((?:~)((?:[^~]+))(?:~))$/gm +export const pasteRegex = /(?:^|\s)((?:~)((?:[^~]+))(?:~))/gm + +export default new Mark() + .name('strike') + .schema(() => ({ + parseDOM: [ + { + tag: 's', + }, + { + tag: 'del', + }, + { + tag: 'strike', + }, + { + style: 'text-decoration', + getAttrs: node => node === 'line-through' ? {} : false, + }, + ], + toDOM: () => ['s', 0], + })) + .commands(({ editor, name }) => ({ + strike: next => () => { + editor.toggleMark(name) + next() + }, + })) + .keys(({ editor }) => ({ + 'Mod-d': () => editor.strike() + })) + .inputRules(({ type }) => [ + markInputRule(inputRegex, type) + ]) + .pasteRules(({ type }) => [ + markPasteRule(inputRegex, type) + ]) + .create() diff --git a/packages/extension-strike/package.json b/packages/extension-strike/package.json new file mode 100644 index 000000000..6e024b038 --- /dev/null +++ b/packages/extension-strike/package.json @@ -0,0 +1,17 @@ +{ + "name": "@tiptap/extension-strike", + "version": "1.0.0", + "source": "index.ts", + "main": "dist/tiptap-extension-strike.js", + "umd:main": "dist/tiptap-extension-strike.umd.js", + "module": "dist/tiptap-extension-strike.mjs", + "unpkg": "dist/tiptap-extension-strike.js", + "jsdelivr": "dist/tiptap-extension-strike.js", + "files": [ + "src", + "dist" + ], + "peerDependencies": { + "@tiptap/core": "2.x" + } +}