fix(web): paste markdown with inline code inside bold, italic, or strikethrough (#12290)
This commit is contained in:
1 parent
f7efb5354a
commit
dca84efb53
5 files changed
+25
-1
No files matched your search
@@ -32,6 +32,7 @@
|
||||
"@tanstack/react-pacer": "^0.19.4",
|
||||
"@tanstack/react-router": "^1.160.2",
|
||||
"@tiptap/core": "^3.31.3",
|
||||
"@tiptap/extension-code": "^3.31.3",
|
||||
"@tiptap/extension-task-item": "^3.31.3",
|
||||
"@tiptap/extension-task-list": "^3.31.3",
|
||||
"@tiptap/pm": "^3.31.3",
|
||||
|
||||
@@ -46,6 +46,7 @@ import {
|
||||
buildDocJson,
|
||||
buildTiptapContent,
|
||||
collapsedToFlat,
|
||||
ComposerCodeExtension,
|
||||
ComposerTaskItemExtension,
|
||||
flatToCollapsed,
|
||||
flatToMarkdown,
|
||||
@@ -754,8 +755,9 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
|
||||
dropcursor: false,
|
||||
gapcursor: false,
|
||||
trailingNode: false,
|
||||
code: false,
|
||||
// Plain mode has no marks: typed markers stay literal characters.
|
||||
...(richText ? {} : { bold: false, italic: false, strike: false, code: false }),
|
||||
...(richText ? {} : { bold: false, italic: false, strike: false }),
|
||||
}),
|
||||
ComposerMentionExtension,
|
||||
ComposerSkillExtension,
|
||||
@@ -764,6 +766,7 @@ function ComposerPromptEditorTiptapInner(props: ComposerPromptEditorProps) {
|
||||
ComposerMarkersExtension,
|
||||
...(richText
|
||||
? [
|
||||
ComposerCodeExtension,
|
||||
TaskList,
|
||||
ComposerTaskItemExtension.extend({
|
||||
addInputRules() {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { describe, expect, it } from "vite-plus/test";
|
||||
import {
|
||||
buildDocJson,
|
||||
collapsedToFlat,
|
||||
ComposerCodeExtension,
|
||||
ComposerTaskItemExtension,
|
||||
flatToCollapsed,
|
||||
flatToMarkdown,
|
||||
@@ -38,7 +39,9 @@ const schema = getSchemaByResolvedExtensions(
|
||||
dropcursor: false,
|
||||
gapcursor: false,
|
||||
trailingNode: false,
|
||||
code: false,
|
||||
}),
|
||||
ComposerCodeExtension,
|
||||
stubAtom("composer-mention", { path: { default: "" }, source: { default: "" } }),
|
||||
stubAtom("composer-skill", {
|
||||
skillName: { default: "" },
|
||||
@@ -64,6 +67,8 @@ const schema = getSchemaByResolvedExtensions(
|
||||
function roundTrip(value: string) {
|
||||
const json = buildDocJson(value, (name) => ({ label: name, description: null }));
|
||||
const doc = ProseMirrorNode.fromJSON(schema, json);
|
||||
// `insertContent` validates every node against the schema; `fromJSON` does not.
|
||||
doc.check();
|
||||
return serializeEditorDoc(doc);
|
||||
}
|
||||
|
||||
@@ -135,6 +140,10 @@ describe("composer rich text document model", () => {
|
||||
"hello **bold** world",
|
||||
"a *italic* word and `code` here",
|
||||
"struck ~~out~~ now",
|
||||
"**`x`**",
|
||||
"*`x`*",
|
||||
"~~`x`~~",
|
||||
"**a `code` c**",
|
||||
"***bold italic*** keeps nesting",
|
||||
"line one\nline two",
|
||||
"trailing newline\n",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Node as ProseMirrorNode } from "@tiptap/pm/model";
|
||||
import { Code } from "@tiptap/extension-code";
|
||||
import { TaskItem } from "@tiptap/extension-task-item";
|
||||
|
||||
import { splitPromptIntoComposerSegments } from "~/composer-editor-mentions";
|
||||
@@ -41,6 +42,13 @@ const TIPTAP_TO_MARK: Record<string, RichTextMark> = {
|
||||
code: "code",
|
||||
};
|
||||
|
||||
/**
|
||||
* Tiptap's code mark excludes every other mark, which rejects the `bold+code`
|
||||
* spans markdown like `**\`x\`**` parses into and drops the whole insert.
|
||||
* Code nests inside emphasis here, so it only excludes itself like the rest.
|
||||
*/
|
||||
export const ComposerCodeExtension = Code.extend({ excludes: "code" });
|
||||
|
||||
/**
|
||||
* Task list items keep their exact source indent in an attribute so nesting
|
||||
* round-trips byte-identically. Checkbox case (`[X]`) normalizes to `[x]` —
|
||||
|
||||
Generated
+3
@@ -637,6 +637,9 @@ importers:
|
||||
'@tiptap/core':
|
||||
specifier: ^3.31.3
|
||||
version: 3.31.3(@tiptap/[email protected])
|
||||
'@tiptap/extension-code':
|
||||
specifier: ^3.31.3
|
||||
version: 3.31.3(@tiptap/[email protected](@tiptap/[email protected]))
|
||||
'@tiptap/extension-task-item':
|
||||
specifier: ^3.31.3
|
||||
version: 3.31.3(@tiptap/[email protected](@tiptap/[email protected](@tiptap/[email protected]))(@tiptap/[email protected]))
|
||||
|
||||
Reference in new issue
Block a user