11import { Schema } from "prosemirror-model" ;
2+ import rehypeParse from "rehype-parse" ;
3+ import rehypeRemark from "rehype-remark" ;
4+ import remarkGfm from "remark-gfm" ;
5+ import remarkStringify from "remark-stringify" ;
6+ import { unified } from "unified" ;
7+
28import { PartialBlock } from "../../../blocks/defaultBlocks.js" ;
39import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js" ;
410import {
511 BlockSchema ,
612 InlineContentSchema ,
713 StyleSchema ,
814} from "../../../schema/index.js" ;
9- import {
10- esmDependencies ,
11- initializeESMDependencies ,
12- } from "../../../util/esmDependencies.js" ;
1315import { createExternalHTMLExporter } from "../html/externalHTMLExporter.js" ;
1416import { removeUnderlines } from "./removeUnderlinesRehypePlugin.js" ;
1517import { addSpacesToCheckboxes } from "./util/addSpacesToCheckboxesRehypePlugin.js" ;
1618
1719// Needs to be sync because it's used in drag handler event (SideMenuPlugin)
18- // Ideally, call `await initializeESMDependencies()` before calling this function
1920export function cleanHTMLToMarkdown ( cleanHTMLString : string ) {
20- const deps = esmDependencies ;
21-
22- if ( ! deps ) {
23- throw new Error (
24- "cleanHTMLToMarkdown requires ESM dependencies to be initialized" ,
25- ) ;
26- }
27-
28- const markdownString = deps . unified
29- . unified ( )
30- . use ( deps . rehypeParse . default , { fragment : true } )
21+ const markdownString = unified ( )
22+ . use ( rehypeParse , { fragment : true } )
3123 . use ( removeUnderlines )
3224 . use ( addSpacesToCheckboxes )
33- . use ( deps . rehypeRemark . default )
34- . use ( deps . remarkGfm . default )
35- . use ( deps . remarkStringify . default , {
25+ . use ( rehypeRemark )
26+ . use ( remarkGfm )
27+ . use ( remarkStringify , {
3628 handlers : { text : ( node ) => node . value } ,
3729 } )
3830 . processSync ( cleanHTMLString ) ;
@@ -50,7 +42,6 @@ export async function blocksToMarkdown<
5042 editor : BlockNoteEditor < BSchema , I , S > ,
5143 options : { document ?: Document } ,
5244) : Promise < string > {
53- await initializeESMDependencies ( ) ;
5445 const exporter = createExternalHTMLExporter ( schema , editor ) ;
5546 const externalHTML = exporter . exportBlocks ( blocks , options ) ;
5647
0 commit comments