Skip to content

Prevent inline math input rule from replacing previous character#7481

Open
n-siddarth wants to merge 3 commits intoueberdosis:mainfrom
n-siddarth:n-siddarth/fix-inline-math-input-rule
Open

Prevent inline math input rule from replacing previous character#7481
n-siddarth wants to merge 3 commits intoueberdosis:mainfrom
n-siddarth:n-siddarth/fix-inline-math-input-rule

Conversation

@n-siddarth
Copy link

@n-siddarth n-siddarth commented Jan 31, 2026

Changes Overview

Changed the InlineMath extension's input rule to prevent it from consuming the preceding character to a $$latex$$ expression.

For example, the string Hello $$\sigma$$ would be transformed into → Helloσ (with the space deleted).

Implementation Approach

We can utilize a fixed-width negative lookbehind that validates the preceding character is not a $-sign. This mimics the negative lookahead that's used at the end of the regular expression.

Testing Done

Change is small enough to not require tests.

Verification Steps

Build the editor. Utilize the mathematics extension and verify that $$somelatex$$ does not replace the preceding character.

Additional Notes

Checklist

  • I have created a changeset for this PR if necessary
  • My changes do not break the library.
  • I have added tests where applicable: (N/A here)
  • I have followed the project guidelines.
  • I have fixed any lint issues.

Related Issues

Copilot AI review requested due to automatic review settings January 31, 2026 17:14
@changeset-bot
Copy link

changeset-bot bot commented Jan 31, 2026

🦋 Changeset detected

Latest commit: 3d3962f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 72 packages
Name Type
@tiptap/extension-mathematics Major
@tiptap/core Major
@tiptap/extension-audio Major
@tiptap/extension-blockquote Major
@tiptap/extension-bold Major
@tiptap/extension-bubble-menu Major
@tiptap/extension-bullet-list Major
@tiptap/extension-code-block-lowlight Major
@tiptap/extension-code-block Major
@tiptap/extension-code Major
@tiptap/extension-collaboration-caret Major
@tiptap/extension-collaboration Major
@tiptap/extension-color Major
@tiptap/extension-details Major
@tiptap/extension-document Major
@tiptap/extension-drag-handle-react Major
@tiptap/extension-drag-handle-vue-2 Major
@tiptap/extension-drag-handle-vue-3 Major
@tiptap/extension-drag-handle Major
@tiptap/extension-emoji Major
@tiptap/extension-file-handler Major
@tiptap/extension-floating-menu Major
@tiptap/extension-font-family Major
@tiptap/extension-hard-break Major
@tiptap/extension-heading Major
@tiptap/extension-highlight Major
@tiptap/extension-horizontal-rule Major
@tiptap/extension-image Major
@tiptap/extension-invisible-characters Major
@tiptap/extension-italic Major
@tiptap/extension-link Major
@tiptap/extension-list Major
@tiptap/extension-mention Major
@tiptap/extension-node-range Major
@tiptap/extension-ordered-list Major
@tiptap/extension-paragraph Major
@tiptap/extension-strike Major
@tiptap/extension-subscript Major
@tiptap/extension-superscript Major
@tiptap/extension-table-of-contents Major
@tiptap/extension-table Major
@tiptap/extension-text-align Major
@tiptap/extension-text-style Major
@tiptap/extension-text Major
@tiptap/extension-twitch Major
@tiptap/extension-typography Major
@tiptap/extension-underline Major
@tiptap/extension-unique-id Major
@tiptap/extension-youtube Major
@tiptap/extensions Major
@tiptap/html Major
@tiptap/markdown Major
@tiptap/pm Major
@tiptap/react Major
@tiptap/starter-kit Major
@tiptap/static-renderer Major
@tiptap/suggestion Major
@tiptap/vue-2 Major
@tiptap/vue-3 Major
@tiptap/extension-character-count Major
@tiptap/extension-dropcursor Major
@tiptap/extension-focus Major
@tiptap/extension-gapcursor Major
@tiptap/extension-history Major
@tiptap/extension-list-item Major
@tiptap/extension-list-keymap Major
@tiptap/extension-placeholder Major
@tiptap/extension-table-cell Major
@tiptap/extension-table-header Major
@tiptap/extension-table-row Major
@tiptap/extension-task-item Major
@tiptap/extension-task-list Major

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

@netlify
Copy link

netlify bot commented Jan 31, 2026

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 3d3962f
🔍 Latest deploy log https://app.netlify.com/projects/tiptap-embed/deploys/697e3996f5cf9200085b6c14
😎 Deploy Preview https://deploy-preview-7481--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 project configuration.

Copy link
Contributor

Copilot AI left a 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 InlineMath extension where the input rule for $$latex$$ syntax was consuming the character immediately before the opening $$. The fix changes the regular expression from using a capturing group (^|[^$]) to a negative lookbehind assertion (?<!$).

Changes:

  • Modified the InlineMath input rule regex to use negative lookbehind instead of a capturing group
  • Added a changeset documenting the fix

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/extension-mathematics/src/extensions/InlineMath.ts Updated regex pattern in addInputRules() from capturing group to negative lookbehind
.changeset/yellow-bags-pump.md Added changeset for the bug fix with minor version bump
Comments suppressed due to low confidence (1)

packages/extension-mathematics/src/extensions/InlineMath.ts:233

  • This bug fix changes user-visible behavior and should include a test to prevent regression. Other extensions in this codebase have unit tests (e.g., packages/extension-bold/__tests__/bold.spec.ts). Consider adding a test that verifies the input rule correctly matches $$latex$$ without consuming the preceding character, for example by testing that Hello $$\sigma$$ produces the expected result with proper spacing preserved.
      new InputRule({
        find: /(?<!$)(\$\$([^$\n]+?)\$\$)(?!\$)/,
        handler: ({ state, range, match }) => {
          const latex = match[3]
          const { tr } = state
          const start = range.from
          const end = range.to

          tr.replaceWith(start, end, this.type.create({ latex }))
        },
      }),
    ]

n-siddarth and others added 2 commits January 31, 2026 12:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@bdbch
Copy link
Member

bdbch commented Mar 6, 2026

Is there a related issue for this?

@bdbch
Copy link
Member

bdbch commented Mar 6, 2026

One thing that worries me is a negative lookup. While Safari catched up and supports them since 2023 I wonder if we should keep this information on the docs. Not sure though.

@n-siddarth
Copy link
Author

Is there a related issue for this?

Sorry, I did not create one due to the simplicity of the change. Would you like me to create a corresponding issue?

@n-siddarth
Copy link
Author

One thing that worries me is a negative lookup. While Safari catched up and supports them since 2023 I wonder if we should keep this information on the docs. Not sure though.

Hmm, good point. We of course do not need to use negative lookbehinds. We could capture the previous character and insert content that re-adds the character in a generic InputRule. Is this approach better?

@bdbch bdbch changed the base branch from develop to main March 14, 2026 15:04
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.

3 participants