From f79c05edd40a43531752e90db9ce9f814d124272 Mon Sep 17 00:00:00 2001 From: Marwan Zaarab <99911676+marwan37@users.noreply.github.com> Date: Mon, 25 Nov 2024 09:30:46 -0600 Subject: [PATCH] fix(code): more robust regex for text enclosed in backticks #4487 (#4468) --- .changeset/famous-bags-breathe.md | 5 +++++ packages/extension-code/src/code.ts | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 .changeset/famous-bags-breathe.md diff --git a/.changeset/famous-bags-breathe.md b/.changeset/famous-bags-breathe.md new file mode 100644 index 000000000..597fac775 --- /dev/null +++ b/.changeset/famous-bags-breathe.md @@ -0,0 +1,5 @@ +--- +"@tiptap/extension-code": patch +--- + +Update inline code formatting for text enclosed in backticks diff --git a/packages/extension-code/src/code.ts b/packages/extension-code/src/code.ts index 068804b51..642765ba3 100644 --- a/packages/extension-code/src/code.ts +++ b/packages/extension-code/src/code.ts @@ -34,14 +34,20 @@ declare module '@tiptap/core' { } /** - * Matches inline code. + * 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. + * This ensures that any text between backticks is formatted as code, + * regardless of the surrounding characters (exception being another backtick). */ -export const inputRegex = /(?:^|\s)(`(?!\s+`)((?:[^`]+))`(?!\s+`))$/ +export const inputRegex = /(?