Skip to content

Commit 6b85d67

Browse files
authored
[WIKI-788] regression: copy markdown option #8200
1 parent 123f59e commit 6b85d67

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

packages/editor/src/core/helpers/editor-ref.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@ import type { HocuspocusProvider } from "@hocuspocus/provider";
22
import type { Editor } from "@tiptap/core";
33
import { DOMSerializer } from "@tiptap/pm/model";
44
import * as Y from "yjs";
5+
// plane imports
6+
import { convertHTMLToMarkdown } from "@plane/utils";
57
// components
68
import { getEditorMenuItems } from "@/components/menus";
79
// constants
810
import { CORE_EXTENSIONS } from "@/constants/extension";
911
import { CORE_EDITOR_META } from "@/constants/meta";
1012
// types
11-
import type { EditorRefApi, TEditorCommands } from "@/types";
13+
import type { EditorRefApi, IEditorProps, TEditorCommands } from "@/types";
1214
// local imports
1315
import { getParagraphCount } from "./common";
1416
import { insertContentAtSavedSelection } from "./insert-content-at-cursor-position";
1517
import { scrollSummary, scrollToNodeViaDOMCoordinates } from "./scroll-to-node";
1618

17-
type TArgs = {
19+
type TArgs = Pick<IEditorProps, "getEditorMetaData"> & {
1820
editor: Editor | null;
1921
provider: HocuspocusProvider | undefined;
2022
};
2123

2224
export const getEditorRefHelpers = (args: TArgs): EditorRefApi => {
23-
const { editor, provider } = args;
25+
const { editor, getEditorMetaData, provider } = args;
2426

2527
return {
2628
blur: () => editor?.commands.blur(),
@@ -77,8 +79,15 @@ export const getEditorRefHelpers = (args: TArgs): EditorRefApi => {
7779
}),
7880
getHeadings: () => (editor ? editor.storage.headingsList?.headings : []),
7981
getMarkDown: () => {
80-
const markdownOutput = editor?.storage?.markdown?.getMarkdown?.() ?? "";
81-
return markdownOutput;
82+
if (!editor) return "";
83+
const editorHTML = editor.getHTML();
84+
const metaData = getEditorMetaData(editorHTML);
85+
// convert to markdown
86+
const markdown = convertHTMLToMarkdown({
87+
description_html: editorHTML,
88+
metaData,
89+
});
90+
return markdown;
8291
},
8392
isAnyDropbarOpen: () => {
8493
if (!editor) return false;

packages/editor/src/core/hooks/use-editor.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,16 @@ export const useEditor = (props: TEditorHookProps) => {
132132
onAssetChange(assets);
133133
}, [assetsList?.assets, onAssetChange]);
134134

135-
useImperativeHandle(forwardedRef, () => getEditorRefHelpers({ editor, provider }), [editor, provider]);
135+
useImperativeHandle(
136+
forwardedRef,
137+
() =>
138+
getEditorRefHelpers({
139+
editor,
140+
getEditorMetaData,
141+
provider,
142+
}),
143+
[editor, getEditorMetaData, provider]
144+
);
136145

137146
if (!editor) {
138147
return null;

0 commit comments

Comments
 (0)