[WIKI-788] regression: copy markdown option #8200
This commit is contained in:
parent
123f59e74b
commit
6b85d67f6c
2 changed files with 24 additions and 6 deletions
|
|
@ -2,25 +2,27 @@ import type { HocuspocusProvider } from "@hocuspocus/provider";
|
|||
import type { Editor } from "@tiptap/core";
|
||||
import { DOMSerializer } from "@tiptap/pm/model";
|
||||
import * as Y from "yjs";
|
||||
// plane imports
|
||||
import { convertHTMLToMarkdown } from "@plane/utils";
|
||||
// components
|
||||
import { getEditorMenuItems } from "@/components/menus";
|
||||
// constants
|
||||
import { CORE_EXTENSIONS } from "@/constants/extension";
|
||||
import { CORE_EDITOR_META } from "@/constants/meta";
|
||||
// types
|
||||
import type { EditorRefApi, TEditorCommands } from "@/types";
|
||||
import type { EditorRefApi, IEditorProps, TEditorCommands } from "@/types";
|
||||
// local imports
|
||||
import { getParagraphCount } from "./common";
|
||||
import { insertContentAtSavedSelection } from "./insert-content-at-cursor-position";
|
||||
import { scrollSummary, scrollToNodeViaDOMCoordinates } from "./scroll-to-node";
|
||||
|
||||
type TArgs = {
|
||||
type TArgs = Pick<IEditorProps, "getEditorMetaData"> & {
|
||||
editor: Editor | null;
|
||||
provider: HocuspocusProvider | undefined;
|
||||
};
|
||||
|
||||
export const getEditorRefHelpers = (args: TArgs): EditorRefApi => {
|
||||
const { editor, provider } = args;
|
||||
const { editor, getEditorMetaData, provider } = args;
|
||||
|
||||
return {
|
||||
blur: () => editor?.commands.blur(),
|
||||
|
|
@ -77,8 +79,15 @@ export const getEditorRefHelpers = (args: TArgs): EditorRefApi => {
|
|||
}),
|
||||
getHeadings: () => (editor ? editor.storage.headingsList?.headings : []),
|
||||
getMarkDown: () => {
|
||||
const markdownOutput = editor?.storage?.markdown?.getMarkdown?.() ?? "";
|
||||
return markdownOutput;
|
||||
if (!editor) return "";
|
||||
const editorHTML = editor.getHTML();
|
||||
const metaData = getEditorMetaData(editorHTML);
|
||||
// convert to markdown
|
||||
const markdown = convertHTMLToMarkdown({
|
||||
description_html: editorHTML,
|
||||
metaData,
|
||||
});
|
||||
return markdown;
|
||||
},
|
||||
isAnyDropbarOpen: () => {
|
||||
if (!editor) return false;
|
||||
|
|
|
|||
|
|
@ -132,7 +132,16 @@ export const useEditor = (props: TEditorHookProps) => {
|
|||
onAssetChange(assets);
|
||||
}, [assetsList?.assets, onAssetChange]);
|
||||
|
||||
useImperativeHandle(forwardedRef, () => getEditorRefHelpers({ editor, provider }), [editor, provider]);
|
||||
useImperativeHandle(
|
||||
forwardedRef,
|
||||
() =>
|
||||
getEditorRefHelpers({
|
||||
editor,
|
||||
getEditorMetaData,
|
||||
provider,
|
||||
}),
|
||||
[editor, getEditorMetaData, provider]
|
||||
);
|
||||
|
||||
if (!editor) {
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue