Liyuan Li 5 tahun lalu
induk
melakukan
51d35517d8
4 mengubah file dengan 20 tambahan dan 11 penghapusan
  1. 1 0
      CHANGELOG.md
  2. 10 4
      demo/index.html
  3. 2 2
      src/ts/upload/index.ts
  4. 7 5
      src/ts/util/processCode.ts

+ 1 - 0
CHANGELOG.md

@@ -68,6 +68,7 @@
 
 
 ### v3.3.5 / 2020-07-xx
 ### v3.3.5 / 2020-07-xx
 
 
+* [549](https://github.com/Vanessa219/vditor/issues/549) 粘贴 HTML 内容失败 `修复缺陷`
 * [548](https://github.com/Vanessa219/vditor/issues/548) 添加文件上传多选/单选配置 `引入特性`
 * [548](https://github.com/Vanessa219/vditor/issues/548) 添加文件上传多选/单选配置 `引入特性`
 * [545](https://github.com/Vanessa219/vditor/issues/545) SV 模式列表项下输入代码块问题 `修复缺陷`
 * [545](https://github.com/Vanessa219/vditor/issues/545) SV 模式列表项下输入代码块问题 `修复缺陷`
 * [544](https://github.com/Vanessa219/vditor/issues/544) SV 模式有序列表缩进问题 `修复缺陷`
 * [544](https://github.com/Vanessa219/vditor/issues/544) SV 模式有序列表缩进问题 `修复缺陷`

+ 10 - 4
demo/index.html

@@ -8,7 +8,8 @@
     <meta name="apple-mobile-web-app-capable" content="yes">
     <meta name="apple-mobile-web-app-capable" content="yes">
     <meta name="mobile-web-app-capable" content="yes"/>
     <meta name="mobile-web-app-capable" content="yes"/>
     <meta name="apple-mobile-web-app-status-bar-style" content="black">
     <meta name="apple-mobile-web-app-status-bar-style" content="black">
-    <title>Vditor: ♏ An In-browser Markdown editor, support WYSIWYG,  Instant Rendering (Typora-like) and Split View modes. 一款浏览器端的 Markdown 编辑器,支持所见即所得、即时渲染(类似 Typora)和分屏预览模式。</title>
+    <title>Vditor: ♏ An In-browser Markdown editor, support WYSIWYG, Instant Rendering (Typora-like) and Split View
+        modes. 一款浏览器端的 Markdown 编辑器,支持所见即所得、即时渲染(类似 Typora)和分屏预览模式。</title>
     <meta name="description"
     <meta name="description"
           content="Vditor 支持三种所见即所得(wysiwyg)、即时渲染(ir)、分屏预览(sv)模式,支持大纲、数学公式、脑图、图表、流程图、甘特图、时序图、五线谱、多媒体、语音阅读、标题锚点、代码高亮及复制、graphviz 渲染。"/>
           content="Vditor 支持三种所见即所得(wysiwyg)、即时渲染(ir)、分屏预览(sv)模式,支持大纲、数学公式、脑图、图表、流程图、甘特图、时序图、五线谱、多媒体、语音阅读、标题锚点、代码高亮及复制、graphviz 渲染。"/>
     <meta property="og:description"
     <meta property="og:description"
@@ -23,7 +24,8 @@
     <meta name="copyright" content="B3log"/>
     <meta name="copyright" content="B3log"/>
     <meta http-equiv="Window-target" content="_top"/>
     <meta http-equiv="Window-target" content="_top"/>
     <meta property="og:locale" content="zh-cmn-Hans"/>
     <meta property="og:locale" content="zh-cmn-Hans"/>
-    <meta property="og:title" content="Vditor: ♏ An In-browser Markdown editor, support WYSIWYG,  Instant Rendering (Typora-like) and Split View modes. 一款浏览器端的 Markdown 编辑器,支持所见即所得、即时渲染(类似 Typora)和分屏预览模式。"/>
+    <meta property="og:title"
+          content="Vditor: ♏ An In-browser Markdown editor, support WYSIWYG,  Instant Rendering (Typora-like) and Split View modes. 一款浏览器端的 Markdown 编辑器,支持所见即所得、即时渲染(类似 Typora)和分屏预览模式。"/>
     <meta property="og:site_name" content="Blog-vditor"/>
     <meta property="og:site_name" content="Blog-vditor"/>
     <meta property="og:url" content="https://vditor.b3log.org"/>
     <meta property="og:url" content="https://vditor.b3log.org"/>
     <meta name="twitter:card" content="summary"/>
     <meta name="twitter:card" content="summary"/>
@@ -45,8 +47,12 @@
 <h2>
 <h2>
     <a href="https://vditor.b3log.org" target="_blank">官网</a> |
     <a href="https://vditor.b3log.org" target="_blank">官网</a> |
     <a href="/render.html">Render</a> |
     <a href="/render.html">Render</a> |
-    <button onclick="window.vditor.setTheme('dark', 'dark',  'native');document.querySelector('body').style.backgroundColor='#2f363d'">Dark Mode</button>
-    <button onclick="window.vditor.setTheme('light', 'light', 'github');document.querySelector('body').style.backgroundColor=''">Light Mode</button>
+    <button onclick="window.vditor.setTheme('dark', 'dark',  'native');document.querySelector('body').style.backgroundColor='#2f363d'">
+        Dark Mode
+    </button>
+    <button onclick="window.vditor.setTheme('light', 'light', 'github');document.querySelector('body').style.backgroundColor=''">
+        Light Mode
+    </button>
 </h2>
 </h2>
 <div id="vditor">
 <div id="vditor">
 <h1>Vditor</h1>
 <h1>Vditor</h1>

+ 2 - 2
src/ts/upload/index.ts

@@ -141,8 +141,8 @@ const genUploadedLabel = (responseText: string, vditor: IVditor) => {
 const uploadFiles = (vditor: IVditor, files: FileList | DataTransferItemList | File[], element?: HTMLInputElement) => {
 const uploadFiles = (vditor: IVditor, files: FileList | DataTransferItemList | File[], element?: HTMLInputElement) => {
     // FileList | DataTransferItemList | File[] => File[]
     // FileList | DataTransferItemList | File[] => File[]
     let fileList = [];
     let fileList = [];
-    const iMax = vditor.options.upload.multiple === true ? files.length : 1;
-    for (let i = 0; i < iMax; i++) {
+    const filesMax = vditor.options.upload.multiple === true ? files.length : 1;
+    for (let i = 0; i < filesMax; i++) {
         let fileItem = files[i];
         let fileItem = files[i];
         if (fileItem instanceof DataTransferItem) {
         if (fileItem instanceof DataTransferItem) {
             fileItem = fileItem.getAsFile();
             fileItem = fileItem.getAsFile();

+ 7 - 5
src/ts/util/processCode.ts

@@ -27,6 +27,11 @@ export const processPasteCode = (html: string, text: string, type = "sv") => {
         // Xcode
         // Xcode
         isCode = true;
         isCode = true;
     }
     }
+    if (tempElement.childElementCount === 1 && tempElement.firstElementChild.tagName === "TABLE" &&
+        tempElement.querySelector(".line-number") && tempElement.querySelector(".line-content")) {
+        // 网页源码
+        isCode = true;
+    }
 
 
     if (isCode) {
     if (isCode) {
         const code = text || html;
         const code = text || html;
@@ -35,10 +40,7 @@ export const processPasteCode = (html: string, text: string, type = "sv") => {
                 return `<div class="vditor-wysiwyg__block" data-block="0" data-type="code-block"><pre><code>${
                 return `<div class="vditor-wysiwyg__block" data-block="0" data-type="code-block"><pre><code>${
                     code.replace(/&/g, "&amp;").replace(/</g, "&lt;")}<wbr></code></pre></div>`;
                     code.replace(/&/g, "&amp;").replace(/</g, "&lt;")}<wbr></code></pre></div>`;
             }
             }
-            if (type === "ir") {
-                return "```\n" + code.replace(/&/g, "&amp;").replace(/</g, "&lt;") + "\n```";
-            }
-            return "```\n" + code + "\n```";
+            return "```\n" + code.replace(/&/g, "&amp;").replace(/</g, "&lt;") + "\n```";
         } else {
         } else {
             if (type === "wysiwyg") {
             if (type === "wysiwyg") {
                 return `<code>${code.replace(/&/g, "&amp;").replace(/</g, "&lt;")}</code><wbr>`;
                 return `<code>${code.replace(/&/g, "&amp;").replace(/</g, "&lt;")}</code><wbr>`;
@@ -69,7 +71,7 @@ export const processCodeRender = (previewPanel: HTMLElement, vditor: IVditor) =>
         mermaidRender(previewPanel, `.vditor-${vditor.currentMode}__preview .language-mermaid`, vditor.options.cdn);
         mermaidRender(previewPanel, `.vditor-${vditor.currentMode}__preview .language-mermaid`, vditor.options.cdn);
     } else if (language === "echarts") {
     } else if (language === "echarts") {
         chartRender(previewPanel, vditor.options.cdn);
         chartRender(previewPanel, vditor.options.cdn);
-    }  else if (language === "mindmap") {
+    } else if (language === "mindmap") {
         mindmapRender(previewPanel, vditor.options.cdn);
         mindmapRender(previewPanel, vditor.options.cdn);
     } else if (language === "graphviz") {
     } else if (language === "graphviz") {
         graphvizRender(previewPanel, vditor.options.cdn);
         graphvizRender(previewPanel, vditor.options.cdn);