fix(code): more robust regex for text enclosed in backticks #4487 (#4468)

This commit is contained in:
Marwan Zaarab 2024-11-25 09:30:46 -06:00 committed by GitHub
parent c106a39887
commit f79c05edd4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
"@tiptap/extension-code": patch
---
Update inline code formatting for text enclosed in backticks

View File

@ -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.