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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

marwan37
Copy link

@marwan37 marwan37 commented Sep 21, 2023

Please describe your changes

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.

How did you accomplish your changes

Updated the inputRegex and pasteRegex patterns to the following:

export const inputRegex = /(?<!`)`([^`]+)`(?!`)/;
export const pasteRegex = /(?<!`)`([^`]+)`(?!`)/g;

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.

How have you tested your changes

Tested in various scenarios to ensure that it correctly formats text as inline code blocks, and that it doesn't conflict with other extensions.

TipTap-LocalTest

How can we verify your changes

  1. Clone the repository and switch to the branch containing these changes.
  2. Start the app via npm run start and navigate to any playground
  3. Type text enclosed in backticks, with various surrounding characters.
  4. You should observe the text within the backticks being correctly formatted as inline code.
  5. Additionally, test with multiple backticks to ensure they don't interfere with the formatting.

Remarks

This change enhances the flexibility of the inline code formatting.

Checklist

  • The changes are not breaking the editor
  • Added tests where possible
  • Followed the guidelines
  • Fixed linting issues

Related issues

#4467
Issue #338 in BlockNote - Original issue where the bug was identified and discussed.

@netlify
Copy link

netlify bot commented Sep 21, 2023

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit e742738
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/650c8a2c4c081900083ea4b3
😎 Deploy Preview https://deploy-preview-4468--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@nperez0111 nperez0111 force-pushed the develop branch 2 times, most recently from bcaef5c to 7e7ae19 Compare June 12, 2024 04:33
@bdbch bdbch deleted the branch ueberdosis:develop June 26, 2024 21:57
@bdbch bdbch closed this Jun 26, 2024
@bdbch bdbch reopened this Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants