You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
61 lines
1.6 KiB
import { Mark, mergeAttributes, markInputRule, markPasteRule } from '@tiptap/core';
|
|
|
|
const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/;
|
|
const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/g;
|
|
const Code = Mark.create({
|
|
name: 'code',
|
|
addOptions() {
|
|
return {
|
|
HTMLAttributes: {},
|
|
};
|
|
},
|
|
excludes: '_',
|
|
code: true,
|
|
exitable: true,
|
|
parseHTML() {
|
|
return [
|
|
{ tag: 'code' },
|
|
];
|
|
},
|
|
renderHTML({ HTMLAttributes }) {
|
|
return ['code', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
},
|
|
addCommands() {
|
|
return {
|
|
setCode: () => ({ commands }) => {
|
|
return commands.setMark(this.name);
|
|
},
|
|
toggleCode: () => ({ commands }) => {
|
|
return commands.toggleMark(this.name);
|
|
},
|
|
unsetCode: () => ({ commands }) => {
|
|
return commands.unsetMark(this.name);
|
|
},
|
|
};
|
|
},
|
|
addKeyboardShortcuts() {
|
|
return {
|
|
'Mod-e': () => this.editor.commands.toggleCode(),
|
|
};
|
|
},
|
|
addInputRules() {
|
|
return [
|
|
markInputRule({
|
|
find: inputRegex,
|
|
type: this.type,
|
|
}),
|
|
];
|
|
},
|
|
addPasteRules() {
|
|
return [
|
|
markPasteRule({
|
|
find: pasteRegex,
|
|
type: this.type,
|
|
}),
|
|
];
|
|
},
|
|
});
|
|
|
|
export { Code, Code as default, inputRegex, pasteRegex };
|
|
//# sourceMappingURL=tiptap-extension-code.esm.js.map
|