mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-23 00:27:49 +08:00
51 lines
1.0 KiB
TypeScript
51 lines
1.0 KiB
TypeScript
import {
|
|
Command, Mark, markInputRule, markPasteRule,
|
|
} from '@tiptap/core'
|
|
|
|
type StrikeCommand = () => Command
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
interface Commands {
|
|
strike: StrikeCommand,
|
|
}
|
|
}
|
|
|
|
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(({ name }) => ({
|
|
strike: () => ({ commands }) => {
|
|
return commands.toggleMark(name)
|
|
},
|
|
}))
|
|
.keys(({ editor }) => ({
|
|
'Mod-d': () => editor.strike(),
|
|
}))
|
|
.inputRules(({ type }) => [
|
|
markInputRule(inputRegex, type),
|
|
])
|
|
.pasteRules(({ type }) => [
|
|
markPasteRule(inputRegex, type),
|
|
])
|
|
.create()
|