diff --git a/src/extensions/rich-text/rich-text-code.ts b/src/extensions/rich-text/rich-text-code.ts
index 3e5066a9..a6b36fee 100644
--- a/src/extensions/rich-text/rich-text-code.ts
+++ b/src/extensions/rich-text/rich-text-code.ts
@@ -1,3 +1,4 @@
+import { markInputRule, markPasteRule } from '@tiptap/core'
import { Code } from '@tiptap/extension-code'
import { CODE_EXTENSION_PRIORITY } from '../../constants/extension-priorities'
@@ -9,6 +10,18 @@ import type { CodeOptions } from '@tiptap/extension-code'
*/
type RichTextCodeOptions = CodeOptions
+/**
+ * The original input regex for Markdown inline code (i.e. `code
`) to prevent the issue
+ * introduced in this PR: https://github.com/ueberdosis/tiptap/pull/4468#issuecomment-2575093998
+ */
+const inputRegex = /(?:^|\s)(`(?!\s+`)((?:[^`]+))`(?!\s+`))$/
+
+/**
+ * The original paste regex for Markdown inline code (i.e. `code
`) to prevent the issue
+ * introduced in this PR: https://github.com/ueberdosis/tiptap/pull/4468#issuecomment-2575093998
+ */
+const pasteRegex = /(?:^|\s)(`(?!\s+`)((?:[^`]+))`(?!\s+`))/g
+
/**
* Custom extension that extends the built-in `Code` extension to allow all marks (e.g., Bold,
* Italic, and Strikethrough) to coexist with the `Code` mark (as opposed to disallowing all any
@@ -20,6 +33,22 @@ type RichTextCodeOptions = CodeOptions
const RichTextCode = Code.extend({
priority: CODE_EXTENSION_PRIORITY,
excludes: Code.name,
+ addInputRules() {
+ return [
+ markInputRule({
+ find: inputRegex,
+ type: this.type,
+ }),
+ ]
+ },
+ addPasteRules() {
+ return [
+ markPasteRule({
+ find: pasteRegex,
+ type: this.type,
+ }),
+ ]
+ },
})
export { RichTextCode }