2020-09-24 06:29:05 +08:00
|
|
|
import {
|
2020-11-13 23:44:22 +08:00
|
|
|
Command,
|
2020-11-16 18:19:43 +08:00
|
|
|
Mark,
|
2020-11-13 23:44:22 +08:00
|
|
|
markInputRule,
|
|
|
|
markPasteRule,
|
2020-11-25 16:50:54 +08:00
|
|
|
mergeAttributes,
|
2020-09-24 06:29:05 +08:00
|
|
|
} from '@tiptap/core'
|
2020-09-22 05:17:30 +08:00
|
|
|
|
2020-11-13 23:44:22 +08:00
|
|
|
export interface StrikeOptions {
|
|
|
|
HTMLAttributes: {
|
|
|
|
[key: string]: any
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
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-12-08 04:32:50 +08:00
|
|
|
export const Strike = Mark.create({
|
2020-10-22 18:34:49 +08:00
|
|
|
name: 'strike',
|
|
|
|
|
2020-11-13 23:44:22 +08:00
|
|
|
defaultOptions: <StrikeOptions>{
|
|
|
|
HTMLAttributes: {},
|
|
|
|
},
|
|
|
|
|
2020-10-22 18:34:49 +08:00
|
|
|
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
|
|
|
]
|
|
|
|
},
|
|
|
|
|
2020-11-13 23:07:20 +08:00
|
|
|
renderHTML({ HTMLAttributes }) {
|
2020-11-25 16:50:54 +08:00
|
|
|
return ['s', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
2020-10-22 18:34:49 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
addCommands() {
|
|
|
|
return {
|
2020-11-18 04:50:40 +08:00
|
|
|
/**
|
2020-11-18 23:59:58 +08:00
|
|
|
* Set a strike mark
|
2020-11-18 04:50:40 +08:00
|
|
|
*/
|
2020-11-18 23:59:58 +08:00
|
|
|
setStrike: (): Command => ({ commands }) => {
|
2020-11-19 00:36:00 +08:00
|
|
|
return commands.setMark('strike')
|
2020-11-18 04:50:40 +08:00
|
|
|
},
|
2020-11-13 22:08:30 +08:00
|
|
|
/**
|
|
|
|
* Toggle a strike mark
|
|
|
|
*/
|
2020-11-18 04:50:40 +08:00
|
|
|
toggleStrike: (): Command => ({ commands }) => {
|
2020-10-22 18:34:49 +08:00
|
|
|
return commands.toggleMark('strike')
|
|
|
|
},
|
2020-11-18 04:50:40 +08:00
|
|
|
/**
|
2020-11-18 23:59:58 +08:00
|
|
|
* Unset a strike mark
|
2020-11-18 04:50:40 +08:00
|
|
|
*/
|
2020-11-18 23:59:58 +08:00
|
|
|
unsetStrike: (): Command => ({ commands }) => {
|
2020-11-19 00:38:16 +08:00
|
|
|
return commands.unsetMark('strike')
|
2020-11-18 04:50:40 +08:00
|
|
|
},
|
2020-10-22 18:34:49 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addKeyboardShortcuts() {
|
|
|
|
return {
|
2020-11-19 08:16:10 +08:00
|
|
|
'Mod-Shift-x': () => this.editor.commands.toggleStrike(),
|
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
|
|
|
|
2020-11-16 23:58:30 +08:00
|
|
|
declare module '@tiptap/core' {
|
|
|
|
interface AllExtensions {
|
|
|
|
Strike: typeof Strike,
|
2020-10-23 04:40:40 +08:00
|
|
|
}
|
|
|
|
}
|