-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(extension-code): modify input and paste regular expression #7124
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
base: develop
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 5859c22 The changes in this PR will be included in the next version bump. This PR includes changesets to release 70 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@tiptap/extension-character-count
@tiptap/extension-gapcursor
@tiptap/extension-dropcursor
@tiptap/extension-focus
@tiptap/extension-list-item
@tiptap/extension-history
@tiptap/extension-list-keymap
@tiptap/extension-placeholder
@tiptap/extension-table-cell
@tiptap/extension-table-header
@tiptap/extension-task-item
@tiptap/extension-table-row
@tiptap/extension-task-list
@tiptap/extension-blockquote
@tiptap/core
@tiptap/extension-bold
@tiptap/extension-code
@tiptap/extension-bullet-list
@tiptap/extension-bubble-menu
@tiptap/extension-code-block-lowlight
@tiptap/extension-code-block
@tiptap/extension-collaboration
@tiptap/extension-color
@tiptap/extension-collaboration-caret
@tiptap/extension-details
@tiptap/extension-document
@tiptap/extension-drag-handle
@tiptap/extension-drag-handle-react
@tiptap/extension-drag-handle-vue-2
@tiptap/extension-drag-handle-vue-3
@tiptap/extension-emoji
@tiptap/extension-floating-menu
@tiptap/extension-file-handler
@tiptap/extension-font-family
@tiptap/extension-hard-break
@tiptap/extension-heading
@tiptap/extension-highlight
@tiptap/extension-horizontal-rule
@tiptap/extension-image
@tiptap/extension-italic
@tiptap/extension-invisible-characters
@tiptap/extension-link
@tiptap/extension-list
@tiptap/extension-mathematics
@tiptap/extension-mention
@tiptap/extension-node-range
@tiptap/extension-paragraph
@tiptap/extension-ordered-list
@tiptap/extension-strike
@tiptap/extension-subscript
@tiptap/extension-superscript
@tiptap/extension-table
@tiptap/extension-table-of-contents
@tiptap/extension-text
@tiptap/extension-text-align
@tiptap/extension-text-style
@tiptap/extension-typography
@tiptap/extension-underline
@tiptap/extension-unique-id
@tiptap/extension-youtube
@tiptap/extensions
@tiptap/html
@tiptap/markdown
@tiptap/react
@tiptap/pm
@tiptap/suggestion
@tiptap/starter-kit
@tiptap/vue-2
@tiptap/vue-3
@tiptap/static-renderer
commit: |
a7bbb2d to
054988c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug in the Code extension where typing a letter followed by backtick-enclosed text (e.g., ab``) would cause the preceding character to be consumed. The fix updates the input and paste regular expressions to match the pattern used consistently across other Mark extensions (Bold, Italic, Strike, Highlight).
Key changes:
- Modified regex patterns to require whitespace or start-of-line before backtick markers
- Added negative lookaheads to prevent matching when spaces surround backticks
- Aligned Code extension behavior with other Mark extensions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/extension-code/src/code.ts | Updated inputRegex and pasteRegex to use the standard Mark extension pattern `(?:^ |
| .changeset/ninety-humans-raise.md | Added changeset documenting the fix for inline code removing preceding characters |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| export const inputRegex = /(?:^|\s)(`(?!\s+`)((?:[^`]+))`(?!\s+`))$/ | ||
| /** | ||
| * Matches inline code while pasting. | ||
| */ | ||
| export const pasteRegex = /(^|[^`])`([^`]+)`(?!`)/g | ||
| export const pasteRegex = /(?:^|\s)(`(?!\s+`)((?:[^`]+))`(?!\s+`))/g |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updated regex patterns should have test coverage similar to the Bold extension. Consider adding a test file at packages/extension-code/__tests__/code.spec.ts to verify:
- The new regex correctly matches backtick-enclosed text when preceded by whitespace or at start of line
- The regex correctly rejects cases without proper whitespace (addressing the original bug where "a`b`" consumed the "a")
- Both
inputRegexandpasteRegexmatch expected patterns
Example test structure (following Bold extension's pattern):
import { inputRegex, pasteRegex } from '@tiptap/extension-code'
import { describe, expect, it } from 'vitest'
describe('code regex test', () => {
it('input regex matches code with space before', () => {
expect(' `Test`').toMatch(inputRegex)
})
it('input regex matches code at start', () => {
expect('`Test`').toMatch(inputRegex)
})
it('paste regex matches', () => {
expect('`Test`').toMatch(pasteRegex)
})
})|
What I wonder is if we can somehow fix this without requiring an additional whitespace before the inline code. |
Changes Overview
The Code extension had an issue where typing a`b` would cause the preceding character "a" to disappear.
This PR applies the same regular expression pattern used in other Mark extensions (Bold, Strike, Italic) to fix this behavior.
Implementation Approach
Updated the regular expressions for
inputRegexandpasteRegexin the Code extension to match the pattern used in other Mark extensions:The key changes:
(^|[^])to(?:^|\s)` - now requires whitespace or start of line instead of "not a backtick"(?!\s+)` lookaheads to prevent matching when there are spaces around backticksTesting Done
Tested manually in the
demos/environment using the extension-code demo by:Verification Steps
b)Additional Notes
AS-IS (Original behavior on https://tiptap.dev/ main page):
2025-10-25.2.23.13.mov
TO-BE (Fixed behavior):
2025-10-25.2.19.05.mov
This change aligns the Code extension's regex pattern with other Mark extensions in the codebase, ensuring consistent behavior across all inline formatting marks.
Checklist
Related Issues
Closes #7110