BlockNote icon indicating copy to clipboard operation
BlockNote copied to clipboard

Bugfix/code block in parentheses

Open marwan37 opened this issue 2 years ago • 6 comments

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.ts file from TipTap's extension and updated the inputRegex and pasteRegex patterns (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.
BlockNoteCustomCode

marwan37 avatar Sep 20 '23 13:09 marwan37

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

vercel[bot] avatar Sep 20 '23 13:09 vercel[bot]

@marwan37 is attempting to deploy a commit to the TypeCell Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Sep 20 '23 13:09 vercel[bot]

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 avatar Sep 21 '23 17:09 matthewlipski

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

marwan37 avatar Sep 21 '23 17:09 marwan37

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 avatar Sep 21 '23 19:09 matthewlipski

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

marwan37 avatar Sep 21 '23 19:09 marwan37