Procházet zdrojové kódy

【优化】try mkardown 组件异常,因为 stream 模型可能返回的信息不全

cherishsince před 1 rokem
rodič
revize
63638ce4a1
1 změnil soubory, kde provedl 6 přidání a 1 odebrání
  1. 6 1
      src/components/MarkdownView/index.vue

+ 6 - 1
src/components/MarkdownView/index.vue

@@ -20,7 +20,12 @@ const contentRef = ref()
 // marked 渲染器
 const renderer = {
   code(code, language, c) {
-    const highlightHtml = hljs.highlight(code, {language: language, ignoreIllegals: true}).value
+    let highlightHtml
+    try {
+      highlightHtml = hljs.highlight(code, {language: language, ignoreIllegals: true}).value
+    } catch (e) {
+      // skip
+    }
     const copyHtml = `<div id="copy" data-copy='${code}' style="position: absolute; right: 10px; top: 5px; color: #fff;cursor: pointer;">复制</div>`
     return `<pre style="position: relative;">${copyHtml}<code class="hljs">${highlightHtml}</code></pre>`
   }