Bugfix/code block in parentheses
Description
In the current implementation of the @tiptap/extension-code, the regex pattern does not correctly format text enclosed in backticks when they are immediately preceded or followed by any character other than whitespace.
fixes: #338
Changes
- Created a new folder and file at:
packages/code/extensions/CustomCode/CustomCodeExtension.ts. - Copied the
code.tsfile from TipTap's extension and updated theinputRegexandpasteRegexpatterns (see below) - The regex uses negative lookbehind and lookahead assertions to ensure that only single backticks are considered for formatting to avoid conflicts with potential code block syntax or other uses of multiple backticks.
export const inputRegex = /(?<!`)`([^`]+)`(?!`)/;
export const pasteRegex = /(?<!`)`([^`]+)`(?!`)/g;
Testing
- The updated regex pattern has been tested in various scenarios to ensure that it correctly formats text as inline code blocks.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Updated (UTC) |
|---|---|---|---|
| blocknote | ✅ Ready (Inspect) | Visit Preview | Sep 20, 2023 1:59pm |
@marwan37 is attempting to deploy a commit to the TypeCell Team on Vercel.
A member of the Team first needs to authorize it.
Nice find! Though if this is an issue in TipTap's code base, wouldn't it be better to make a PR in their repo? It seems like a pretty major workaround to pretty much copy a file from TipTap to BlockNote, when the change could be made directly at the source of the issue
@matthewlipski You're absolutely right. My initial approach was to provide a quick fix for BlockNote users, but I understand the concerns about maintaining a separate copy of the file. I'll look into submitting a PR to TipTap directly.
Awesome, let me know how it goes - if for some reason the TipTap guys don't approve the changes, we can sort out a fix in BlockNote
@matthewlipski Thanks for the guidance! I've submitted a PR to the TipTap repo addressing the issue here. I'll keep you posted on its progress.