1
1
import { 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
+
2
8
import { PartialBlock } from "../../../blocks/defaultBlocks.js" ;
3
9
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js" ;
4
10
import {
5
11
BlockSchema ,
6
12
InlineContentSchema ,
7
13
StyleSchema ,
8
14
} from "../../../schema/index.js" ;
9
- import {
10
- esmDependencies ,
11
- initializeESMDependencies ,
12
- } from "../../../util/esmDependencies.js" ;
13
15
import { createExternalHTMLExporter } from "../html/externalHTMLExporter.js" ;
14
16
import { removeUnderlines } from "./removeUnderlinesRehypePlugin.js" ;
15
17
import { addSpacesToCheckboxes } from "./util/addSpacesToCheckboxesRehypePlugin.js" ;
16
18
17
19
// Needs to be sync because it's used in drag handler event (SideMenuPlugin)
18
- // Ideally, call `await initializeESMDependencies()` before calling this function
19
20
export 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 } )
31
23
. use ( removeUnderlines )
32
24
. 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 , {
36
28
handlers : { text : ( node ) => node . value } ,
37
29
} )
38
30
. processSync ( cleanHTMLString ) ;
@@ -50,7 +42,6 @@ export async function blocksToMarkdown<
50
42
editor : BlockNoteEditor < BSchema , I , S > ,
51
43
options : { document ?: Document } ,
52
44
) : Promise < string > {
53
- await initializeESMDependencies ( ) ;
54
45
const exporter = createExternalHTMLExporter ( schema , editor ) ;
55
46
const externalHTML = exporter . exportBlocks ( blocks , options ) ;
56
47
0 commit comments