mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-24 09:27:49 +08:00
0c9ce26c02
This reverts commit 24c3a9abd3
.
# Conflicts:
# packages/core/src/Editor.ts
73 lines
1.1 KiB
TypeScript
73 lines
1.1 KiB
TypeScript
import {
|
|
Command,
|
|
Mark,
|
|
markInputRule,
|
|
markPasteRule,
|
|
} from '@tiptap/core'
|
|
|
|
export interface CodeOptions {
|
|
HTMLAttributes: {
|
|
[key: string]: any
|
|
},
|
|
}
|
|
|
|
export const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/gm
|
|
export const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/gm
|
|
|
|
const Code = Mark.create({
|
|
name: 'code',
|
|
|
|
defaultOptions: <CodeOptions>{
|
|
HTMLAttributes: {},
|
|
},
|
|
|
|
excludes: '_',
|
|
|
|
parseHTML() {
|
|
return [
|
|
{ tag: 'code' },
|
|
]
|
|
},
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
return ['code', HTMLAttributes, 0]
|
|
},
|
|
|
|
addCommands() {
|
|
return {
|
|
/**
|
|
* Toggle inline code
|
|
*/
|
|
code: (): Command => ({ commands }) => {
|
|
return commands.toggleMark('code')
|
|
},
|
|
}
|
|
},
|
|
|
|
addKeyboardShortcuts() {
|
|
return {
|
|
'Mod-`': () => this.editor.commands.code(),
|
|
}
|
|
},
|
|
|
|
addInputRules() {
|
|
return [
|
|
markInputRule(inputRegex, this.type),
|
|
]
|
|
},
|
|
|
|
addPasteRules() {
|
|
return [
|
|
markPasteRule(inputRegex, this.type),
|
|
]
|
|
},
|
|
})
|
|
|
|
export default Code
|
|
|
|
declare module '@tiptap/core' {
|
|
interface AllExtensions {
|
|
Code: typeof Code,
|
|
}
|
|
}
|