From 3a6ea817374dde64e4efc91c4446da2a7247a782 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sun, 8 Mar 2026 23:16:58 +0100 Subject: [PATCH] fix(links): allow inline code within links The Tiptap inline code mark extension excludes all other mark types from coexisting with itself. This makes sense for most mark types, but link is an exception. Unfortunately there's no way to dynamically create a list of all marks when `excludes` is initialized, as this happens when compiling the editor schema, so the latter is not available yet. Thus to fix the bug while keeping the side effects small, we have to explicitely list all mark types except link and code in `excludes` in the code mark definition. Fixes: #4900 Signed-off-by: Jonas --- src/extensions/RichText.js | 2 +- src/marks/Code.ts | 13 +++++++++++++ src/marks/index.js | 3 ++- src/tests/markdown.spec.js | 5 +++++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/marks/Code.ts diff --git a/src/extensions/RichText.js b/src/extensions/RichText.js index 4a1501bbf39..41abb85886c 100644 --- a/src/extensions/RichText.js +++ b/src/extensions/RichText.js @@ -7,7 +7,6 @@ import { t } from '@nextcloud/l10n' import { Extension } from '@tiptap/core' /* eslint-disable import/no-named-as-default */ import Blockquote from '@tiptap/extension-blockquote' -import Code from '@tiptap/extension-code' import Document from '@tiptap/extension-document' import HorizontalRule from '@tiptap/extension-horizontal-rule' import { ListItem } from '@tiptap/extension-list' @@ -27,6 +26,7 @@ import Search from './../extensions/Search.ts' import TextDirection from './../extensions/TextDirection.ts' import Typography from './../extensions/Typography.ts' import { + Code, Highlight, Italic, Link, diff --git a/src/marks/Code.ts b/src/marks/Code.ts new file mode 100644 index 00000000000..58c85b33651 --- /dev/null +++ b/src/marks/Code.ts @@ -0,0 +1,13 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import TipTapCode from '@tiptap/extension-code' + +const Code = TipTapCode.extend({ + // List all enabled marks except 'code' and 'link' (issue #4900) + excludes: 'em strike strong underline', +}) + +export default Code diff --git a/src/marks/index.js b/src/marks/index.js index 54f2ef06364..306cbdd68d0 100644 --- a/src/marks/index.js +++ b/src/marks/index.js @@ -4,6 +4,7 @@ */ import TipTapItalic from '@tiptap/extension-italic' +import Code from './Code.ts' import Highlight from './Highlight.ts' import Link from './Link.ts' import Strike from './Strike.js' @@ -14,4 +15,4 @@ const Italic = TipTapItalic.extend({ name: 'em', }) -export { Highlight, Italic, Link, Strike, Strong, Underline } +export { Code, Highlight, Italic, Link, Strike, Strong, Underline } diff --git a/src/tests/markdown.spec.js b/src/tests/markdown.spec.js index 615a4738eec..6d8840503c9 100644 --- a/src/tests/markdown.spec.js +++ b/src/tests/markdown.spec.js @@ -69,6 +69,11 @@ describe('Markdown though editor', () => { expect(markdownThroughEditor('[bar\\\\]: /uri\n\n[bar\\\\]')).toBe( '[bar\\\\](/uri)', ) + // Issue #4900 + expect(markdownThroughEditor('[`code`](foo)')).toBe('[`code`](foo)') + expect(markdownThroughEditor('[text with `code` inside](foo)')).toBe( + '[text with `code` inside](foo)', + ) }) test('images', () => { // Inline images