@seafile/seafile-editor 0.4.8 → 1.0.0
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/.babelrc +5 -0
- package/.eslintignore +19 -0
- package/.eslintrc.json +52 -0
- package/.github/workflows/nodejs.yml +25 -0
- package/.vscode/settings.json +5 -0
- package/config/config.common.js +157 -0
- package/config/config.dev.js +53 -0
- package/config/jest/cssTransform.js +16 -0
- package/config/jest/fileTransform.js +40 -0
- package/config/utils/theme.css.js +103 -0
- package/config.js +61 -0
- package/dev-server.js +145 -0
- package/jest.config.js +16 -0
- package/package.json +81 -131
- package/public/locales/en/seafile-editor.json +145 -148
- package/public/locales/zh-CN/seafile-editor.json +123 -135
- package/public/media/seafile-ui.css +6 -11166
- package/scripts/ejs.js +16 -0
- package/site/_i18n/index.js +35 -0
- package/site/api/index.js +212 -0
- package/site/app.js +21 -0
- package/site/assets/css/app.css +47 -0
- package/site/assets/css/seafile-editor.css +33 -0
- package/site/commons/loading/index.js +14 -0
- package/site/commons/loading/style.css +49 -0
- package/site/commons/switch/index.css +14 -0
- package/site/commons/switch/index.js +37 -0
- package/site/commons/toast/alert.js +106 -0
- package/site/commons/toast/index.js +5 -0
- package/site/commons/toast/toast.js +195 -0
- package/site/commons/toast/toastManager.js +138 -0
- package/site/commons/toast/toaster.js +64 -0
- package/site/index.html +23 -0
- package/site/index.js +21 -0
- package/site/pages/home.js +21 -0
- package/site/pages/plain-markdown-view.js +6 -0
- package/site/pages/rich-seafile-editor.js +72 -0
- package/site/pages/seafile-editor.js +39 -0
- package/site/pages/seafile-viewer.js +45 -0
- package/site/pages/simple-editor.js +44 -0
- package/site/pages/wiki-viewer.js +7 -0
- package/site/setting.js +36 -0
- package/site/setting.local.dist.js +23 -0
- package/src/assets/css/slate-editor.css +57 -0
- package/src/constants/event-types.js +11 -0
- package/src/constants/hot-keys.js +47 -0
- package/src/containers/article-info/index.js +49 -0
- package/src/containers/article-info/style.css +52 -0
- package/src/containers/custom/get-event-transfer.js +28 -0
- package/{dist → src}/containers/custom/set-event-transfer.js +13 -11
- package/src/containers/hotkeys-helper/classify-hotkeys.js +30 -0
- package/src/containers/hotkeys-helper/index.js +43 -0
- package/{dist/assets/css/user-help.css → src/containers/hotkeys-helper/style.css} +37 -29
- package/src/containers/loading/index.js +14 -0
- package/src/containers/loading/style.css +49 -0
- package/src/containers/outline/index.js +75 -0
- package/src/containers/outline/outline-item.js +28 -0
- package/src/containers/outline/style.css +45 -0
- package/src/editors/plain-markdown-editor/code-mirror.css +8 -0
- package/src/editors/plain-markdown-editor/code-mirror.js +73 -0
- package/src/editors/plain-markdown-editor/index.js +136 -0
- package/{dist/assets/editor/plain-editor.css → src/editors/plain-markdown-editor/style.css} +12 -4
- package/src/editors/simple-slate-editor /index.js +71 -0
- package/src/editors/simple-slate-editor /with-props-editor.js +15 -0
- package/src/editors/slate-editor/editor-help/index.js +46 -0
- package/src/editors/slate-editor/editor-help/style.css +15 -0
- package/src/editors/slate-editor/index.js +77 -0
- package/src/editors/slate-editor/with-props-editor.js +15 -0
- package/src/editors/slate-viewer/index.js +35 -0
- package/src/editors/slate-viewer/style.css +40 -0
- package/src/extension/commons/element-popover/index.js +52 -0
- package/src/extension/commons/index.js +10 -0
- package/src/extension/commons/menu/index.js +9 -0
- package/src/extension/commons/menu/menu-drop-down.js +110 -0
- package/src/extension/commons/menu/menu-group.js +20 -0
- package/src/extension/commons/menu/menu-item.js +60 -0
- package/src/extension/commons/menu/menu.css +120 -0
- package/src/extension/commons/tooltip/index.css +21 -0
- package/src/extension/commons/tooltip/index.js +26 -0
- package/src/extension/constants/element-types.js +23 -0
- package/src/extension/constants/index.js +37 -0
- package/src/extension/constants/keyboard.js +29 -0
- package/src/extension/constants/menus-config.js +149 -0
- package/src/extension/core/index.js +3 -0
- package/src/extension/core/queries/index.js +410 -0
- package/src/extension/core/transforms/focus-editor.js +12 -0
- package/src/extension/core/transforms/index.js +4 -0
- package/src/extension/core/transforms/move-children.js +23 -0
- package/src/extension/core/transforms/remove-node-children.js +8 -0
- package/src/extension/core/transforms/replace-node-children.js +14 -0
- package/src/extension/core/utils/index.js +76 -0
- package/src/extension/editor.js +14 -0
- package/src/extension/index.js +15 -0
- package/src/extension/plugins/blockquote/helpers.js +65 -0
- package/src/extension/plugins/blockquote/index.js +13 -0
- package/src/extension/plugins/blockquote/menu/index.js +31 -0
- package/src/extension/plugins/blockquote/plugin.js +64 -0
- package/src/extension/plugins/blockquote/render-elem.js +9 -0
- package/src/extension/plugins/check-list/helper.js +34 -0
- package/src/extension/plugins/check-list/index.js +14 -0
- package/src/extension/plugins/check-list/menu/index.js +44 -0
- package/src/extension/plugins/check-list/plugin.js +46 -0
- package/src/extension/plugins/check-list/render-elem.js +23 -0
- package/src/extension/plugins/clear-format/helpers.js +48 -0
- package/src/extension/plugins/clear-format/menu/index.js +39 -0
- package/src/extension/plugins/code-block/helpers.js +107 -0
- package/src/extension/plugins/code-block/index.js +14 -0
- package/src/extension/plugins/code-block/menu/index.js +40 -0
- package/src/extension/plugins/code-block/plugin.js +210 -0
- package/src/extension/plugins/code-block/render-elem/constant.js +17 -0
- package/src/extension/plugins/code-block/render-elem/index.js +55 -0
- package/src/extension/plugins/code-block/render-elem/language-selector.js +38 -0
- package/src/extension/plugins/code-block/render-elem/style.css +27 -0
- package/src/extension/plugins/formula/formula.css +22 -0
- package/src/extension/plugins/formula/helper.js +68 -0
- package/src/extension/plugins/formula/index.js +14 -0
- package/src/extension/plugins/formula/menu/formula-modal.js +73 -0
- package/src/extension/plugins/formula/menu/index.js +63 -0
- package/src/extension/plugins/formula/plugin.js +18 -0
- package/src/extension/plugins/formula/render-elem.js +40 -0
- package/src/extension/plugins/header/helper.js +47 -0
- package/src/extension/plugins/header/index.js +14 -0
- package/src/extension/plugins/header/menu/index.js +114 -0
- package/src/extension/plugins/header/menu/style.css +115 -0
- package/src/extension/plugins/header/plugin.js +134 -0
- package/src/extension/plugins/header/render-elem.js +31 -0
- package/src/extension/plugins/image/helper.js +50 -0
- package/src/extension/plugins/image/index.js +14 -0
- package/src/extension/plugins/image/menu/image-menu-dialog.js +68 -0
- package/src/extension/plugins/image/menu/image-menu-popover.js +76 -0
- package/src/extension/plugins/image/menu/index.js +61 -0
- package/src/extension/plugins/image/menu/style.css +36 -0
- package/src/extension/plugins/image/plugin.js +23 -0
- package/src/extension/plugins/image/render-element/image-previewer.js +71 -0
- package/src/extension/plugins/image/render-element/index.js +94 -0
- package/src/extension/plugins/image/render-element/style.css +60 -0
- package/src/extension/plugins/index.js +47 -0
- package/src/extension/plugins/link/helper.js +161 -0
- package/src/extension/plugins/link/index.js +14 -0
- package/src/extension/plugins/link/menu/index.js +82 -0
- package/src/extension/plugins/link/menu/link-modal.js +135 -0
- package/src/extension/plugins/link/plugin.js +85 -0
- package/src/extension/plugins/link/render-elem/index.js +69 -0
- package/src/extension/plugins/link/render-elem/link-popover.js +79 -0
- package/src/extension/plugins/link/render-elem/style.css +60 -0
- package/src/extension/plugins/list/constant.js +3 -0
- package/src/extension/plugins/list/helpers.js +53 -0
- package/src/extension/plugins/list/index.js +14 -0
- package/src/extension/plugins/list/menu/index.js +48 -0
- package/src/extension/plugins/list/plugin/index.js +48 -0
- package/src/extension/plugins/list/plugin/insert-break-list.js +25 -0
- package/src/extension/plugins/list/plugin/insert-fragment-list.js +162 -0
- package/src/extension/plugins/list/plugin/normalize-list.js +64 -0
- package/src/extension/plugins/list/plugin/on-tab-handle.js +34 -0
- package/src/extension/plugins/list/queries/index.js +39 -0
- package/src/extension/plugins/list/render-elem/index.js +26 -0
- package/src/extension/plugins/list/render-elem/style.css +6 -0
- package/src/extension/plugins/list/transforms/index.js +23 -0
- package/src/extension/plugins/list/transforms/insert-list-item.js +65 -0
- package/src/extension/plugins/list/transforms/move-list-item-down.js +40 -0
- package/src/extension/plugins/list/transforms/move-list-item-up.js +105 -0
- package/src/extension/plugins/list/transforms/move-list-items-to-list.js +58 -0
- package/src/extension/plugins/list/transforms/move-list-items.js +76 -0
- package/src/extension/plugins/list/transforms/normalize-list-item.js +92 -0
- package/src/extension/plugins/list/transforms/normalize-nested-list.js +31 -0
- package/src/extension/plugins/list/transforms/remove-first-list-item.js +11 -0
- package/src/extension/plugins/list/transforms/transforms-to-list.js +91 -0
- package/src/extension/plugins/list/transforms/unwrap-list.js +44 -0
- package/src/extension/plugins/node-id/constants.js +18 -0
- package/src/extension/plugins/node-id/helpers.js +61 -0
- package/src/extension/plugins/node-id/index.js +7 -0
- package/src/extension/plugins/node-id/with-node-id.js +37 -0
- package/src/extension/plugins/paragraph/helper.js +9 -0
- package/src/extension/plugins/paragraph/index.js +12 -0
- package/src/extension/plugins/paragraph/plugin.js +40 -0
- package/src/extension/plugins/paragraph/render-elem.js +11 -0
- package/src/extension/plugins/table/constant.js +3 -0
- package/src/extension/plugins/table/helper.js +175 -0
- package/src/extension/plugins/table/index.js +15 -0
- package/src/extension/plugins/table/menu/index.js +69 -0
- package/src/extension/plugins/table/menu/style.css +32 -0
- package/src/extension/plugins/table/menu/table-operator.js +101 -0
- package/src/extension/plugins/table/menu/table-size-selector.js +71 -0
- package/src/extension/plugins/table/model.js +69 -0
- package/src/extension/plugins/table/plugin.js +159 -0
- package/src/extension/plugins/table/render-elem/context-menu.js +78 -0
- package/src/extension/plugins/table/render-elem/index.js +157 -0
- package/src/extension/plugins/table/render-elem/style.css +94 -0
- package/src/extension/plugins/table/table-operations.js +162 -0
- package/src/extension/plugins/text-style/helpers.js +38 -0
- package/src/extension/plugins/text-style/index.js +12 -0
- package/src/extension/plugins/text-style/menu/index.js +41 -0
- package/src/extension/plugins/text-style/plugin.js +37 -0
- package/src/extension/plugins/text-style/render-elem.js +45 -0
- package/src/extension/render/render-element.js +82 -0
- package/src/extension/render/render-leaf.js +16 -0
- package/src/extension/toolbar/header-toolbar/index.js +129 -0
- package/src/extension/toolbar/header-toolbar/style.css +41 -0
- package/src/extension/toolbar/index.js +5 -0
- package/src/extension/toolbar/user-help/shortcut-dialog.js +144 -0
- package/src/hooks/use-mathjax.js +44 -0
- package/src/hooks/use-scroll-context.js +14 -0
- package/src/hooks/use-selection-update.js +14 -0
- package/src/index.js +22 -0
- package/src/pages/markdown-editor.js +53 -0
- package/src/pages/markdown-view.js +36 -0
- package/src/pages/rich-markdown-editor.js +95 -0
- package/src/pages/simple-editor.js +52 -0
- package/src/slate-convert/html-to-slate/constants.js +54 -0
- package/src/slate-convert/html-to-slate/helper.js +22 -0
- package/src/slate-convert/html-to-slate/index.js +144 -0
- package/src/slate-convert/html-to-slate/rules/blockquote.js +16 -0
- package/src/slate-convert/html-to-slate/rules/check-list.js +22 -0
- package/src/slate-convert/html-to-slate/rules/code-block.js +91 -0
- package/src/slate-convert/html-to-slate/rules/header.js +18 -0
- package/src/slate-convert/html-to-slate/rules/image.js +18 -0
- package/src/slate-convert/html-to-slate/rules/index.js +23 -0
- package/src/slate-convert/html-to-slate/rules/link.js +24 -0
- package/src/slate-convert/html-to-slate/rules/list.js +52 -0
- package/src/slate-convert/html-to-slate/rules/paragraph.js +16 -0
- package/src/slate-convert/html-to-slate/rules/table.js +37 -0
- package/src/slate-convert/html-to-slate/rules/text.js +63 -0
- package/src/slate-convert/index.js +11 -0
- package/src/slate-convert/md-to-html/index.js +44 -0
- package/src/slate-convert/md-to-html/sanitize-schema.js +41 -0
- package/src/slate-convert/md-to-slate/index.js +42 -0
- package/src/slate-convert/md-to-slate/transform.js +336 -0
- package/src/slate-convert/slate-to-md/index.js +44 -0
- package/src/slate-convert/slate-to-md/transform.js +248 -0
- package/src/utils/common.js +30 -0
- package/src/utils/deserialize-html.js +174 -0
- package/src/utils/dom-utils.js +45 -0
- package/src/utils/event-bus.js +37 -0
- package/src/utils/event-handler.js +36 -0
- package/src/utils/object-utils.js +51 -0
- package/tests/core/constants/index.js +54 -0
- package/tests/core/index.js +11 -0
- package/tests/core/jsx/index.js +9 -0
- package/tests/core/stub-editor/index.js +26 -0
- package/tests/core/utils.js +58 -0
- package/tests/extension/plugins/list/insert-block.test.js +40 -0
- package/tests/extension/plugins/list/insert-fragment-list.test.js +392 -0
- package/tests/extension/plugins/list/toggle-list.test.js +160 -0
- package/tests/extension/plugins/text/text.test.js +29 -0
- package/tests/extension/plugins/text-style/toggle-text-style.test.js +148 -0
- package/tests/slate-convert/html-to-slate/blockquote.test.js +107 -0
- package/tests/slate-convert/html-to-slate/code-block.test.js +32 -0
- package/tests/slate-convert/html-to-slate/header.test.js +56 -0
- package/tests/slate-convert/html-to-slate/link.test.js +77 -0
- package/tests/slate-convert/html-to-slate/list.test.js +190 -0
- package/tests/slate-convert/html-to-slate/paragraph.test.js +40 -0
- package/tests/slate-convert/html-to-slate/text.test.js +131 -0
- package/tests/slate-convert/md-to-html/blockquote.test.js +110 -0
- package/tests/slate-convert/md-to-html/check-list.test.js +19 -0
- package/tests/slate-convert/md-to-html/code-block.test.js +19 -0
- package/tests/slate-convert/md-to-html/header.test.js +20 -0
- package/tests/slate-convert/md-to-html/image.test.js +17 -0
- package/tests/slate-convert/md-to-html/image_reference.test.js +17 -0
- package/tests/slate-convert/md-to-html/link.test.js +15 -0
- package/tests/slate-convert/md-to-html/link_reference.test.js +15 -0
- package/tests/slate-convert/md-to-html/list-ordered.test.js +22 -0
- package/tests/slate-convert/md-to-html/list-unordered.test.js +22 -0
- package/tests/slate-convert/md-to-html/paragraph.test.js +15 -0
- package/tests/slate-convert/md-to-html/table.test.js +29 -0
- package/tests/slate-convert/md-to-html/text_base.test.js +14 -0
- package/tests/slate-convert/md-to-html/text_bold.test.js +14 -0
- package/tests/slate-convert/md-to-html/text_bold_italic.test.js +15 -0
- package/tests/slate-convert/md-to-html/text_code.test.js +14 -0
- package/tests/slate-convert/md-to-html/text_code_bold.test.js +14 -0
- package/tests/slate-convert/md-to-html/text_code_bold_italic.test.js +14 -0
- package/tests/slate-convert/md-to-html/text_code_italic.test.js +14 -0
- package/tests/slate-convert/md-to-html/text_italic.test.js +14 -0
- package/tests/slate-convert/md-to-slate/blockquote.test.js +200 -0
- package/tests/slate-convert/md-to-slate/check-list.test.js +34 -0
- package/tests/slate-convert/md-to-slate/code-block.test.js +32 -0
- package/tests/slate-convert/md-to-slate/header.test.js +49 -0
- package/tests/slate-convert/md-to-slate/image.test.js +31 -0
- package/tests/slate-convert/md-to-slate/link.test.js +30 -0
- package/tests/slate-convert/md-to-slate/list-ordered.test.js +42 -0
- package/tests/slate-convert/md-to-slate/list-unordered.test.js +42 -0
- package/tests/slate-convert/md-to-slate/paragraph.test.js +19 -0
- package/tests/slate-convert/md-to-slate/table.test.js +34 -0
- package/tests/slate-convert/md-to-slate/text_base.test.js +19 -0
- package/tests/slate-convert/md-to-slate/text_bold.test.js +22 -0
- package/tests/slate-convert/md-to-slate/text_bold_italic.test.js +23 -0
- package/tests/slate-convert/md-to-slate/text_code.test.js +22 -0
- package/tests/slate-convert/md-to-slate/text_code_bold.test.js +23 -0
- package/tests/slate-convert/md-to-slate/text_code_bold_italic.test.js +24 -0
- package/tests/slate-convert/md-to-slate/text_code_italic.test.js +23 -0
- package/tests/slate-convert/md-to-slate/text_italic.test.js +22 -0
- package/tests/slate-convert/slate-to-md/blockquote.test.js +416 -0
- package/tests/slate-convert/slate-to-md/check-list.test.js +96 -0
- package/tests/slate-convert/slate-to-md/code-block.test.js +35 -0
- package/tests/slate-convert/slate-to-md/formula.test.js +26 -0
- package/tests/slate-convert/slate-to-md/header.test.js +109 -0
- package/tests/slate-convert/slate-to-md/image.test.js +98 -0
- package/tests/slate-convert/slate-to-md/link.test.js +52 -0
- package/tests/slate-convert/slate-to-md/list-ordered.test.js +87 -0
- package/tests/slate-convert/slate-to-md/list-unordered.test.js +81 -0
- package/tests/slate-convert/slate-to-md/paragraph.test.js +28 -0
- package/tests/slate-convert/slate-to-md/table.test.js +56 -0
- package/tests/slate-convert/slate-to-md/text_base.test.js +28 -0
- package/tests/slate-convert/slate-to-md/text_bold.test.js +36 -0
- package/tests/slate-convert/slate-to-md/text_bold_italic.test.js +42 -0
- package/tests/slate-convert/slate-to-md/text_code.test.js +31 -0
- package/tests/slate-convert/slate-to-md/text_code_bold.test.js +37 -0
- package/tests/slate-convert/slate-to-md/text_code_bold_italic.test.js +43 -0
- package/tests/slate-convert/slate-to-md/text_code_italic.test.js +37 -0
- package/tests/slate-convert/slate-to-md/text_italic.test.js +36 -0
- package/README.md +0 -52
- package/TODO.md +0 -55
- package/dist/assets/css/diff-viewer.css +0 -105
- package/dist/assets/css/formula.css +0 -19
- package/dist/assets/css/history-viewer.css +0 -104
- package/dist/assets/css/image.css +0 -134
- package/dist/assets/css/link.css +0 -7
- package/dist/assets/css/markdown-editor.css +0 -12
- package/dist/assets/css/markdown-viewer.css +0 -69
- package/dist/assets/css/navbar-imgbutton.css +0 -83
- package/dist/assets/css/outline.css +0 -29
- package/dist/assets/css/table.css +0 -57
- package/dist/assets/css/textlink-hovermenu.css +0 -47
- package/dist/assets/css/topbar.css +0 -350
- package/dist/assets/css/tree-view.css +0 -67
- package/dist/assets/editor/seatable-editor.css +0 -77
- package/dist/assets/editor/simple-editor.css +0 -77
- package/dist/components/click-outside.js +0 -46
- package/dist/components/context-menu.js +0 -97
- package/dist/components/dialogs/add-formula-dialog.js +0 -116
- package/dist/components/dialogs/add-image-dialog.js +0 -69
- package/dist/components/dialogs/add-link-dialog.js +0 -133
- package/dist/components/dialogs/shortcut-dialog.js +0 -131
- package/dist/components/error-boundary.js +0 -28
- package/dist/components/load-script/index.js +0 -69
- package/dist/components/loading.js +0 -25
- package/dist/components/menu/index.js +0 -4
- package/dist/components/menu/item.js +0 -49
- package/dist/components/menu/menu.js +0 -38
- package/dist/components/menu/style.css +0 -42
- package/dist/components/modal-portal.js +0 -38
- package/dist/components/outline/index.js +0 -92
- package/dist/components/outline/outline-item.js +0 -58
- package/dist/components/select/_option.js +0 -44
- package/dist/components/select/field-setting.js +0 -106
- package/dist/components/select/index.js +0 -149
- package/dist/components/select/style.css +0 -144
- package/dist/components/svg-icons/check-mark-icon.js +0 -14
- package/dist/components/svg-icons/column-icon.js +0 -17
- package/dist/components/svg-icons/text-icon.js +0 -34
- package/dist/components/text-link-hover-menu/index.js +0 -123
- package/dist/components/toast/alert.js +0 -138
- package/dist/components/toast/index.js +0 -3
- package/dist/components/toast/toast.js +0 -159
- package/dist/components/toast/toastManager.js +0 -139
- package/dist/components/toast/toaster.js +0 -65
- package/dist/components/toolbar/header-list.js +0 -114
- package/dist/components/toolbar/help-group.js +0 -33
- package/dist/components/toolbar/index.js +0 -4
- package/dist/components/toolbar/insert-image.js +0 -106
- package/dist/components/toolbar/insert-table.js +0 -136
- package/dist/components/toolbar/table-group.js +0 -74
- package/dist/components/toolbar/toolbar.js +0 -317
- package/dist/components/toolbar/widgets/button-group.js +0 -24
- package/dist/components/toolbar/widgets/button-item.js +0 -129
- package/dist/components/toolbar/widgets/drop-list.js +0 -88
- package/dist/components/user-help/index.js +0 -179
- package/dist/config.js +0 -15
- package/dist/constants/cell-types.js +0 -29
- package/dist/constants/column.js +0 -4
- package/dist/containers/code-highlight-package.js +0 -14
- package/dist/containers/controller/block-element-controller.js +0 -375
- package/dist/containers/controller/index.js +0 -5
- package/dist/containers/controller/inline-element-controller.js +0 -134
- package/dist/containers/controller/normalize-controller.js +0 -95
- package/dist/containers/controller/shortcut-controller.js +0 -385
- package/dist/containers/controller/void-element-controller.js +0 -9
- package/dist/containers/custom/custom.js +0 -18
- package/dist/containers/custom/get-event-transfer.js +0 -33
- package/dist/containers/custom/getNodesByTypeAtRange.js +0 -57
- package/dist/containers/custom/insertNodes.js +0 -120
- package/dist/containers/custom/is-empty-paragraph.js +0 -9
- package/dist/containers/custom/split-nodes-at-point.js +0 -136
- package/dist/containers/custom/unwrap-node-by-type-at-range.js +0 -70
- package/dist/containers/editor-context.js +0 -85
- package/dist/containers/editor-utils/block-element-utils/blockquote-utils.js +0 -80
- package/dist/containers/editor-utils/block-element-utils/code-utils.js +0 -145
- package/dist/containers/editor-utils/block-element-utils/formula-utils.js +0 -51
- package/dist/containers/editor-utils/block-element-utils/index.js +0 -31
- package/dist/containers/editor-utils/block-element-utils/list-utils.js +0 -395
- package/dist/containers/editor-utils/block-element-utils/table-utils.js +0 -412
- package/dist/containers/editor-utils/clear-format-utils.js +0 -84
- package/dist/containers/editor-utils/common-editor-utils.js +0 -492
- package/dist/containers/editor-utils/inline-element-utils/index.js +0 -95
- package/dist/containers/editor-utils/mark-utils.js +0 -20
- package/dist/containers/editor-utils/range-utils.js +0 -7
- package/dist/containers/editor-utils/selection-utils.js +0 -30
- package/dist/containers/editor-utils/text-utils.js +0 -117
- package/dist/containers/editor-widgets/check-list-item.js +0 -53
- package/dist/containers/editor-widgets/code-block.js +0 -128
- package/dist/containers/editor-widgets/column.js +0 -100
- package/dist/containers/editor-widgets/formula.js +0 -67
- package/dist/containers/editor-widgets/image.js +0 -237
- package/dist/containers/editor-widgets/link.js +0 -9
- package/dist/containers/editor-widgets/table.js +0 -144
- package/dist/containers/element-model/blockquote.js +0 -13
- package/dist/containers/element-model/column.js +0 -19
- package/dist/containers/element-model/image.js +0 -16
- package/dist/containers/element-model/link.js +0 -16
- package/dist/containers/element-model/table.js +0 -57
- package/dist/containers/element-model/text.js +0 -10
- package/dist/containers/render-utils/common-utils.js +0 -80
- package/dist/containers/render-utils/editor-utils.js +0 -133
- package/dist/containers/render-utils/viewer-utils.js +0 -198
- package/dist/containers/viewer-widgets/viewer-formula/index.js +0 -54
- package/dist/containers/viewer-widgets/viewer-image/index.js +0 -70
- package/dist/containers/viewer-widgets/viewer-image/viewer-image.css +0 -3
- package/dist/editors/index.js +0 -78
- package/dist/editors/markdown-editor.js +0 -206
- package/dist/editors/plain-markdown-editor.js +0 -285
- package/dist/editors/seatable-editor.js +0 -210
- package/dist/editors/simple-editor.js +0 -200
- package/dist/index.js +0 -11
- package/dist/setting.local.js +0 -14
- package/dist/utils/deserialize-html.js +0 -260
- package/dist/utils/diff/compare-strings.js +0 -35
- package/dist/utils/diff/diff.js +0 -769
- package/dist/utils/diff/index.js +0 -2
- package/dist/utils/seafile-markdown2html.js +0 -52
- package/dist/utils/slate2markdown/deserialize.js +0 -588
- package/dist/utils/slate2markdown/index.js +0 -3
- package/dist/utils/slate2markdown/serialize.js +0 -366
- package/dist/utils/utils.js +0 -68
- package/dist/viewer/diff-viewer.js +0 -85
- package/dist/viewer/index.js +0 -4
- package/dist/viewer/markdown-viewer.js +0 -121
- package/dist/viewer/seatable-viewer.js +0 -63
- package/dist/viewer/slate-viewer.js +0 -71
- package/public/index.html +0 -45
- package/public/manifest.json +0 -15
- package/public/media/seafile-logo.png +0 -0
- /package/{dist/assets/css/keyboard-shortcuts.css → src/extension/toolbar/user-help/style.css} +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
|
|
3
|
+
const textRule = (element, parseChild) => {
|
|
4
|
+
const { nodeName, nodeType } = element;
|
|
5
|
+
|
|
6
|
+
if (nodeName === 'SPAN') {
|
|
7
|
+
return {
|
|
8
|
+
id: slugid.nice(),
|
|
9
|
+
text: element.textContent,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (nodeName === 'STRONG' || nodeName === 'B') {
|
|
14
|
+
return {
|
|
15
|
+
id: slugid.nice(),
|
|
16
|
+
bold: true,
|
|
17
|
+
text: element.textContent,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (nodeName === 'CODE' && element.parentElement.nodeName !== 'PRE') {
|
|
22
|
+
return {
|
|
23
|
+
id: slugid.nice(),
|
|
24
|
+
code: true,
|
|
25
|
+
text: element.textContent
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (nodeName === 'DEL') {
|
|
30
|
+
return {
|
|
31
|
+
id: slugid.nice(),
|
|
32
|
+
delete: true,
|
|
33
|
+
text: element.textContent
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (nodeName === 'I') {
|
|
38
|
+
return {
|
|
39
|
+
id: slugid.nice(),
|
|
40
|
+
italic: true,
|
|
41
|
+
text: element.textContent
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (nodeName === 'INS') {
|
|
46
|
+
return {
|
|
47
|
+
id: slugid.nice(),
|
|
48
|
+
add: true,
|
|
49
|
+
text: element.textContent
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (nodeType === 3) {
|
|
54
|
+
return {
|
|
55
|
+
id: slugid.nice(),
|
|
56
|
+
text: element.textContent,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default textRule;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import mdStringToSlate from './md-to-slate';
|
|
2
|
+
import slateToMdString from './slate-to-md';
|
|
3
|
+
import processor from './md-to-html';
|
|
4
|
+
import deserializeHtml from './html-to-slate';
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
mdStringToSlate,
|
|
8
|
+
slateToMdString,
|
|
9
|
+
processor, // md string to html
|
|
10
|
+
deserializeHtml, // html -> slate notes
|
|
11
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import markdown from 'remark-parse';
|
|
3
|
+
import gfm from 'remark-gfm';
|
|
4
|
+
import math from 'remark-math';
|
|
5
|
+
import breaks from 'remark-breaks';
|
|
6
|
+
import remarkRehype from 'remark-rehype';
|
|
7
|
+
import mathjax from 'rehype-mathjax/browser';
|
|
8
|
+
import rehypeSlug from 'rehype-slug';
|
|
9
|
+
import rehypeRaw from 'rehype-raw';
|
|
10
|
+
import rehypeFormat from 'rehype-format';
|
|
11
|
+
import rehypeSanitize from 'rehype-sanitize';
|
|
12
|
+
import rehypeStringify from 'rehype-stringify';
|
|
13
|
+
import sanitizeSchema from './sanitize-schema';
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// mdString -> mdast -> html ast -> html
|
|
17
|
+
const processor = unified()
|
|
18
|
+
// Handles markdown basic syntax
|
|
19
|
+
// https://github.com/remarkjs/remark/tree/main
|
|
20
|
+
.use(markdown)
|
|
21
|
+
// Handle markdown extension syntax
|
|
22
|
+
// https://github.com/remarkjs/remark-gfm
|
|
23
|
+
.use(gfm)
|
|
24
|
+
// https://github.com/remarkjs/remark-math
|
|
25
|
+
.use(math)
|
|
26
|
+
// https://github.com/remarkjs/remark-breaks
|
|
27
|
+
.use(breaks)
|
|
28
|
+
.use(remarkRehype, { allowDangerousHtml: true }) // convert mdast -> hast
|
|
29
|
+
// https://www.npmjs.com/package/rehype-mathjax
|
|
30
|
+
.use(mathjax, { displayMath: ['$$', '$$'] })
|
|
31
|
+
// https://www.npmjs.com/package/rehype-raw
|
|
32
|
+
.use(rehypeRaw)
|
|
33
|
+
// https://www.npmjs.com/package/rehype-format
|
|
34
|
+
.use(rehypeFormat, { blanks: ['pre', 'code'] })
|
|
35
|
+
// https://github.com/rehypejs/rehype-slug
|
|
36
|
+
.use(rehypeSlug)
|
|
37
|
+
// https://github.com/rehypejs/rehype-sanitize
|
|
38
|
+
.use(rehypeSanitize, sanitizeSchema)
|
|
39
|
+
// https://github.com/rehypejs/rehype/tree/main/packages/rehype-stringify
|
|
40
|
+
.use(rehypeStringify);
|
|
41
|
+
|
|
42
|
+
// transform rules: https://github.com/syntax-tree/mdast-util-to-hast
|
|
43
|
+
|
|
44
|
+
export default processor;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import deepmerge from 'deepmerge';
|
|
2
|
+
import { defaultSchema } from 'hast-util-sanitize';
|
|
3
|
+
|
|
4
|
+
const customSchema = {
|
|
5
|
+
'tagNames': [
|
|
6
|
+
'input',
|
|
7
|
+
'code',
|
|
8
|
+
'span',
|
|
9
|
+
'div',
|
|
10
|
+
'blockquote',
|
|
11
|
+
'pre',
|
|
12
|
+
],
|
|
13
|
+
'attributes': {
|
|
14
|
+
'input': [
|
|
15
|
+
'type',
|
|
16
|
+
],
|
|
17
|
+
'li': [
|
|
18
|
+
'className'
|
|
19
|
+
],
|
|
20
|
+
'code': [
|
|
21
|
+
'className',
|
|
22
|
+
],
|
|
23
|
+
'span': [
|
|
24
|
+
'className'
|
|
25
|
+
],
|
|
26
|
+
'div': [
|
|
27
|
+
'className'
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
'protocols': {
|
|
31
|
+
'src': [
|
|
32
|
+
'http',
|
|
33
|
+
'https',
|
|
34
|
+
'cid',
|
|
35
|
+
],
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const sanitizeSchema = deepmerge(defaultSchema, customSchema);
|
|
40
|
+
|
|
41
|
+
export default sanitizeSchema;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import markdown from 'remark-parse';
|
|
3
|
+
import gfm from 'remark-gfm';
|
|
4
|
+
import math from 'remark-math';
|
|
5
|
+
import { generateDefaultParagraph } from '../../extension/core';
|
|
6
|
+
import { formatMdToSlate } from './transform';
|
|
7
|
+
|
|
8
|
+
// md string -> md ast
|
|
9
|
+
const getProcessor = () => {
|
|
10
|
+
const processor = unified()
|
|
11
|
+
.use(markdown) // Handles markdown basic syntax
|
|
12
|
+
.use(gfm) // Handle markdown extension syntax
|
|
13
|
+
.use(math); // Handles markdown math formulas
|
|
14
|
+
|
|
15
|
+
return processor;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const reconciledSlateNodes = (nodes) => {
|
|
19
|
+
return nodes;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// md string --> md ast --> slate ast
|
|
23
|
+
// https://github.com/syntax-tree/mdast
|
|
24
|
+
const mdStringToSlate = (mdString) => {
|
|
25
|
+
if (!mdString) return generateDefaultParagraph();
|
|
26
|
+
|
|
27
|
+
let content = mdString;
|
|
28
|
+
if (typeof mdString === 'number') {
|
|
29
|
+
content = mdString + '';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// md string --> md ast
|
|
33
|
+
const root = getProcessor().parse(content);
|
|
34
|
+
|
|
35
|
+
// md ast --> slate ast
|
|
36
|
+
const slateNodes = formatMdToSlate(root.children);
|
|
37
|
+
|
|
38
|
+
// Format the document
|
|
39
|
+
return reconciledSlateNodes(slateNodes);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default mdStringToSlate;
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import slugid from 'slugid';
|
|
2
|
+
import { generateDefaultText } from '../../extension/core';
|
|
3
|
+
import {
|
|
4
|
+
BLOCKQUOTE,
|
|
5
|
+
HEADER,
|
|
6
|
+
IMAGE,
|
|
7
|
+
LINK,
|
|
8
|
+
PARAGRAPH,
|
|
9
|
+
TABLE,
|
|
10
|
+
CODE_BLOCK,
|
|
11
|
+
LIST_ITEM,
|
|
12
|
+
ORDERED_LIST,
|
|
13
|
+
UNORDERED_LIST,
|
|
14
|
+
CHECK_LIST_ITEM,
|
|
15
|
+
CODE_LINE,
|
|
16
|
+
TABLE_ROW,
|
|
17
|
+
TABLE_CELL,
|
|
18
|
+
} from '../../extension/constants/element-types';
|
|
19
|
+
|
|
20
|
+
const INLINE_KEY_MAP = {
|
|
21
|
+
strong: 'bold',
|
|
22
|
+
emphasis: 'italic',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// <strong><em>aa<em>bb<em></strong>
|
|
26
|
+
const applyMarkForInlineItem = (result, item, textNode = {}) => {
|
|
27
|
+
const { type, children, value } = item;
|
|
28
|
+
|
|
29
|
+
if (type === LINK) {
|
|
30
|
+
const child = children.length === 0 ? { type: 'text', value: '' } : children[0];
|
|
31
|
+
const linkChildren = [{ id: slugid.nice(), text: child.value }];
|
|
32
|
+
const link = {
|
|
33
|
+
id: slugid.nice(),
|
|
34
|
+
type: LINK,
|
|
35
|
+
url: item.url,
|
|
36
|
+
title: item.title,
|
|
37
|
+
children: linkChildren,
|
|
38
|
+
};
|
|
39
|
+
result.push([
|
|
40
|
+
generateDefaultText(),
|
|
41
|
+
link,
|
|
42
|
+
generateDefaultText(),
|
|
43
|
+
]);
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (type === IMAGE) {
|
|
48
|
+
const data = {
|
|
49
|
+
src: item.url,
|
|
50
|
+
...(item.title && { title: item.title }),
|
|
51
|
+
...(item.alt && { alt: item.alt }),
|
|
52
|
+
...(item.width && { width: item.width }),
|
|
53
|
+
...(item.height && { height: item.height }),
|
|
54
|
+
};
|
|
55
|
+
const image = {
|
|
56
|
+
id: slugid.nice(),
|
|
57
|
+
data: data,
|
|
58
|
+
type: IMAGE,
|
|
59
|
+
children: [generateDefaultText()]
|
|
60
|
+
};
|
|
61
|
+
result.push([
|
|
62
|
+
generateDefaultText(),
|
|
63
|
+
image,
|
|
64
|
+
generateDefaultText(),
|
|
65
|
+
]);
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Handle special images
|
|
70
|
+
if (type === 'html') {
|
|
71
|
+
const nodes = transformHtml(item);
|
|
72
|
+
result.push(nodes);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (type === 'text') {
|
|
77
|
+
textNode['text'] = value || '';
|
|
78
|
+
result.push(textNode);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (type === 'inlineCode') {
|
|
83
|
+
textNode['code'] = true;
|
|
84
|
+
textNode['text'] = value || '';
|
|
85
|
+
result.push(textNode);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const attr_key = INLINE_KEY_MAP[type];
|
|
90
|
+
if (!Array.isArray(children) || children.length === 0 || !attr_key) {
|
|
91
|
+
textNode['text'] = value || '';
|
|
92
|
+
result.push(textNode);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
textNode[attr_key] = true;
|
|
97
|
+
children.forEach(item => {
|
|
98
|
+
applyMarkForInlineItem(result, item, textNode);
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const transformNodeWithInlineChildren = (node) => {
|
|
103
|
+
const { children } = node;
|
|
104
|
+
const defaultChildren = [generateDefaultText()];
|
|
105
|
+
if (!children || !Array.isArray(children) || children.length === 0) {
|
|
106
|
+
return defaultChildren;
|
|
107
|
+
}
|
|
108
|
+
const result = [];
|
|
109
|
+
children.forEach(item => applyMarkForInlineItem(result, item));
|
|
110
|
+
return result.flat();
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const transformHeader = (node) => {
|
|
114
|
+
const { depth } = node;
|
|
115
|
+
const type = `${HEADER}${depth}`;
|
|
116
|
+
return {
|
|
117
|
+
id: slugid.nice(),
|
|
118
|
+
type: type,
|
|
119
|
+
children: transformNodeWithInlineChildren(node),
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const transformParagraph = (node) => {
|
|
124
|
+
return {
|
|
125
|
+
id: slugid.nice(),
|
|
126
|
+
type: PARAGRAPH,
|
|
127
|
+
children: transformNodeWithInlineChildren(node),
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const transformBlockquote = (node) => {
|
|
132
|
+
const { children } = node;
|
|
133
|
+
return {
|
|
134
|
+
id: slugid.nice(),
|
|
135
|
+
type: BLOCKQUOTE,
|
|
136
|
+
children: children.map(child => {
|
|
137
|
+
const handler = elementHandlers[child.type];
|
|
138
|
+
return handler(child);
|
|
139
|
+
}).flat(), // flat
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export const transformListContent = (node) => {
|
|
144
|
+
return {
|
|
145
|
+
id: slugid.nice(),
|
|
146
|
+
type: PARAGRAPH,
|
|
147
|
+
children: transformNodeWithInlineChildren(node),
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export const transformListItem = (node) => {
|
|
152
|
+
const { children } = node;
|
|
153
|
+
return {
|
|
154
|
+
id: slugid.nice(),
|
|
155
|
+
type: LIST_ITEM,
|
|
156
|
+
// eslint-disable-next-line array-callback-return
|
|
157
|
+
children: children.map(child => {
|
|
158
|
+
if (child.type === PARAGRAPH) {
|
|
159
|
+
return transformListContent(child);
|
|
160
|
+
} else {
|
|
161
|
+
return transformList(child);
|
|
162
|
+
}
|
|
163
|
+
}),
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export const transformOrderedList = (node) => {
|
|
168
|
+
const { children } = node;
|
|
169
|
+
return {
|
|
170
|
+
id: slugid.nice(),
|
|
171
|
+
type: ORDERED_LIST,
|
|
172
|
+
children: children.map(child => transformListItem(child)),
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export const transformUnorderedList = (node) => {
|
|
177
|
+
const { children } = node;
|
|
178
|
+
return {
|
|
179
|
+
id: slugid.nice(),
|
|
180
|
+
type: UNORDERED_LIST,
|
|
181
|
+
children: children.map(child => transformListItem(child)),
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export const transformCheckListItem = (node) => {
|
|
186
|
+
const { children, checked } = node;
|
|
187
|
+
return {
|
|
188
|
+
id: slugid.nice(),
|
|
189
|
+
type: CHECK_LIST_ITEM,
|
|
190
|
+
checked: checked,
|
|
191
|
+
children: children.map(child => transformNodeWithInlineChildren(child)).flat()
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export const transformCheckList = (node) => {
|
|
196
|
+
const { children } = node;
|
|
197
|
+
return children.map(child => transformCheckListItem(child));
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export const transformList = (node) => {
|
|
201
|
+
const { ordered, children } = node;
|
|
202
|
+
const firstChild = children[0];
|
|
203
|
+
if (ordered === true) {
|
|
204
|
+
return transformOrderedList(node);
|
|
205
|
+
}
|
|
206
|
+
if (ordered === false && firstChild.checked === null) {
|
|
207
|
+
return transformUnorderedList(node);
|
|
208
|
+
}
|
|
209
|
+
return transformCheckList(node);
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export const transformTableCell = (cell, align) => {
|
|
213
|
+
return {
|
|
214
|
+
id: slugid.nice(),
|
|
215
|
+
type: TABLE_CELL,
|
|
216
|
+
align: align || null,
|
|
217
|
+
children: transformNodeWithInlineChildren(cell),
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export const transformTableRow = (row, align) => {
|
|
222
|
+
const { children: cells } = row;
|
|
223
|
+
return {
|
|
224
|
+
id: slugid.nice(),
|
|
225
|
+
type: TABLE_ROW,
|
|
226
|
+
children: cells.map(cell => transformTableCell(cell, align)),
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export const transformTable = (node) => {
|
|
231
|
+
const { children: rows, align = [] } = node;
|
|
232
|
+
return {
|
|
233
|
+
id: slugid.nice(),
|
|
234
|
+
type: TABLE,
|
|
235
|
+
children: rows.map((row, index) => transformTableRow(row, align[index])),
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
export const transformCodeLine = (text) => {
|
|
240
|
+
return {
|
|
241
|
+
id: slugid.nice(),
|
|
242
|
+
type: CODE_LINE,
|
|
243
|
+
children: [
|
|
244
|
+
{
|
|
245
|
+
id: slugid.nice(),
|
|
246
|
+
text: text,
|
|
247
|
+
}
|
|
248
|
+
]
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export const transformCodeBlock = (node) => {
|
|
253
|
+
const { lang, value } = node;
|
|
254
|
+
const children = value.split('\n');
|
|
255
|
+
return {
|
|
256
|
+
id: slugid.nice(),
|
|
257
|
+
type: CODE_BLOCK,
|
|
258
|
+
lang: lang,
|
|
259
|
+
children: children.map(text => transformCodeLine(text)),
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
export const transformHr = (node) => {
|
|
264
|
+
return {
|
|
265
|
+
id: slugid.nice(),
|
|
266
|
+
type: 'hr',
|
|
267
|
+
children: [
|
|
268
|
+
generateDefaultText(),
|
|
269
|
+
]
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export const transformHtml = (node) => {
|
|
274
|
+
const defaultTextNode = generateDefaultText();
|
|
275
|
+
if (node.value.slice(0, 4).toLowerCase() === '<img') {
|
|
276
|
+
const { body } = new DOMParser().parseFromString(node.value, 'text/html');
|
|
277
|
+
const img = body.firstChild;
|
|
278
|
+
const src = img.getAttribute('src');
|
|
279
|
+
if (src) return defaultTextNode;
|
|
280
|
+
|
|
281
|
+
const alt = img.getAttribute('alt');
|
|
282
|
+
const title = img.getAttribute('title');
|
|
283
|
+
const width = img.getAttribute('width');
|
|
284
|
+
const height = img.getAttribute('height');
|
|
285
|
+
const data = {
|
|
286
|
+
src: src,
|
|
287
|
+
...(alt && { alt }),
|
|
288
|
+
...(title && { title }),
|
|
289
|
+
...(!isNaN(width) && width > 0 && { width }),
|
|
290
|
+
...(!isNaN(height) && height > 0 && { height }),
|
|
291
|
+
};
|
|
292
|
+
const image = {
|
|
293
|
+
id: slugid.nice(),
|
|
294
|
+
data: data,
|
|
295
|
+
type: IMAGE,
|
|
296
|
+
children: [generateDefaultText()]
|
|
297
|
+
};
|
|
298
|
+
return [defaultTextNode, image, defaultTextNode];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return defaultTextNode;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
export const transformMath = (node) => {
|
|
305
|
+
return {
|
|
306
|
+
id: slugid.nice(),
|
|
307
|
+
type: 'formula',
|
|
308
|
+
data: {
|
|
309
|
+
formula: node.value
|
|
310
|
+
},
|
|
311
|
+
children: [
|
|
312
|
+
generateDefaultText(),
|
|
313
|
+
]
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const elementHandlers = {
|
|
318
|
+
'paragraph': transformParagraph,
|
|
319
|
+
'heading': transformHeader,
|
|
320
|
+
'blockquote': transformBlockquote,
|
|
321
|
+
'table': transformTable,
|
|
322
|
+
'list': transformList, // ordered_list | unordered_list | check_list_item
|
|
323
|
+
'code': transformCodeBlock,
|
|
324
|
+
'thematicBreak': transformHr,
|
|
325
|
+
'math': transformMath,
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
export const formatMdToSlate = (children) => {
|
|
329
|
+
const validChildren = children.filter(child => elementHandlers[child.type]);
|
|
330
|
+
return validChildren.map(child => {
|
|
331
|
+
const handler = elementHandlers[child.type];
|
|
332
|
+
return handler(child);
|
|
333
|
+
}).flat();
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import markdown from 'remark-parse';
|
|
3
|
+
import gfm from 'remark-gfm';
|
|
4
|
+
import remarkStringify from 'remark-stringify';
|
|
5
|
+
import remarkMath from 'remark-math';
|
|
6
|
+
import { formatSlateToMd } from './transform';
|
|
7
|
+
|
|
8
|
+
const isContentValid = (value) => {
|
|
9
|
+
if (!value || !Array.isArray(value)) return false;
|
|
10
|
+
return true;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// slateNode -> mdast -> mdString
|
|
14
|
+
const slateToMdString = (value) => {
|
|
15
|
+
if (!isContentValid(value)) return '';
|
|
16
|
+
// slateNode -> mdast
|
|
17
|
+
// https://github.com/syntax-tree/mdast#phrasingcontent
|
|
18
|
+
const mdASTNodes = formatSlateToMd(value);
|
|
19
|
+
|
|
20
|
+
const root = {
|
|
21
|
+
type: 'root',
|
|
22
|
+
children: mdASTNodes
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// convert slate value to md
|
|
26
|
+
const stringifyOptions = {
|
|
27
|
+
rule: '-',
|
|
28
|
+
ruleSpaces: false,
|
|
29
|
+
bullet: '*',
|
|
30
|
+
commonmarks: true,
|
|
31
|
+
fences: true,
|
|
32
|
+
};
|
|
33
|
+
const res = unified()
|
|
34
|
+
.use(markdown)
|
|
35
|
+
.use(gfm)
|
|
36
|
+
.use(remarkStringify, stringifyOptions)
|
|
37
|
+
.use(remarkMath)
|
|
38
|
+
.stringify(root);
|
|
39
|
+
return res;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// transform rules: https://github.com/syntax-tree/mdast
|
|
43
|
+
|
|
44
|
+
export default slateToMdString;
|