Skip to content

Commit 9c150de

Browse files
committed
fix(web): paste markdown with inline code inside bold, italic, or strikethrough
Tiptap's code mark declares excludes: "_", so the bold+code, italic+code, and strike+code spans that markdown like **`x`** parses into fail node.check() inside insertContent. The paste handler had already called preventDefault, so nothing was inserted and no error surfaced. The composer's code mark now only excludes itself, matching the other marks and the serializer, which already emits **`x`** for bold+code. The round-trip tests now run doc.check() so schema-invalid mark sets fail the way insertContent does. Fixes #12247
1 parent 4749035 commit 9c150de

5 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎apps/web/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@tanstack/react-pacer": "^0.19.4",
3333
"@tanstack/react-router": "^1.160.2",
3434
"@tiptap/core": "^3.31.3",
35+
"@tiptap/extension-code": "^3.31.3",
3536
"@tiptap/extension-task-item": "^3.31.3",
3637
"@tiptap/extension-task-list": "^3.31.3",
3738
"@tiptap/pm": "^3.31.3",

‎apps/web/src/components/ComposerPromptEditorTiptap.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
buildDocJson,
4747
buildTiptapContent,
4848
collapsedToFlat,
49+
ComposerCodeExtension,
4950
ComposerTaskItemExtension,
5051
flatToCollapsed,
5152
flatToMarkdown,
@@ -741,8 +742,9 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
741742
dropcursor: false,
742743
gapcursor: false,
743744
trailingNode: false,
745+
code: false,
744746
// Plain mode has no marks: typed markers stay literal characters.
745-
...(richText ? {} : { bold: false, italic: false, strike: false, code: false }),
747+
...(richText ? {} : { bold: false, italic: false, strike: false }),
746748
}),
747749
ComposerMentionExtension,
748750
ComposerSkillExtension,
@@ -751,6 +753,7 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
751753
ComposerMarkersExtension,
752754
...(richText
753755
? [
756+
ComposerCodeExtension,
754757
TaskList,
755758
ComposerTaskItemExtension.extend({
756759
addInputRules() {

‎apps/web/src/composer-rich-text-doc.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { describe, expect, it } from "vite-plus/test";
77
import {
88
buildDocJson,
99
collapsedToFlat,
10+
ComposerCodeExtension,
1011
ComposerTaskItemExtension,
1112
flatToCollapsed,
1213
flatToMarkdown,
@@ -38,7 +39,9 @@ const schema = getSchemaByResolvedExtensions(
3839
dropcursor: false,
3940
gapcursor: false,
4041
trailingNode: false,
42+
code: false,
4143
}),
44+
ComposerCodeExtension,
4245
stubAtom("composer-mention", { path: { default: "" }, source: { default: "" } }),
4346
stubAtom("composer-skill", {
4447
skillName: { default: "" },
@@ -64,6 +67,8 @@ const schema = getSchemaByResolvedExtensions(
6467
function roundTrip(value: string) {
6568
const json = buildDocJson(value, (name) => ({ label: name, description: null }));
6669
const doc = ProseMirrorNode.fromJSON(schema, json);
70+
// `insertContent` validates every node against the schema; `fromJSON` does not.
71+
doc.check();
6772
return serializeEditorDoc(doc);
6873
}
6974

@@ -135,6 +140,10 @@ describe("composer rich text document model", () => {
135140
"hello **bold** world",
136141
"a *italic* word and `code` here",
137142
"struck ~~out~~ now",
143+
"**`x`**",
144+
"*`x`*",
145+
"~~`x`~~",
146+
"**a `code` c**",
138147
"***bold italic*** keeps nesting",
139148
"line one\nline two",
140149
"trailing newline\n",

‎apps/web/src/composer-rich-text-doc.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Node as ProseMirrorNode } from "@tiptap/pm/model";
2+
import { Code } from "@tiptap/extension-code";
23
import { TaskItem } from "@tiptap/extension-task-item";
34

45
import { splitPromptIntoComposerSegments } from "~/composer-editor-mentions";
@@ -41,6 +42,13 @@ const TIPTAP_TO_MARK: Record<string, RichTextMark> = {
4142
code: "code",
4243
};
4344

45+
/**
46+
* Tiptap's code mark excludes every other mark, which rejects the `bold+code`
47+
* spans markdown like `**\`x\`**` parses into and drops the whole insert.
48+
* Code nests inside emphasis here, so it only excludes itself like the rest.
49+
*/
50+
export const ComposerCodeExtension = Code.extend({ excludes: "code" });
51+
4452
/**
4553
* Task list items keep their exact source indent in an attribute so nesting
4654
* round-trips byte-identically. Checkbox case (`[X]`) normalizes to `[x]` —

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)