From fc5293602436ed42e7f69dd3689a196eb2032b81 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:36:12 +0530 Subject: [PATCH] fix: escape markdown content for images (#6096) --- .../core/extensions/custom-image/custom-image.ts | 13 +++---------- .../custom-image/read-only-custom-image.ts | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/packages/editor/src/core/extensions/custom-image/custom-image.ts b/packages/editor/src/core/extensions/custom-image/custom-image.ts index a232bb258a3..3b64db8d098 100644 --- a/packages/editor/src/core/extensions/custom-image/custom-image.ts +++ b/packages/editor/src/core/extensions/custom-image/custom-image.ts @@ -1,11 +1,9 @@ import { Editor, mergeAttributes } from "@tiptap/core"; import { Image } from "@tiptap/extension-image"; -import { MarkdownSerializerState } from "@tiptap/pm/markdown"; -import { Node } from "@tiptap/pm/model"; import { ReactNodeViewRenderer } from "@tiptap/react"; import { v4 as uuidv4 } from "uuid"; // extensions -import { CustomImageNode, ImageAttributes } from "@/extensions/custom-image"; +import { CustomImageNode } from "@/extensions/custom-image"; // plugins import { TrackImageDeletionPlugin, TrackImageRestorationPlugin, isFileValid } from "@/plugins/image"; // types @@ -126,14 +124,9 @@ export const CustomImageExtension = (props: TFileHandler) => { deletedImageSet: new Map(), uploadInProgress: false, maxFileSize, + // escape markdown for images markdown: { - serialize(state: MarkdownSerializerState, node: Node) { - const attrs = node.attrs as ImageAttributes; - const imageSource = state.esc(this?.editor?.commands?.getImageSource?.(attrs.src) || attrs.src); - const imageWidth = state.esc(attrs.width?.toString()); - state.write(``); - state.closeBlock(node); - }, + serialize() {}, }, }; }, diff --git a/packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts b/packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts index 3248329f033..c27970d9287 100644 --- a/packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts +++ b/packages/editor/src/core/extensions/custom-image/read-only-custom-image.ts @@ -1,10 +1,8 @@ import { mergeAttributes } from "@tiptap/core"; import { Image } from "@tiptap/extension-image"; -import { MarkdownSerializerState } from "@tiptap/pm/markdown"; -import { Node } from "@tiptap/pm/model"; import { ReactNodeViewRenderer } from "@tiptap/react"; // components -import { CustomImageNode, ImageAttributes, UploadImageExtensionStorage } from "@/extensions/custom-image"; +import { CustomImageNode, UploadImageExtensionStorage } from "@/extensions/custom-image"; // types import { TFileHandler } from "@/types"; @@ -54,14 +52,9 @@ export const CustomReadOnlyImageExtension = (props: Pick`); - state.closeBlock(node); - }, + serialize() {}, }, }; },