mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-30 21:27:51 +08:00
0c9ce26c02
This reverts commit 24c3a9abd3
.
# Conflicts:
# packages/core/src/Editor.ts
82 lines
1.3 KiB
TypeScript
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,
|
|
}
|
|
}
|