@seafile/seafile-editor 0.3.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -0
- package/TODO.md +55 -0
- package/dist/components/add-formula-dialog.js +135 -0
- package/dist/components/add-image-dialog.js +78 -0
- package/dist/components/add-link-dialog.js +148 -0
- package/dist/components/comment-dialog.js +107 -0
- package/dist/components/comment-panel.js +452 -0
- package/dist/components/context-menu.js +112 -0
- package/dist/components/detail-list-view.js +119 -0
- package/dist/components/generate-share-link.js +412 -0
- package/dist/components/internal-link-dialog.js +96 -0
- package/dist/components/loading.js +32 -0
- package/dist/components/markdown-lint.js +87 -0
- package/dist/components/modal-portal.js +46 -0
- package/dist/components/outline.js +130 -0
- package/dist/components/participants-list.js +126 -0
- package/dist/components/related-files-list.js +75 -0
- package/dist/components/shortcut-dialog.js +167 -0
- package/dist/components/side-panel.js +175 -0
- package/dist/components/toast/alert.js +150 -0
- package/dist/components/toast/index.js +3 -0
- package/dist/components/toast/toast.js +179 -0
- package/dist/components/toast/toastManager.js +158 -0
- package/dist/components/toast/toaster.js +76 -0
- package/dist/components/toolbar.js +235 -0
- package/dist/components/topbar-component/button-group.js +31 -0
- package/dist/components/topbar-component/editor-toolbar.js +545 -0
- package/dist/components/topbar-component/file-info.js +65 -0
- package/dist/components/topbar-component/header-list.js +128 -0
- package/dist/components/topbar-component/icon-button.js +99 -0
- package/dist/components/topbar-component/insert-file.js +67 -0
- package/dist/components/topbar-component/table-toolbar.js +175 -0
- package/dist/components/topbar-component/upload-img.js +122 -0
- package/dist/components/user-help.js +205 -0
- package/dist/css/diff-viewer.css +105 -0
- package/dist/css/history-viewer.css +104 -0
- package/dist/css/keyboard-shortcuts.css +59 -0
- package/dist/css/layout.css +110 -0
- package/dist/css/markdown-viewer-slate/file-tags-list.css +76 -0
- package/dist/css/markdown-viewer.css +69 -0
- package/dist/css/plaineditor/markdown-editor.css +12 -0
- package/dist/css/react-mentions-default-style.js +72 -0
- package/dist/css/related-files-list.css +56 -0
- package/dist/css/richeditor/comments-list.css +184 -0
- package/dist/css/richeditor/detail-list-view.css +114 -0
- package/dist/css/richeditor/document-info.css +57 -0
- package/dist/css/richeditor/formula.css +19 -0
- package/dist/css/richeditor/image.css +141 -0
- package/dist/css/richeditor/link.css +7 -0
- package/dist/css/richeditor/navbar-imgbutton.css +79 -0
- package/dist/css/richeditor/participants-list.css +22 -0
- package/dist/css/richeditor/rich-editor-main.css +42 -0
- package/dist/css/richeditor/right-panel.css +84 -0
- package/dist/css/richeditor/side-panel.css +190 -0
- package/dist/css/richeditor/table.css +57 -0
- package/dist/css/richeditor/textlink-hovermenu.css +47 -0
- package/dist/css/richeditor/tree-view.css +67 -0
- package/dist/css/topbar.css +400 -0
- package/dist/editor/code-highlight-package.js +27 -0
- package/dist/editor/controller/block-element-controller.js +376 -0
- package/dist/editor/controller/inline-element-controller.js +129 -0
- package/dist/editor/controller/normalize-controller.js +107 -0
- package/dist/editor/controller/shortcut-controller.js +394 -0
- package/dist/editor/controller/void-element-controller.js +12 -0
- package/dist/editor/custom/custom.js +17 -0
- package/dist/editor/custom/get-event-transfer.js +34 -0
- package/dist/editor/custom/getNodesByTypeAtRange.js +69 -0
- package/dist/editor/custom/insertNodes.js +140 -0
- package/dist/editor/custom/is-empty-paragraph.js +13 -0
- package/dist/editor/custom/set-event-transfer.js +31 -0
- package/dist/editor/custom/split-nodes-at-point.js +162 -0
- package/dist/editor/custom/unwrap-node-by-type-at-range.js +81 -0
- package/dist/editor/editor-component/check-list-item.js +64 -0
- package/dist/editor/editor-component/code-block.js +150 -0
- package/dist/editor/editor-component/formula.js +79 -0
- package/dist/editor/editor-component/image.js +215 -0
- package/dist/editor/editor-component/link.js +11 -0
- package/dist/editor/editor-component/table.js +172 -0
- package/dist/editor/editor-component/textlink-hovermenu.js +136 -0
- package/dist/editor/editor-plugin.js +249 -0
- package/dist/editor/editor-utils/block-element-utils/blockquote-utils.js +96 -0
- package/dist/editor/editor-utils/block-element-utils/code-utils.js +162 -0
- package/dist/editor/editor-utils/block-element-utils/formula-utils.js +58 -0
- package/dist/editor/editor-utils/block-element-utils/index.js +38 -0
- package/dist/editor/editor-utils/block-element-utils/list-utils.js +398 -0
- package/dist/editor/editor-utils/block-element-utils/table-utils.js +418 -0
- package/dist/editor/editor-utils/common-editor-utils.js +587 -0
- package/dist/editor/editor-utils/inline-element-utils/index.js +95 -0
- package/dist/editor/editor-utils/mark-utils.js +25 -0
- package/dist/editor/editor-utils/range-utils.js +9 -0
- package/dist/editor/editor-utils/selection-utils.js +33 -0
- package/dist/editor/editor-utils/text-utils.js +130 -0
- package/dist/editor/editor.js +66 -0
- package/dist/editor/element-model/blockquote.js +16 -0
- package/dist/editor/element-model/image.js +19 -0
- package/dist/editor/element-model/link.js +19 -0
- package/dist/editor/element-model/table.js +50 -0
- package/dist/editor/element-model/text.js +13 -0
- package/dist/editor/load-script.js +83 -0
- package/dist/editor/plain-markdown-editor.js +324 -0
- package/dist/editor/rich-markdown-editor.js +580 -0
- package/dist/editor/seafile-editor.js +326 -0
- package/dist/editor/simple-editor.js +245 -0
- package/dist/editor-api.js +261 -0
- package/dist/index.css +97 -0
- package/dist/lib/slate-hyperscript/creators.js +263 -0
- package/dist/lib/slate-hyperscript/hyperscript.js +92 -0
- package/dist/lib/slate-hyperscript/index.js +3 -0
- package/dist/lib/slate-hyperscript/tokens.js +102 -0
- package/dist/lib/unified/index.js +470 -0
- package/dist/lib/vfile/core.js +172 -0
- package/dist/lib/vfile/index.js +48 -0
- package/dist/seafile-editor-chooser.js +45 -0
- package/dist/seafile-markdown-editor.js +301 -0
- package/dist/seafile-markdown-viewer.js +79 -0
- package/dist/seafile-simple-editor.js +56 -0
- package/dist/utils/copy-to-clipboard.js +47 -0
- package/dist/utils/deserialize-html.js +282 -0
- package/dist/utils/diff/compare-strings.js +46 -0
- package/dist/utils/diff/diff.js +855 -0
- package/dist/utils/diff/index.js +2 -0
- package/dist/utils/render-slate.js +219 -0
- package/dist/utils/seafile-markdown2html.js +62 -0
- package/dist/utils/slate2markdown/deserialize.js +689 -0
- package/dist/utils/slate2markdown/index.js +3 -0
- package/dist/utils/slate2markdown/serialize.js +407 -0
- package/dist/utils/utils.js +28 -0
- package/dist/viewer/diff-viewer.js +98 -0
- package/dist/viewer/markdown-viewer.js +139 -0
- package/dist/viewer/slate-viewer.js +73 -0
- package/dist/viewer/viewer-formula.js +67 -0
- package/dist/viewer/viewer-image.js +93 -0
- package/dist/viewer/viewer-outline.js +118 -0
- package/package.json +215 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +45 -0
- package/public/locales/cs/seafile-editor.json +169 -0
- package/public/locales/de/seafile-editor.json +169 -0
- package/public/locales/en/seafile-editor.json +222 -0
- package/public/locales/es/seafile-editor.json +169 -0
- package/public/locales/es-AR/seafile-editor.json +169 -0
- package/public/locales/es-MX/seafile-editor.json +169 -0
- package/public/locales/fr/seafile-editor.json +169 -0
- package/public/locales/it/seafile-editor.json +169 -0
- package/public/locales/ru/seafile-editor.json +169 -0
- package/public/locales/zh-CN/seafile-editor.json +219 -0
- package/public/manifest.json +15 -0
- package/public/media/scripts/mathjax/tex-svg.js +1 -0
- package/public/media/seafile-editor-font/iconfont.eot +0 -0
- package/public/media/seafile-editor-font/iconfont.svg +164 -0
- package/public/media/seafile-editor-font/iconfont.ttf +0 -0
- package/public/media/seafile-editor-font/iconfont.woff +0 -0
- package/public/media/seafile-editor-font/iconfont.woff2 +0 -0
- package/public/media/seafile-editor-font.css +201 -0
- package/public/media/seafile-logo.png +0 -0
- package/public/media/seafile-ui.css +11169 -0
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
import { generateTable } from '../../editor/element-model/table';
|
|
3
|
+
import { Text } from 'slate';
|
|
4
|
+
import { isEmptyParagraph } from '../utils';
|
|
5
|
+
|
|
6
|
+
var unified = require('../../lib/unified');
|
|
7
|
+
|
|
8
|
+
var markdown = require('remark-parse');
|
|
9
|
+
|
|
10
|
+
var math = require('remark-math/block');
|
|
11
|
+
|
|
12
|
+
var definitions = require('mdast-util-definitions'); // transform code value: a function used to tranform code value of markdown format to slate document
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
function mdCodeNodeToSlate(codeValue) {
|
|
16
|
+
// statement an array : filled width code value splited by '\n'
|
|
17
|
+
var codeValueArr = codeValue.split(/\n/g);
|
|
18
|
+
var slateText, slateBlock; // map codeValueArr item to slate document 'code_line'
|
|
19
|
+
|
|
20
|
+
var slate_code_arr = codeValueArr.map(function (text) {
|
|
21
|
+
// transform string to slateText object
|
|
22
|
+
slateText = {
|
|
23
|
+
text: text
|
|
24
|
+
}; // transform slateText to Block object
|
|
25
|
+
|
|
26
|
+
slateBlock = {
|
|
27
|
+
children: [slateText],
|
|
28
|
+
type: 'code_line'
|
|
29
|
+
};
|
|
30
|
+
return slateBlock;
|
|
31
|
+
});
|
|
32
|
+
return slate_code_arr;
|
|
33
|
+
} // deserialize mdTable to SlateNode
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function mdTableToSlateTable(tableNode, opts) {
|
|
37
|
+
// get align array
|
|
38
|
+
var tableAlignArr = tableNode.align; // get all table_rows, return:array
|
|
39
|
+
|
|
40
|
+
var tableRows = tableNode.children; // slate table_row Node into it
|
|
41
|
+
|
|
42
|
+
var tableRowsArr = []; // traverse table_rows
|
|
43
|
+
|
|
44
|
+
for (var rowIndex = 0; rowIndex < tableRows.length; rowIndex++) {
|
|
45
|
+
// slate table_cell Node into it
|
|
46
|
+
var tableCellsArr = [];
|
|
47
|
+
/*
|
|
48
|
+
* traverse every table_cells of an table_rows,
|
|
49
|
+
* the length of every table_rows is equal to tableAlign array
|
|
50
|
+
* */
|
|
51
|
+
|
|
52
|
+
for (var columnsIndex = 0; columnsIndex < tableAlignArr.length; columnsIndex++) {
|
|
53
|
+
// get table_cell and tranlate it to slate Node: table_cell
|
|
54
|
+
var tableCell = tableRows[rowIndex].children[columnsIndex];
|
|
55
|
+
|
|
56
|
+
if (!tableCell) {
|
|
57
|
+
tableCell = {
|
|
58
|
+
type: 'tableCell',
|
|
59
|
+
children: [{
|
|
60
|
+
type: 'paragraph',
|
|
61
|
+
children: [{
|
|
62
|
+
text: ''
|
|
63
|
+
}]
|
|
64
|
+
}],
|
|
65
|
+
data: {
|
|
66
|
+
align: 'left'
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var children = parseChildren(tableCell, opts);
|
|
72
|
+
|
|
73
|
+
if (children.length === 0) {
|
|
74
|
+
children.push({
|
|
75
|
+
text: ''
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
tableCell = {
|
|
80
|
+
type: 'table_cell',
|
|
81
|
+
children: [{
|
|
82
|
+
type: 'paragraph',
|
|
83
|
+
children: children
|
|
84
|
+
}],
|
|
85
|
+
data: {
|
|
86
|
+
align: tableAlignArr[columnsIndex]
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
tableCellsArr.push(tableCell);
|
|
90
|
+
} // push add table_rows into tableRowsArr
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
tableRowsArr.push({
|
|
94
|
+
type: 'table_row',
|
|
95
|
+
children: tableCellsArr
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return tableRowsArr;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function mdImageToSlate(node, opts) {
|
|
103
|
+
var _DOMParser$parseFromS = new DOMParser().parseFromString(node.value, 'text/html'),
|
|
104
|
+
body = _DOMParser$parseFromS.body;
|
|
105
|
+
|
|
106
|
+
var img = body.firstChild;
|
|
107
|
+
var data = {};
|
|
108
|
+
data['src'] = img.getAttribute('src');
|
|
109
|
+
|
|
110
|
+
if (!isNaN(img.getAttribute('width')) && img.getAttribute('width') > 0) {
|
|
111
|
+
data['width'] = img.getAttribute('width');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!isNaN(img.getAttribute('height')) && img.getAttribute('height') > 0) {
|
|
115
|
+
data['height'] = img.getAttribute('height');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (img.getAttribute('alt')) {
|
|
119
|
+
data['alt'] = img.getAttribute('alt');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (img.getAttribute('title')) {
|
|
123
|
+
data['title'] = img.getAttribute('title');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (data['src']) {
|
|
127
|
+
return [{
|
|
128
|
+
text: ''
|
|
129
|
+
}, {
|
|
130
|
+
type: 'image',
|
|
131
|
+
data: data,
|
|
132
|
+
children: [{
|
|
133
|
+
text: ''
|
|
134
|
+
}]
|
|
135
|
+
}, {
|
|
136
|
+
text: ''
|
|
137
|
+
}];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function _applyMark(childNodeOrNodes, mark) {
|
|
142
|
+
if (childNodeOrNodes instanceof Array) {
|
|
143
|
+
return childNodeOrNodes.map(function (item) {
|
|
144
|
+
return _applyMark(item, mark);
|
|
145
|
+
});
|
|
146
|
+
} else if (childNodeOrNodes.text) {
|
|
147
|
+
childNodeOrNodes[mark] = true;
|
|
148
|
+
return childNodeOrNodes;
|
|
149
|
+
} else {
|
|
150
|
+
return childNodeOrNodes;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function addChildNodeOrNodes(children, childNodeOrNodes) {
|
|
155
|
+
if (childNodeOrNodes instanceof Array) {
|
|
156
|
+
childNodeOrNodes.map(function (item) {
|
|
157
|
+
return children.push(item);
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
if (childNodeOrNodes !== undefined) children.push(childNodeOrNodes);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function parseMark(node, markString, opts) {
|
|
165
|
+
var mark = markString;
|
|
166
|
+
var children = [];
|
|
167
|
+
|
|
168
|
+
var _iterator = _createForOfIteratorHelper(node.children),
|
|
169
|
+
_step;
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
173
|
+
var child = _step.value;
|
|
174
|
+
|
|
175
|
+
var childNodeOrNodes = _nodeToSlate(child, opts); // ignore unrecognized node type
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
if (!childNodeOrNodes) continue;
|
|
179
|
+
childNodeOrNodes = _applyMark(childNodeOrNodes, mark);
|
|
180
|
+
addChildNodeOrNodes(children, childNodeOrNodes);
|
|
181
|
+
}
|
|
182
|
+
} catch (err) {
|
|
183
|
+
_iterator.e(err);
|
|
184
|
+
} finally {
|
|
185
|
+
_iterator.f();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return children;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function parseChildren(node, opts) {
|
|
192
|
+
var children = [];
|
|
193
|
+
|
|
194
|
+
var _iterator2 = _createForOfIteratorHelper(node.children),
|
|
195
|
+
_step2;
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
199
|
+
var child = _step2.value;
|
|
200
|
+
|
|
201
|
+
var ret = _nodeToSlate(child, opts);
|
|
202
|
+
|
|
203
|
+
addChildNodeOrNodes(children, ret);
|
|
204
|
+
}
|
|
205
|
+
} catch (err) {
|
|
206
|
+
_iterator2.e(err);
|
|
207
|
+
} finally {
|
|
208
|
+
_iterator2.f();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return children;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function _nodeToSlate(node, opts) {
|
|
215
|
+
var children = [];
|
|
216
|
+
var definition = opts.definition;
|
|
217
|
+
|
|
218
|
+
switch (node.type) {
|
|
219
|
+
case 'heading':
|
|
220
|
+
var header_string;
|
|
221
|
+
children = parseChildren(node, opts);
|
|
222
|
+
|
|
223
|
+
if (children && children.length === 0) {
|
|
224
|
+
children.push({
|
|
225
|
+
text: ''
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
switch (node.depth) {
|
|
230
|
+
case 1:
|
|
231
|
+
header_string = 'header_one';
|
|
232
|
+
break;
|
|
233
|
+
|
|
234
|
+
case 2:
|
|
235
|
+
header_string = 'header_two';
|
|
236
|
+
break;
|
|
237
|
+
|
|
238
|
+
case 3:
|
|
239
|
+
header_string = 'header_three';
|
|
240
|
+
break;
|
|
241
|
+
|
|
242
|
+
case 4:
|
|
243
|
+
header_string = 'header_four';
|
|
244
|
+
break;
|
|
245
|
+
|
|
246
|
+
case 5:
|
|
247
|
+
header_string = 'header_five';
|
|
248
|
+
break;
|
|
249
|
+
|
|
250
|
+
case 6:
|
|
251
|
+
header_string = 'header_six';
|
|
252
|
+
break;
|
|
253
|
+
|
|
254
|
+
default:
|
|
255
|
+
console.log('Invalid depth: ' + node.depth);
|
|
256
|
+
header_string = 'header_one';
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
type: header_string,
|
|
262
|
+
children: children
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
case 'paragraph':
|
|
266
|
+
children = parseChildren(node, opts);
|
|
267
|
+
|
|
268
|
+
if (children.length === 0) {
|
|
269
|
+
children.push({
|
|
270
|
+
text: ''
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
type: 'paragraph',
|
|
276
|
+
children: children
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
case 'blockquote':
|
|
280
|
+
children = parseChildren(node, opts);
|
|
281
|
+
|
|
282
|
+
if (children.length === 0) {
|
|
283
|
+
children.push({
|
|
284
|
+
type: 'paragraph',
|
|
285
|
+
children: [{
|
|
286
|
+
text: ''
|
|
287
|
+
}]
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return {
|
|
292
|
+
type: 'blockquote',
|
|
293
|
+
children: children
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
case 'list':
|
|
297
|
+
opts.loose = node.loose;
|
|
298
|
+
children = parseChildren(node, opts);
|
|
299
|
+
|
|
300
|
+
if (children.length === 0) {
|
|
301
|
+
children.push({
|
|
302
|
+
type: 'list_item',
|
|
303
|
+
children: [{
|
|
304
|
+
type: 'paragraph',
|
|
305
|
+
children: [{
|
|
306
|
+
text: ''
|
|
307
|
+
}]
|
|
308
|
+
}]
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (node.ordered) {
|
|
313
|
+
return {
|
|
314
|
+
type: 'ordered_list',
|
|
315
|
+
children: children
|
|
316
|
+
};
|
|
317
|
+
} else {
|
|
318
|
+
return {
|
|
319
|
+
type: 'unordered_list',
|
|
320
|
+
children: children
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
case 'listItem':
|
|
325
|
+
children = parseChildren(node, opts);
|
|
326
|
+
|
|
327
|
+
if (children.length === 0) {
|
|
328
|
+
/**
|
|
329
|
+
* if children is an empty array push an empy paragaph to it
|
|
330
|
+
*/
|
|
331
|
+
children.push({
|
|
332
|
+
type: 'paragraph',
|
|
333
|
+
children: [{
|
|
334
|
+
text: ''
|
|
335
|
+
}]
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
var data = {};
|
|
340
|
+
|
|
341
|
+
if (node.checked !== null) {
|
|
342
|
+
data.checked = node.checked;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
return {
|
|
346
|
+
type: 'list_item',
|
|
347
|
+
data: data,
|
|
348
|
+
children: children
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
case 'code':
|
|
352
|
+
var data = {};
|
|
353
|
+
|
|
354
|
+
if (node.lang) {
|
|
355
|
+
data.syntax = node.lang;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
var slate_code_arr = mdCodeNodeToSlate(node.value);
|
|
359
|
+
|
|
360
|
+
if (slate_code_arr.length === 0) {
|
|
361
|
+
slate_code_arr.push({
|
|
362
|
+
type: 'code_line',
|
|
363
|
+
children: [{
|
|
364
|
+
text: ''
|
|
365
|
+
}]
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return {
|
|
370
|
+
type: 'code_block',
|
|
371
|
+
data: data,
|
|
372
|
+
children: slate_code_arr
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
case 'strong':
|
|
376
|
+
return parseMark(node, 'BOLD', opts);
|
|
377
|
+
|
|
378
|
+
case 'emphasis':
|
|
379
|
+
return parseMark(node, 'ITALIC', opts);
|
|
380
|
+
|
|
381
|
+
case 'inlineCode':
|
|
382
|
+
// Inline code need to be handled differently
|
|
383
|
+
return {
|
|
384
|
+
text: node.value,
|
|
385
|
+
'CODE': true
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
case 'text':
|
|
389
|
+
// A plain text in markdown
|
|
390
|
+
// text is the botton node in Markdown AST
|
|
391
|
+
return {
|
|
392
|
+
text: node.value
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
case 'thematicBreak':
|
|
396
|
+
return {
|
|
397
|
+
type: 'hr',
|
|
398
|
+
children: [{
|
|
399
|
+
text: ''
|
|
400
|
+
}]
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
case 'table':
|
|
404
|
+
// get all children of table by mdTableToSlateTable
|
|
405
|
+
children = mdTableToSlateTable(node, opts);
|
|
406
|
+
|
|
407
|
+
if (children.length === 0) {
|
|
408
|
+
return generateTable();
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return {
|
|
412
|
+
type: 'table',
|
|
413
|
+
children: children,
|
|
414
|
+
data: {
|
|
415
|
+
align: node.align
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
case 'html':
|
|
420
|
+
if (node.value.slice(0, 4).toLowerCase() === '<img') {
|
|
421
|
+
return mdImageToSlate(node, opts);
|
|
422
|
+
} else {
|
|
423
|
+
return {
|
|
424
|
+
text: node.value
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
case 'link':
|
|
429
|
+
children = parseChildren(node, opts);
|
|
430
|
+
if (children.length === 0) return {
|
|
431
|
+
text: ''
|
|
432
|
+
};
|
|
433
|
+
var data = {
|
|
434
|
+
href: node.url
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
if (node.title) {
|
|
438
|
+
data.title = node.title;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return [{
|
|
442
|
+
text: ''
|
|
443
|
+
}, {
|
|
444
|
+
type: 'link',
|
|
445
|
+
data: data,
|
|
446
|
+
children: children
|
|
447
|
+
}, {
|
|
448
|
+
text: ''
|
|
449
|
+
}];
|
|
450
|
+
|
|
451
|
+
case 'image':
|
|
452
|
+
var data = {
|
|
453
|
+
src: node.url
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
if (node.title) {
|
|
457
|
+
data.title = node.title;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (node.alt) {
|
|
461
|
+
data.alt = node.alt;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (node.width) {
|
|
465
|
+
data.width = node.width;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (node.height) {
|
|
469
|
+
data.height = node.height;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
return [{
|
|
473
|
+
text: ''
|
|
474
|
+
}, {
|
|
475
|
+
type: 'image',
|
|
476
|
+
data: data,
|
|
477
|
+
children: [{
|
|
478
|
+
text: ''
|
|
479
|
+
}]
|
|
480
|
+
}, {
|
|
481
|
+
text: ''
|
|
482
|
+
}];
|
|
483
|
+
|
|
484
|
+
case 'linkReference':
|
|
485
|
+
children = parseChildren(node, opts);
|
|
486
|
+
var def = definition(node.identifier);
|
|
487
|
+
var data = {};
|
|
488
|
+
|
|
489
|
+
if (def) {
|
|
490
|
+
data.href = def.url;
|
|
491
|
+
|
|
492
|
+
if (def.title) {
|
|
493
|
+
data.title = def.title;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return {
|
|
497
|
+
type: 'link',
|
|
498
|
+
data: data,
|
|
499
|
+
nodes: children
|
|
500
|
+
};
|
|
501
|
+
} else {
|
|
502
|
+
return {
|
|
503
|
+
text: '[' + node.identifier + ']'
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
case 'imageReference':
|
|
508
|
+
var def = definition(node.identifier);
|
|
509
|
+
var data = {};
|
|
510
|
+
|
|
511
|
+
if (def) {
|
|
512
|
+
data.src = def.url;
|
|
513
|
+
|
|
514
|
+
if (def.title) {
|
|
515
|
+
data.title = def.title;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (node.alt) {
|
|
519
|
+
data.alt = node.alt;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return {
|
|
523
|
+
type: 'image',
|
|
524
|
+
data: data,
|
|
525
|
+
children: [{
|
|
526
|
+
text: ''
|
|
527
|
+
}]
|
|
528
|
+
};
|
|
529
|
+
} else {
|
|
530
|
+
return {
|
|
531
|
+
text: '![' + node.alt + ']'
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
case 'math':
|
|
536
|
+
{
|
|
537
|
+
return {
|
|
538
|
+
type: 'formula',
|
|
539
|
+
children: [{
|
|
540
|
+
text: ''
|
|
541
|
+
}],
|
|
542
|
+
data: {
|
|
543
|
+
formula: node.value
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
case 'definition':
|
|
549
|
+
return;
|
|
550
|
+
|
|
551
|
+
default:
|
|
552
|
+
console.log('unrecognized type: ' + node.type);
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function fixValue(nodes) {
|
|
558
|
+
var c = [];
|
|
559
|
+
|
|
560
|
+
var _iterator3 = _createForOfIteratorHelper(nodes),
|
|
561
|
+
_step3;
|
|
562
|
+
|
|
563
|
+
try {
|
|
564
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
565
|
+
var node = _step3.value;
|
|
566
|
+
|
|
567
|
+
// if node is image node, wrap it into paragraph node
|
|
568
|
+
if (node.type === 'image') {
|
|
569
|
+
var data = {};
|
|
570
|
+
data['src'] = node.data.src;
|
|
571
|
+
data['width'] = node.data.width || null;
|
|
572
|
+
data['height'] = node.data.height || null;
|
|
573
|
+
|
|
574
|
+
if (node.data.alt) {
|
|
575
|
+
data['alt'] = node.data.alt;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (node.data.title) {
|
|
579
|
+
data['title'] = node.data.title;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
var nodeNew = {
|
|
583
|
+
type: 'paragraph',
|
|
584
|
+
children: [{
|
|
585
|
+
text: ''
|
|
586
|
+
}, {
|
|
587
|
+
type: 'image',
|
|
588
|
+
data: data,
|
|
589
|
+
children: [{
|
|
590
|
+
text: '',
|
|
591
|
+
marks: []
|
|
592
|
+
}]
|
|
593
|
+
}, {
|
|
594
|
+
text: ''
|
|
595
|
+
}]
|
|
596
|
+
};
|
|
597
|
+
c.push(nodeNew);
|
|
598
|
+
} else if (node.type === 'html_block') {
|
|
599
|
+
// convert from inline to block
|
|
600
|
+
node = {
|
|
601
|
+
type: 'html_block',
|
|
602
|
+
data: {
|
|
603
|
+
html: node.get('data').get('html')
|
|
604
|
+
},
|
|
605
|
+
children: node.nodes
|
|
606
|
+
};
|
|
607
|
+
c.push(node);
|
|
608
|
+
} else if (!Text.isText(node)) {
|
|
609
|
+
c.push(node);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
} catch (err) {
|
|
613
|
+
_iterator3.e(err);
|
|
614
|
+
} finally {
|
|
615
|
+
_iterator3.f();
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
return c;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function deserialize(content) {
|
|
622
|
+
var processor = unified().use(markdown, {
|
|
623
|
+
commonmark: true
|
|
624
|
+
}); // Parse formula md string to slate node when editor can insert formula
|
|
625
|
+
|
|
626
|
+
if (window.canInsertFormula) {
|
|
627
|
+
processor.use(math);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
var root = processor.parse(content);
|
|
631
|
+
var definition = definitions(root);
|
|
632
|
+
var nodes = [];
|
|
633
|
+
|
|
634
|
+
var _iterator4 = _createForOfIteratorHelper(root.children),
|
|
635
|
+
_step4;
|
|
636
|
+
|
|
637
|
+
try {
|
|
638
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
639
|
+
var child = _step4.value;
|
|
640
|
+
addChildNodeOrNodes(nodes, _nodeToSlate(child, {
|
|
641
|
+
definition: definition
|
|
642
|
+
}));
|
|
643
|
+
}
|
|
644
|
+
} catch (err) {
|
|
645
|
+
_iterator4.e(err);
|
|
646
|
+
} finally {
|
|
647
|
+
_iterator4.f();
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
if (nodes.length === 0) {
|
|
651
|
+
// add default paragraph
|
|
652
|
+
var node = {
|
|
653
|
+
type: 'paragraph',
|
|
654
|
+
children: [{
|
|
655
|
+
text: ''
|
|
656
|
+
}]
|
|
657
|
+
};
|
|
658
|
+
nodes.push(node);
|
|
659
|
+
} // handle image and html_block
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
var c;
|
|
663
|
+
c = fixValue(nodes);
|
|
664
|
+
var firstBlockType = c[0].type;
|
|
665
|
+
|
|
666
|
+
if (firstBlockType === 'table' || firstBlockType === 'code_block' || firstBlockType === 'blockquote') {
|
|
667
|
+
c.unshift({
|
|
668
|
+
type: 'paragraph',
|
|
669
|
+
children: [{
|
|
670
|
+
text: ''
|
|
671
|
+
}]
|
|
672
|
+
});
|
|
673
|
+
} // Do not add an empty paragraph in if the article has only an empty paragraph
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
if (c.length === 1 && isEmptyParagraph(c[0])) {
|
|
677
|
+
return c;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
c.push({
|
|
681
|
+
type: 'paragraph',
|
|
682
|
+
children: [{
|
|
683
|
+
text: ''
|
|
684
|
+
}]
|
|
685
|
+
});
|
|
686
|
+
return c;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
export { deserialize };
|