@@ -2,25 +2,27 @@ import type { HocuspocusProvider } from "@hocuspocus/provider";
22import type { Editor } from "@tiptap/core" ;
33import { DOMSerializer } from "@tiptap/pm/model" ;
44import * as Y from "yjs" ;
5+ // plane imports
6+ import { convertHTMLToMarkdown } from "@plane/utils" ;
57// components
68import { getEditorMenuItems } from "@/components/menus" ;
79// constants
810import { CORE_EXTENSIONS } from "@/constants/extension" ;
911import { 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
1315import { getParagraphCount } from "./common" ;
1416import { insertContentAtSavedSelection } from "./insert-content-at-cursor-position" ;
1517import { 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
2224export 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 ;
0 commit comments