Skip to content

Commit

Permalink
fix(code): more robust regex for text enclosed in backticks ueberdosi…
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan37 authored Nov 25, 2024
1 parent c106a39 commit f79c05e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-bags-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/extension-code": patch
---

Update inline code formatting for text enclosed in backticks
12 changes: 9 additions & 3 deletions packages/extension-code/src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /(?<!`)`([^`]+)`(?!`)/;

/**
* Matches inline code while pasting.
*/
export const pasteRegex = /(?:^|\s)(`(?!\s+`)((?:[^`]+))`(?!\s+`))/g
export const pasteRegex = /(?<!`)`([^`]+)`(?!`)/g;

/**
* This extension allows you to mark text as inline code.
Expand Down

0 comments on commit f79c05e

Please sign in to comment.