Skip to content

Commit 5f1691d

Browse files
committed
polyfill window for prismjs
1 parent 331ab9b commit 5f1691d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/editor/headless.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const createHeadlessEditor = ({ namespace }: { namespace?: string }) => {
99
namespace,
1010
nodes: [...nodes],
1111
theme: theme,
12-
onError: () => {},
12+
onError: e => {
13+
console.error(e);
14+
},
1315
html: htmlConfig,
1416
});
1517
};

src/lib/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,25 @@ function setupDom() {
3636
};
3737
}
3838

39+
function setupWindow() {
40+
const _window = global.window;
41+
// need to setup window for CodeNode since facebook#5828
42+
// https://github.com/facebook/lexical/pull/5828
43+
// @ts-expect-error
44+
global.window = global;
45+
46+
return () => {
47+
global.window = _window;
48+
};
49+
}
50+
3951
export async function getHtml(serializedEditorState: string) {
4052
const html: string = await new Promise(resolve => {
53+
const cleanup = setupWindow();
4154
const editor = createHeadlessEditor({ namespace: 'html-renderer' });
4255

4356
editor.setEditorState(editor.parseEditorState(serializedEditorState));
57+
cleanup();
4458

4559
editor.update(() => {
4660
try {

0 commit comments

Comments
 (0)