From c810f81fc1c68f68f2806fcb6c60288c09aaf236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=83=9C?= <244212647@qq.com> Date: Fri, 19 Apr 2024 13:18:14 +0800 Subject: [PATCH] =?UTF-8?q?cherry=20markdown=E6=94=AF=E6=8C=81=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=9B=BE=E7=89=87pdf=E4=BB=A5=E5=8F=8Aword=20(#936)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: first open document, cherryMarkdown not have theme * fix: modify prismjs style and improve image clarity * update cherry-markdown * optimiztion: cherry-markdown * feat: cherry-markdown add auto-save and update icon * fix: the mobile phone displays abnormally and Markdown does not allow conversion * fix: cherry display not complete * support upload pdf&word&picture * support upload pdf&word&picture --------- Co-authored-by: zhangsheng.93 --- static/css/markdown.css | 12 +- static/js/cherry_markdown.js | 114 +++++------------- .../cherry_markdown_edit_template.tpl | 9 +- 3 files changed, 42 insertions(+), 93 deletions(-) diff --git a/static/css/markdown.css b/static/css/markdown.css index 345b0297..3bd1b285 100644 --- a/static/css/markdown.css +++ b/static/css/markdown.css @@ -454,6 +454,10 @@ body .scrollbar-track-color { overflow-y: auto; } +.markdown-category .editor-status.markdown-tree { + bottom: 30px !important; +} + .markdown-category .markdown-nav .nav-item { font-size: 14px; padding: 0 9px; @@ -566,7 +570,7 @@ iframe.cherry-dialog-iframe { } @media screen and (max-width: 839px) { - .toc { - display: none !important; - } -} + .toc { + display: none !important; + } +} \ No newline at end of file diff --git a/static/js/cherry_markdown.js b/static/js/cherry_markdown.js index bfd36405..6b806254 100644 --- a/static/js/cherry_markdown.js +++ b/static/js/cherry_markdown.js @@ -140,6 +140,7 @@ $(function () { MathJax: window.MathJax, }, isPreviewOnly: false, + fileUpload: myFileUpload, engine: { global: { urlProcessor(url, srcType) { @@ -261,19 +262,6 @@ $(function () { resetEditorChanged(true); }); openLastSelectedNode(); - uploadImage("manualEditorContainer", function ($state, $res) { - console.log("注册上传图片") - if ($state === "before") { - return layer.load(1, { - shade: [0.1, '#fff'] // 0.1 透明度的白色背景 - }); - } else if ($state === "success") { - if ($res.errcode === 0) { - var value = '![](' + $res.url + ')'; - window.editor.insertValue(value); - } - } - }); }); /*** @@ -519,6 +507,7 @@ $(function () { } }, 'core': { + 'worker':true, 'check_callback': true, "multiple": false, 'animation': 0, @@ -614,77 +603,36 @@ $(function () { }); }); -function uploadImage($id, $callback) { - locales = { - 'zh-CN': { - unsupportType: '不支持的图片格式', - uploadFailed: '图片上传失败' +function myFileUpload(file, callback) { + // 创建 FormData 对象以便包含要上传的文件 + var formData = new FormData(); + formData.append("editormd-file-file", file); // "file" 是与你的服务端接口相对应的字段名 + var layerIndex = 0; + // AJAX 请求 + $.ajax({ + url: window.fileUploadURL, // 确保此 URL 是文件上传 API 的正确 URL + type: "POST", + dataType: "json", + data: formData, + processData: false, // 必须设置为 false,因为数据是 FormData 对象,不需要对数据进行序列化处理 + contentType: false, // 必须设置为 false,因为是 FormData 对象,jQuery 将不会设置内容类型头 + + beforeSend: function () { + layerIndex = layer.load(1, { + shade: [0.1, '#fff'] // 0.1 透明度的白色背景 + }); }, - 'en': { - unsupportType: 'Unsupport image type', - uploadFailed: 'Upload image failed' - } - } - /** 粘贴上传图片 **/ - document.getElementById($id).addEventListener('paste', function (e) { - if (e.clipboardData && e.clipboardData.items) { - var clipboard = e.clipboardData; - for (var i = 0, len = clipboard.items.length; i < len; i++) { - if (clipboard.items[i].kind === 'file' || clipboard.items[i].type.indexOf('image') > -1) { - - var imageFile = clipboard.items[i].getAsFile(); - - var fileName = String((new Date()).valueOf()); - - switch (imageFile.type) { - case "image/png" : - fileName += ".png"; - break; - case "image/jpg" : - fileName += ".jpg"; - break; - case "image/jpeg" : - fileName += ".jpeg"; - break; - case "image/gif" : - fileName += ".gif"; - break; - default : - layer.msg(locales[lang].unsupportType); - return; - } - var form = new FormData(); - - form.append('editormd-image-file', imageFile, fileName); - - var layerIndex = 0; - - $.ajax({ - url: window.imageUploadURL, - type: "POST", - dataType: "json", - data: form, - processData: false, - contentType: false, - beforeSend: function () { - layerIndex = $callback('before'); - }, - error: function () { - layer.close(layerIndex); - $callback('error'); - layer.msg(locales[lang].uploadFailed); - }, - success: function (data) { - layer.close(layerIndex); - $callback('success', data); - if (data.errcode !== 0) { - layer.msg(data.message); - } - - } - }); - e.preventDefault(); - } + + error: function () { + layer.close(layerIndex); + layer.msg(locales[lang].uploadFailed); + }, + success: function (data) { + layer.close(layerIndex); + if (data.errcode !== 0) { + layer.msg(data.message); + } else { + callback(data.url); // 假设返回的 JSON 中包含上传文件的 URL,调用回调函数并传入 URL } } }); diff --git a/views/document/cherry_markdown_edit_template.tpl b/views/document/cherry_markdown_edit_template.tpl index ea80a673..26bcd3f4 100755 --- a/views/document/cherry_markdown_edit_template.tpl +++ b/views/document/cherry_markdown_edit_template.tpl @@ -64,16 +64,13 @@
- - -
-
-
-
+
0 {{i18n .Lang "doc.attachments"}}
+
+