diff --git a/.changeset/fix-update-block-math-empty-latex.md b/.changeset/fix-update-block-math-empty-latex.md new file mode 100644 index 0000000000..ddc01e315d --- /dev/null +++ b/.changeset/fix-update-block-math-empty-latex.md @@ -0,0 +1,5 @@ +--- +"@tiptap/extension-mathematics": patch +--- + +Fix `updateBlockMath` silently ignoring `latex: ''`. The command used a falsy fallback (`latex || node.attrs.latex`) that treated an explicit empty string the same as `undefined`, leaving the node unchanged. It now uses `latex ?? node.attrs.latex`, so callers can clear the rendered LaTeX with an empty string. diff --git a/.github/workflows/notify.yml b/.github/workflows/notify.yml index 6162e6e4cb..55d04ea1a7 100644 --- a/.github/workflows/notify.yml +++ b/.github/workflows/notify.yml @@ -28,7 +28,7 @@ jobs: permissions: {} steps: - name: Send Slack release notification - uses: slackapi/slack-github-action@v3.0.1 + uses: slackapi/slack-github-action@v3.0.3 with: webhook: ${{ secrets.SLACK_WEBHOOK_URL }} webhook-type: webhook-trigger diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index dbe15e64bb..79c0835710 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -147,7 +147,7 @@ jobs: steps: - name: Send Slack notification - uses: slackapi/slack-github-action@v3.0.1 + uses: slackapi/slack-github-action@v3.0.3 with: webhook: ${{ secrets.SLACK_WEBHOOK_URL }} webhook-type: webhook-trigger @@ -168,7 +168,7 @@ jobs: steps: - name: Send Slack failure notification - uses: slackapi/slack-github-action@v3.0.1 + uses: slackapi/slack-github-action@v3.0.3 with: webhook: ${{ secrets.SLACK_WEBHOOK_URL }} webhook-type: webhook-trigger diff --git a/packages/extension-mathematics/__tests__/blockMath.spec.ts b/packages/extension-mathematics/__tests__/blockMath.spec.ts index 2621bc0af1..2bb5a83566 100644 --- a/packages/extension-mathematics/__tests__/blockMath.spec.ts +++ b/packages/extension-mathematics/__tests__/blockMath.spec.ts @@ -5,7 +5,7 @@ import Paragraph from '@tiptap/extension-paragraph' import Text from '@tiptap/extension-text' import { afterEach, describe, expect, it } from 'vitest' -import { BlockMath } from '../src/index.js' +import { BlockMath, InlineMath } from '../src/index.js' describe('BlockMath', () => { let editor: Editor @@ -99,4 +99,50 @@ describe('BlockMath', () => { }) }) }) + + describe('updateBlockMath', () => { + function createEditor(latex: string) { + return new Editor({ + extensions: [Document, Paragraph, Text, BlockMath], + content: { + type: 'doc', + content: [{ type: 'blockMath', attrs: { latex } }], + }, + }) + } + + it('clears the latex attribute when given an empty string', () => { + editor = createEditor('x^2') + + editor.commands.updateBlockMath({ latex: '', pos: 0 }) + + expect(editor.state.doc.firstChild?.attrs.latex).toBe('') + }) + + it('matches updateInlineMath behavior when clearing latex with an empty string', () => { + const blockEditor = createEditor('x^2') + blockEditor.commands.updateBlockMath({ latex: '', pos: 0 }) + const blockEmpty = blockEditor.state.doc.firstChild?.attrs.latex + blockEditor.destroy() + + const inlineEditor = new Editor({ + extensions: [Document, Paragraph, Text, InlineMath], + content: { + type: 'doc', + content: [ + { + type: 'paragraph', + content: [{ type: 'inlineMath', attrs: { latex: 'x^2' } }], + }, + ], + }, + }) + const inlinePos = 1 + inlineEditor.commands.updateInlineMath({ latex: '', pos: inlinePos }) + const inlineEmpty = inlineEditor.state.doc.nodeAt(inlinePos)?.attrs.latex + inlineEditor.destroy() + + expect(blockEmpty).toBe(inlineEmpty) + }) + }) }) diff --git a/packages/extension-mathematics/src/extensions/BlockMath.ts b/packages/extension-mathematics/src/extensions/BlockMath.ts index bc10017708..3da6bccde2 100644 --- a/packages/extension-mathematics/src/extensions/BlockMath.ts +++ b/packages/extension-mathematics/src/extensions/BlockMath.ts @@ -157,7 +157,7 @@ export const BlockMath = Node.create({ tr.setNodeMarkup(pos, this.type, { ...node.attrs, - latex: latex || node.attrs.latex, + latex: latex ?? node.attrs.latex, }) return true