UNPKG

@tiptap/extension-code

Version:

code extension for tiptap

65 lines (64 loc) 1.37 kB
// src/code.ts import { Mark, markInputRule, markPasteRule, mergeAttributes } from "@tiptap/core"; var inputRegex = /(^|[^`])`([^`]+)`(?!`)/; var pasteRegex = /(^|[^`])`([^`]+)`(?!`)/g; var 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 }) ]; } }); // src/index.ts var index_default = Code; export { Code, index_default as default, inputRegex, pasteRegex }; //# sourceMappingURL=index.js.map