Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions playwright/e2e/input-rules.spec.ts
Original file line number Diff line number Diff line change
@@ -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)')
})
31 changes: 31 additions & 0 deletions src/marks/Code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /(?<!`)`([^`]+)`(?!`)/

/**
* Matches inline code while pasting.
*/
export const pasteRegex = /(?<!`)`([^`]+)`(?!`)/g

const Code = TipTapCode.extend({
// List all enabled marks except 'code' and 'link' (issue #4900)
excludes: 'em strike strong underline',

addInputRules() {
return [
markInputRule({
find: inputRegex,
type: this.type,
}),
]
},

addPasteRules() {
return [
markPasteRule({
find: pasteRegex,
type: this.type,
}),
]
},
})

export default Code
Loading