Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: add `src` to image on copy

Abdullah Attaa5c44dcb3b63
diff --git a/packages/editor/src/extensions/clipboard-text-serializer/index.ts b/packages/editor/src/extensions/clipboard-text-serializer/index.ts
index 325ea29c2..b5d2c1802 100644
--- a/packages/editor/src/extensions/clipboard-text-serializer/index.ts
+++ b/packages/editor/src/extensions/clipboard-text-serializer/index.ts
@@ -30,10 +30,7 @@ export const ClipboardTextSerializer = Extension.create({
key: new PluginKey("clipboardTextSerializer"),
props: {
clipboardTextSerializer: (content) => {
- const {
- editor: { schema }
- } = this;
- return getTextBetween(content, schema);
+ return getTextBetween(content, this.editor.schema);
}
}
})
diff --git a/packages/editor/src/extensions/image/image.ts b/packages/editor/src/extensions/image/image.ts
index f2e5f46d9..0af9f1182 100644
--- a/packages/editor/src/extensions/image/image.ts
+++ b/packages/editor/src/extensions/image/image.ts
@@ -23,12 +23,16 @@ import {
mergeAttributes,
findChildren
} from "@tiptap/core";
+import { Attrs } from "@tiptap/pm/model";
+import { Plugin } from "@tiptap/pm/state";
import { hasSameAttributes } from "../../utils/prosemirror";
import { Attachment, getDataAttribute } from "../attachment";
import { createSelectionBasedNodeView } from "../react";
import { TextDirections } from "../text-direction";
import { ImageComponent } from "./component";
+type Writeable<T> = { -readonly [P in keyof T]: T[P] };
+
export interface ImageOptions {
inline: boolean;
allowBase64: boolean;
@@ -178,6 +182,28 @@ export const ImageNode = Node.create<ImageOptions>({
});
},
+ addProseMirrorPlugins() {
+ return [
+ new Plugin({
+ props: {
+ transformCopied: (content) => {
+ content.content.descendants((node) => {
+ if (
+ node.type.name === this.name &&
+ typeof node.attrs.dataurl === "string"
+ ) {
+ const attrs = node.attrs as Writeable<Attrs>;
+ attrs.src = attrs.dataurl;
+ delete attrs.dataurl;
+ }
+ });
+ return content;
+ }
+ }
+ })
+ ];
+ },
+
addCommands() {
return {
insertImage: