-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter.js
35 lines (28 loc) · 942 Bytes
/
converter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const Window = require('window');
const reactDom = require('react-dom');
const window = new Window();
// Setup global vars required by Gutenberg packages
global.window = window;
global.document = window.document;
window.matchMedia = query => ({
matches: query !== '(min-width: 240px) and (max-width: 767px)',
media: '',
onchange: null,
addListener: () => {},
removeListener: () => {},
});
global.navigator = window.navigator;
global['react-dom'] = reactDom;
const blocks = require('@wordpress/blocks');
const blockLibrary = require('@wordpress/block-library');
exports.parse = function (html) {
blockLibrary.registerCoreBlocks();
const result = blocks.rawHandler({HTML: html});
const serializedResult = blocks.serialize(result);
return serializedResult;
}
exports.parseToJSON = function(html) {
blockLibrary.registerCoreBlocks();
const result = blocks.rawHandler({HTML: html});
return JSON.stringify(result);
}