2020-09-24 06:29:05 +08:00
|
|
|
import {
|
2020-10-22 18:34:49 +08:00
|
|
|
Command, createMark, markInputRule, markPasteRule,
|
2020-09-24 06:29:05 +08:00
|
|
|
} from '@tiptap/core'
|
2020-09-22 05:17:30 +08:00
|
|
|
|
2020-10-02 21:05:26 +08:00
|
|
|
export const inputRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/gm
|
|
|
|
export const pasteRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/gm
|
2020-09-10 17:20:40 +08:00
|
|
|
|
2020-10-23 04:40:40 +08:00
|
|
|
const Strike = createMark({
|
2020-10-22 18:34:49 +08:00
|
|
|
name: 'strike',
|
|
|
|
|
|
|
|
parseHTML() {
|
|
|
|
return [
|
2020-09-10 17:20:40 +08:00
|
|
|
{
|
|
|
|
tag: 's',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tag: 'del',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
tag: 'strike',
|
|
|
|
},
|
|
|
|
{
|
2020-10-28 05:40:07 +08:00
|
|
|
style: 'text-decoration=line-through',
|
2020-09-10 17:20:40 +08:00
|
|
|
},
|
2020-10-22 18:34:49 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
renderHTML({ attributes }) {
|
|
|
|
return ['s', attributes, 0]
|
|
|
|
},
|
|
|
|
|
|
|
|
addCommands() {
|
|
|
|
return {
|
2020-10-23 04:40:40 +08:00
|
|
|
strike: (): Command => ({ commands }) => {
|
2020-10-22 18:34:49 +08:00
|
|
|
return commands.toggleMark('strike')
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addKeyboardShortcuts() {
|
|
|
|
return {
|
2020-11-13 18:42:04 +08:00
|
|
|
'Mod-d': () => this.editor.commands.strike(),
|
2020-10-22 18:34:49 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addInputRules() {
|
|
|
|
return [
|
|
|
|
markInputRule(inputRegex, this.type),
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
addPasteRules() {
|
|
|
|
return [
|
|
|
|
markPasteRule(inputRegex, this.type),
|
|
|
|
]
|
|
|
|
},
|
|
|
|
})
|
2020-10-23 04:40:40 +08:00
|
|
|
|
|
|
|
export default Strike
|
|
|
|
|
2020-11-11 04:18:22 +08:00
|
|
|
declare module '@tiptap/core' {
|
2020-10-23 04:40:40 +08:00
|
|
|
interface AllExtensions {
|
|
|
|
Strike: typeof Strike,
|
|
|
|
}
|
|
|
|
}
|