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

Bugfix/code block in parentheses #341

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

marwan37
Copy link

@marwan37 marwan37 commented Sep 20, 2023

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

@vercel
Copy link

vercel bot commented Sep 20, 2023

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
Copy link

vercel bot commented Sep 20, 2023

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

A member of the Team first needs to authorize it.

@matthewlipski
Copy link
Collaborator

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

@marwan37
Copy link
Author

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

@matthewlipski
Copy link
Collaborator

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

@marwan37
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code Block is not generated inside parentheses
2 participants