Vanessa 5 năm trước cách đây
mục cha
commit
15e6c75238
3 tập tin đã thay đổi với 20 bổ sung14 xóa
  1. 1 0
      CHANGELOG.md
  2. 1 1
      demo/index.js
  3. 18 13
      src/ts/undo/index.ts

+ 1 - 0
CHANGELOG.md

@@ -88,6 +88,7 @@
 
 ### v3.7.1 / 2020-12-0x
 
+* [835](https://github.com/Vanessa219/vditor/issues/835) 历史性能优化 `改进功能`
 * [837](https://github.com/Vanessa219/vditor/issues/837) 历史记录添加时间间隔配置 `引入特性`
 * 文档修改
   * 3.7.1

+ 1 - 1
demo/index.js

@@ -66,7 +66,7 @@ window.vditor = new Vditor('vditor', {
       footnotes: true,
     },
     math: {
-      engine: 'MathJax',
+      engine: 'KaTeX',
     },
   },
   toolbarConfig: {

+ 18 - 13
src/ts/undo/index.ts

@@ -1,6 +1,4 @@
 import DiffMatchPatch, {diff_match_patch, patch_obj} from "diff-match-patch";
-import {chartRender} from "../markdown/chartRender";
-import {mindmapRender} from "../markdown/mindmapRender";
 import {disableToolbar, enableToolbar, hidePanel} from "../toolbar/setToolbar";
 import {isFirefox, isSafari} from "../util/compatibility";
 import {scrollCenter} from "../util/editorCommonEvent";
@@ -174,17 +172,8 @@ class Undo {
         });
         highlightToolbar(vditor);
 
-        vditor.ir.element.querySelectorAll(".vditor-ir__preview .language-echarts").forEach((item: HTMLElement) => {
-            item.innerHTML = item.parentElement.previousElementSibling.firstElementChild.innerHTML;
-            item.removeAttribute("_echarts_instance_");
-            item.removeAttribute("data-processed");
-            chartRender(item.parentElement, vditor.options.cdn, vditor.options.theme);
-        });
-        vditor.ir.element.querySelectorAll(".vditor-ir__preview .language-mindmap").forEach((item: HTMLElement) => {
-            item.innerHTML = item.parentElement.previousElementSibling.firstElementChild.innerHTML;
-            item.removeAttribute("_echarts_instance_");
-            item.removeAttribute("data-processed");
-            mindmapRender(item.parentElement, vditor.options.cdn, vditor.options.theme);
+        vditor[vditor.currentMode].element.querySelectorAll(`.vditor-${vditor.currentMode}__preview[data-render='2']`).forEach((item: HTMLElement) => {
+            processCodeRender(item, vditor);
         });
 
         if (this[vditor.currentMode].undoStack.length > 1) {
@@ -232,6 +221,22 @@ class Undo {
                 range.insertNode(wbrElement);
             }
         }
+        // 移除数学公式、echart 渲染 https://github.com/siyuan-note/siyuan/issues/537
+        const cloneElement = vditor.ir.element.cloneNode(true) as HTMLElement;
+        cloneElement.querySelectorAll(`.vditor-${vditor.currentMode}__preview[data-render='1']`).forEach((item: HTMLElement) => {
+            if (item.firstElementChild.classList.contains("language-echarts") ||
+                item.firstElementChild.classList.contains("language-mindmap")) {
+                item.firstElementChild.removeAttribute("_echarts_instance_");
+                item.firstElementChild.removeAttribute("data-processed");
+                item.firstElementChild.innerHTML = item.previousElementSibling.firstElementChild.innerHTML;
+                item.setAttribute("data-render", "2");
+            }
+            if (item.firstElementChild.classList.contains("language-math")) {
+                item.setAttribute("data-render", "2");
+                item.firstElementChild.textContent = item.firstElementChild.getAttribute("data-math");
+                item.firstElementChild.removeAttribute("data-math");
+            }
+        });
         const text = vditor[vditor.currentMode].element.innerHTML;
         vditor[vditor.currentMode].element.querySelectorAll(".vditor-wbr").forEach((item) => {
             item.remove();