From 0155fa8efc379db2ab35f00a01a6b3e7d3d3da0b Mon Sep 17 00:00:00 2001 From: Jonas Date: Fri, 8 May 2026 21:19:12 +0200 Subject: [PATCH] fix(code): fix regex to not eat preceding character Fixes: #5483 This bug got introduced in upstream Tiptap with https://github.com/ueberdosis/tiptap/pull/5916, which removes named capturing groups and lookbehind assertions from the regex in order to fix support for Safari < 16.4. Upstream issue https://github.com/ueberdosis/tiptap/issues/6358 tracks this bug a ping some months back whether it would be an option to revert this change nowadays didn't get any reply. So let's overwrite the regexes on our side. Signed-off-by: Jonas --- playwright/e2e/input-rules.spec.ts | 20 +++++++++++++++++++ src/marks/Code.ts | 31 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 playwright/e2e/input-rules.spec.ts diff --git a/playwright/e2e/input-rules.spec.ts b/playwright/e2e/input-rules.spec.ts new file mode 100644 index 00000000000..3cebc251bbc --- /dev/null +++ b/playwright/e2e/input-rules.spec.ts @@ -0,0 +1,20 @@ +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { expect, mergeTests } from '@playwright/test' +import { test as editorTest } from '../support/fixtures/editor' +import { test as uploadFileTest } from '../support/fixtures/upload-file' + +const test = mergeTests(editorTest, uploadFileTest) + +test('applies code mark input rule with preceding character (#5483)', async ({ + editor, + open, +}) => { + await open() + await editor.type('hello inline (`code`)') + await expect(editor.el.locator('code')).toHaveText('code') + await expect(editor.el.locator('p').first()).toHaveText('hello inline (code)') +}) diff --git a/src/marks/Code.ts b/src/marks/Code.ts index 58c85b33651..d54e4bf5cb6 100644 --- a/src/marks/Code.ts +++ b/src/marks/Code.ts @@ -3,11 +3,42 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { markInputRule, markPasteRule } from '@tiptap/core' import TipTapCode from '@tiptap/extension-code' +/** + * Regular expressions to match inline code blocks enclosed in backticks. + * Reverts upstream PR https://github.com/ueberdosis/tiptap/pull/5916 which + * introduced isuee https://github.com/nextcloud/text/issues/5483. + */ +export const inputRegex = /(?