Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inline code formatting for text enclosed in backticks #4468

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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