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

This commit is contained in:
cherishsince 2024-05-21 22:43:50 +08:00
parent a96a2ec9ec
commit 63638ce4a1

View File

@ -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>`
}