tiptap/packages/extension-strike/src/index.ts
Philipp Kühn 0c9ce26c02 Revert "use global namespace"
This reverts commit 24c3a9abd3.

# Conflicts:
#	packages/core/src/Editor.ts
2020-11-16 16:58:30 +01:00

82 lines
1.3 KiB
TypeScript

import {
Command,
Mark,
markInputRule,
markPasteRule,
} from '@tiptap/core'
export interface StrikeOptions {
HTMLAttributes: {
[key: string]: any
},
}
export const inputRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/gm
export const pasteRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/gm
const Strike = Mark.create({
name: 'strike',
defaultOptions: <StrikeOptions>{
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,
}
}