@tiptap/extension-code
Advanced tools
+3
-3
| { | ||
| "name": "@tiptap/extension-code", | ||
| "description": "code extension for tiptap", | ||
| "version": "3.20.2", | ||
| "version": "3.20.3", | ||
| "homepage": "https://tiptap.dev", | ||
@@ -34,6 +34,6 @@ "keywords": [ | ||
| "devDependencies": { | ||
| "@tiptap/core": "^3.20.2" | ||
| "@tiptap/core": "^3.20.3" | ||
| }, | ||
| "peerDependencies": { | ||
| "@tiptap/core": "^3.20.2" | ||
| "@tiptap/core": "^3.20.3" | ||
| }, | ||
@@ -40,0 +40,0 @@ "repository": { |
-104
| "use strict"; | ||
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if (from && typeof from === "object" || typeof from === "function") { | ||
| for (let key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| // src/index.ts | ||
| var index_exports = {}; | ||
| __export(index_exports, { | ||
| Code: () => Code, | ||
| default: () => index_default, | ||
| inputRegex: () => inputRegex, | ||
| pasteRegex: () => pasteRegex | ||
| }); | ||
| module.exports = __toCommonJS(index_exports); | ||
| // src/code.ts | ||
| var import_core = require("@tiptap/core"); | ||
| var inputRegex = /(^|[^`])`([^`]+)`(?!`)$/; | ||
| var pasteRegex = /(^|[^`])`([^`]+)`(?!`)/g; | ||
| var Code = import_core.Mark.create({ | ||
| name: "code", | ||
| addOptions() { | ||
| return { | ||
| HTMLAttributes: {} | ||
| }; | ||
| }, | ||
| excludes: "_", | ||
| code: true, | ||
| exitable: true, | ||
| parseHTML() { | ||
| return [{ tag: "code" }]; | ||
| }, | ||
| renderHTML({ HTMLAttributes }) { | ||
| return ["code", (0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0]; | ||
| }, | ||
| markdownTokenName: "codespan", | ||
| parseMarkdown: (token, helpers) => { | ||
| return helpers.applyMark("code", [{ type: "text", text: token.text || "" }]); | ||
| }, | ||
| renderMarkdown: (node, h) => { | ||
| if (!node.content) { | ||
| return ""; | ||
| } | ||
| return `\`${h.renderChildren(node.content)}\``; | ||
| }, | ||
| 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 [ | ||
| (0, import_core.markInputRule)({ | ||
| find: inputRegex, | ||
| type: this.type | ||
| }) | ||
| ]; | ||
| }, | ||
| addPasteRules() { | ||
| return [ | ||
| (0, import_core.markPasteRule)({ | ||
| find: pasteRegex, | ||
| type: this.type | ||
| }) | ||
| ]; | ||
| } | ||
| }); | ||
| // src/index.ts | ||
| var index_default = Code; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| Code, | ||
| inputRegex, | ||
| pasteRegex | ||
| }); | ||
| //# sourceMappingURL=index.cjs.map |
| {"version":3,"sources":["../src/index.ts","../src/code.ts"],"sourcesContent":["import { Code } from './code.js'\n\nexport * from './code.js'\n\nexport default Code\n","import { Mark, markInputRule, markPasteRule, mergeAttributes } from '@tiptap/core'\n\nexport interface CodeOptions {\n /**\n * The HTML attributes applied to the code element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n code: {\n /**\n * Set a code mark\n */\n setCode: () => ReturnType\n /**\n * Toggle inline code\n */\n toggleCode: () => ReturnType\n /**\n * Unset a code mark\n */\n unsetCode: () => ReturnType\n }\n }\n}\n\n/**\n * Regular expressions to match inline code blocks enclosed in backticks.\n * It matches:\n * - An opening backtick, followed by\n * - Any text that doesn't include a backtick (captured for marking), followed by\n * - A closing backtick as the final character.\n * This ensures that any text between backticks is formatted as code,\n * regardless of the surrounding characters (exception being another backtick).\n */\nexport const inputRegex = /(^|[^`])`([^`]+)`(?!`)$/\n\n/**\n * Matches inline code while pasting.\n */\nexport const pasteRegex = /(^|[^`])`([^`]+)`(?!`)/g\n\n/**\n * This extension allows you to mark text as inline code.\n * @see https://tiptap.dev/api/marks/code\n */\nexport const Code = Mark.create<CodeOptions>({\n name: 'code',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n excludes: '_',\n\n code: true,\n\n exitable: true,\n\n parseHTML() {\n return [{ tag: 'code' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['code', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n markdownTokenName: 'codespan',\n\n parseMarkdown: (token, helpers) => {\n // Convert 'codespan' token to code mark\n // For codespan tokens, we use the raw text content, not tokens\n return helpers.applyMark('code', [{ type: 'text', text: token.text || '' }])\n },\n\n renderMarkdown: (node, h) => {\n if (!node.content) {\n return ''\n }\n\n return `\\`${h.renderChildren(node.content)}\\``\n },\n\n addCommands() {\n return {\n setCode:\n () =>\n ({ commands }) => {\n return commands.setMark(this.name)\n },\n toggleCode:\n () =>\n ({ commands }) => {\n return commands.toggleMark(this.name)\n },\n unsetCode:\n () =>\n ({ commands }) => {\n return commands.unsetMark(this.name)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-e': () => this.editor.commands.toggleCode(),\n }\n },\n\n addInputRules() {\n return [\n markInputRule({\n find: inputRegex,\n type: this.type,\n }),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule({\n find: pasteRegex,\n type: this.type,\n }),\n ]\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAoE;AAuC7D,IAAM,aAAa;AAKnB,IAAM,aAAa;AAMnB,IAAM,OAAO,iBAAK,OAAoB;AAAA,EAC3C,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,gBAAgB,CAAC;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,UAAU;AAAA,EAEV,MAAM;AAAA,EAEN,UAAU;AAAA,EAEV,YAAY;AACV,WAAO,CAAC,EAAE,KAAK,OAAO,CAAC;AAAA,EACzB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,YAAQ,6BAAgB,KAAK,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAAA,EACjF;AAAA,EAEA,mBAAmB;AAAA,EAEnB,eAAe,CAAC,OAAO,YAAY;AAGjC,WAAO,QAAQ,UAAU,QAAQ,CAAC,EAAE,MAAM,QAAQ,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC;AAAA,EAC7E;AAAA,EAEA,gBAAgB,CAAC,MAAM,MAAM;AAC3B,QAAI,CAAC,KAAK,SAAS;AACjB,aAAO;AAAA,IACT;AAEA,WAAO,KAAK,EAAE,eAAe,KAAK,OAAO,CAAC;AAAA,EAC5C;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,SACE,MACA,CAAC,EAAE,SAAS,MAAM;AAChB,eAAO,SAAS,QAAQ,KAAK,IAAI;AAAA,MACnC;AAAA,MACF,YACE,MACA,CAAC,EAAE,SAAS,MAAM;AAChB,eAAO,SAAS,WAAW,KAAK,IAAI;AAAA,MACtC;AAAA,MACF,WACE,MACA,CAAC,EAAE,SAAS,MAAM;AAChB,eAAO,SAAS,UAAU,KAAK,IAAI;AAAA,MACrC;AAAA,IACJ;AAAA,EACF;AAAA,EAEA,uBAAuB;AACrB,WAAO;AAAA,MACL,SAAS,MAAM,KAAK,OAAO,SAAS,WAAW;AAAA,IACjD;AAAA,EACF;AAAA,EAEA,gBAAgB;AACd,WAAO;AAAA,UACL,2BAAc;AAAA,QACZ,MAAM;AAAA,QACN,MAAM,KAAK;AAAA,MACb,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,gBAAgB;AACd,WAAO;AAAA,UACL,2BAAc;AAAA,QACZ,MAAM;AAAA,QACN,MAAM,KAAK;AAAA,MACb,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;ADhID,IAAO,gBAAQ;","names":[]} |
| import { Mark } from '@tiptap/core'; | ||
| interface CodeOptions { | ||
| /** | ||
| * The HTML attributes applied to the code element. | ||
| * @default {} | ||
| * @example { class: 'foo' } | ||
| */ | ||
| HTMLAttributes: Record<string, any>; | ||
| } | ||
| declare module '@tiptap/core' { | ||
| interface Commands<ReturnType> { | ||
| code: { | ||
| /** | ||
| * Set a code mark | ||
| */ | ||
| setCode: () => ReturnType; | ||
| /** | ||
| * Toggle inline code | ||
| */ | ||
| toggleCode: () => ReturnType; | ||
| /** | ||
| * Unset a code mark | ||
| */ | ||
| unsetCode: () => ReturnType; | ||
| }; | ||
| } | ||
| } | ||
| /** | ||
| * Regular expressions to match inline code blocks enclosed in backticks. | ||
| * It matches: | ||
| * - An opening backtick, followed by | ||
| * - Any text that doesn't include a backtick (captured for marking), followed by | ||
| * - A closing backtick as the final character. | ||
| * This ensures that any text between backticks is formatted as code, | ||
| * regardless of the surrounding characters (exception being another backtick). | ||
| */ | ||
| declare const inputRegex: RegExp; | ||
| /** | ||
| * Matches inline code while pasting. | ||
| */ | ||
| declare const pasteRegex: RegExp; | ||
| /** | ||
| * This extension allows you to mark text as inline code. | ||
| * @see https://tiptap.dev/api/marks/code | ||
| */ | ||
| declare const Code: Mark<CodeOptions, any>; | ||
| export { Code, type CodeOptions, Code as default, inputRegex, pasteRegex }; |
| import { Mark } from '@tiptap/core'; | ||
| interface CodeOptions { | ||
| /** | ||
| * The HTML attributes applied to the code element. | ||
| * @default {} | ||
| * @example { class: 'foo' } | ||
| */ | ||
| HTMLAttributes: Record<string, any>; | ||
| } | ||
| declare module '@tiptap/core' { | ||
| interface Commands<ReturnType> { | ||
| code: { | ||
| /** | ||
| * Set a code mark | ||
| */ | ||
| setCode: () => ReturnType; | ||
| /** | ||
| * Toggle inline code | ||
| */ | ||
| toggleCode: () => ReturnType; | ||
| /** | ||
| * Unset a code mark | ||
| */ | ||
| unsetCode: () => ReturnType; | ||
| }; | ||
| } | ||
| } | ||
| /** | ||
| * Regular expressions to match inline code blocks enclosed in backticks. | ||
| * It matches: | ||
| * - An opening backtick, followed by | ||
| * - Any text that doesn't include a backtick (captured for marking), followed by | ||
| * - A closing backtick as the final character. | ||
| * This ensures that any text between backticks is formatted as code, | ||
| * regardless of the surrounding characters (exception being another backtick). | ||
| */ | ||
| declare const inputRegex: RegExp; | ||
| /** | ||
| * Matches inline code while pasting. | ||
| */ | ||
| declare const pasteRegex: RegExp; | ||
| /** | ||
| * This extension allows you to mark text as inline code. | ||
| * @see https://tiptap.dev/api/marks/code | ||
| */ | ||
| declare const Code: Mark<CodeOptions, any>; | ||
| export { Code, type CodeOptions, Code as default, inputRegex, pasteRegex }; |
| // 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]; | ||
| }, | ||
| markdownTokenName: "codespan", | ||
| parseMarkdown: (token, helpers) => { | ||
| return helpers.applyMark("code", [{ type: "text", text: token.text || "" }]); | ||
| }, | ||
| renderMarkdown: (node, h) => { | ||
| if (!node.content) { | ||
| return ""; | ||
| } | ||
| return `\`${h.renderChildren(node.content)}\``; | ||
| }, | ||
| 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 |
| {"version":3,"sources":["../src/code.ts","../src/index.ts"],"sourcesContent":["import { Mark, markInputRule, markPasteRule, mergeAttributes } from '@tiptap/core'\n\nexport interface CodeOptions {\n /**\n * The HTML attributes applied to the code element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n code: {\n /**\n * Set a code mark\n */\n setCode: () => ReturnType\n /**\n * Toggle inline code\n */\n toggleCode: () => ReturnType\n /**\n * Unset a code mark\n */\n unsetCode: () => ReturnType\n }\n }\n}\n\n/**\n * Regular expressions to match inline code blocks enclosed in backticks.\n * It matches:\n * - An opening backtick, followed by\n * - Any text that doesn't include a backtick (captured for marking), followed by\n * - A closing backtick as the final character.\n * This ensures that any text between backticks is formatted as code,\n * regardless of the surrounding characters (exception being another backtick).\n */\nexport const inputRegex = /(^|[^`])`([^`]+)`(?!`)$/\n\n/**\n * Matches inline code while pasting.\n */\nexport const pasteRegex = /(^|[^`])`([^`]+)`(?!`)/g\n\n/**\n * This extension allows you to mark text as inline code.\n * @see https://tiptap.dev/api/marks/code\n */\nexport const Code = Mark.create<CodeOptions>({\n name: 'code',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n excludes: '_',\n\n code: true,\n\n exitable: true,\n\n parseHTML() {\n return [{ tag: 'code' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['code', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n markdownTokenName: 'codespan',\n\n parseMarkdown: (token, helpers) => {\n // Convert 'codespan' token to code mark\n // For codespan tokens, we use the raw text content, not tokens\n return helpers.applyMark('code', [{ type: 'text', text: token.text || '' }])\n },\n\n renderMarkdown: (node, h) => {\n if (!node.content) {\n return ''\n }\n\n return `\\`${h.renderChildren(node.content)}\\``\n },\n\n addCommands() {\n return {\n setCode:\n () =>\n ({ commands }) => {\n return commands.setMark(this.name)\n },\n toggleCode:\n () =>\n ({ commands }) => {\n return commands.toggleMark(this.name)\n },\n unsetCode:\n () =>\n ({ commands }) => {\n return commands.unsetMark(this.name)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-e': () => this.editor.commands.toggleCode(),\n }\n },\n\n addInputRules() {\n return [\n markInputRule({\n find: inputRegex,\n type: this.type,\n }),\n ]\n },\n\n addPasteRules() {\n return [\n markPasteRule({\n find: pasteRegex,\n type: this.type,\n }),\n ]\n },\n})\n","import { Code } from './code.js'\n\nexport * from './code.js'\n\nexport default Code\n"],"mappings":";AAAA,SAAS,MAAM,eAAe,eAAe,u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