-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathserver-example.js
More file actions
95 lines (81 loc) · 3.19 KB
/
server-example.js
File metadata and controls
95 lines (81 loc) · 3.19 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const express = require('express');
const bodyParser = require("body-parser");
const jsdom = require("jsdom");
const app = express();
const hostname = '127.0.0.1';
const port = 8999;
const host = hostname + ':' + port;
app.use(bodyParser.urlencoded({extended: false}));
const options = {
runScripts: 'dangerously',
resources: "usable",
pretendToBeVisual: true,
includeNodeLocations: true,
};
const {JSDOM} = jsdom;
const {window} = new JSDOM(`
<!DOCTYPE html>
<div id="editorjs"></div>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
<!--<script src="https://cdn.jsdelivr.net/npm/codex.editor.header@2.0.4/dist/bundle.js"></script>-->
<script src="https://cdn.jsdelivr.net/npm/@editorjs/table@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/header@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/link@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/checklist@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/embed@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/quote@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/inline-code@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/warning@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/code@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/marker@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/underline@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/delimiter@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/paragraph@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/list@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@editorjs/raw@latest"></script>
<!--<script src="https://cdn.jsdelivr.net/npm/@editorjs/image@latest"></script>-->
<script src="https://cdn.jsdelivr.net/npm/@editorjs/simple-image@latest"></script>
<script>
const editor = new EditorJS({
holder: 'editorjs',
tools: {
header: Header,
image: SimpleImage,
checklist:Checklist,
list: List,
raw: RawTool,
quote: Quote,
Code: CodeTool,
warning: Warning,
Marker: Marker,
delimiter:Delimiter,
underline:Underline,
paragraph:Paragraph,
inlineCode:InlineCode,
table: Table
}
})
let me = this
editor.isReady.then(()=>{
me.editor = editor
})
</script>`, options);
window.blocks = null
app.post('/html2blocks', function (req, res) {
if (window.editor) {
if (req.body.html) {
window.editor.blocks.renderFromHTML(req.body.html);
window.editor.save().then(data => {
console.log(data)
res.end(JSON.stringify(data))
})
} else {
res.end({code: -5, data: 'param error'})
}
} else {
res.end({code: -7, data: 'editor init failed'})
}
})
app.listen(port, hostname, function () {
console.log(`server run at http://${host}`);
});