diff --git a/app/src/assets/scss/component/_typography.scss b/app/src/assets/scss/component/_typography.scss index b6fc06126..4fa83500c 100644 --- a/app/src/assets/scss/component/_typography.scss +++ b/app/src/assets/scss/component/_typography.scss @@ -304,7 +304,6 @@ } .hljs { - border-radius: var(--b3-border-radius); font-size: 85%; overflow: auto; font-family: var(--b3-font-family-code); diff --git a/app/src/protyle/render/highlightRender.ts b/app/src/protyle/render/highlightRender.ts index f13289815..bf80cf537 100644 --- a/app/src/protyle/render/highlightRender.ts +++ b/app/src/protyle/render/highlightRender.ts @@ -86,18 +86,17 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) = } else { block.style.fontVariantLigatures = "none"; } - const codeText = block.textContent; + const codeText = block.lastElementChild.textContent; if (!isPreview && (lineNumber === "true" || (lineNumber !== "false" && window.siyuan.config.editor.codeSyntaxHighlightLineNum))) { // 需要先添加 class 以防止抖动 https://ld246.com/article/1648116585443 - block.firstElementChild.classList.add("protyle-linenumber__rows"); + block.firstElementChild.className = "protyle-linenumber__rows"; block.firstElementChild.setAttribute("contenteditable", "false"); lineNumberRender(block); } else { - block.firstElementChild.classList.remove("protyle-linenumber__rows"); + block.firstElementChild.className = "fn__none"; block.firstElementChild.innerHTML = ""; } - - (block.childElementCount === 2 ? block.lastElementChild : block).innerHTML = window.hljs.highlight( + block.lastElementChild.innerHTML = window.hljs.highlight( codeText + (codeText.endsWith("\n") ? "" : "\n"), // https://github.com/siyuan-note/siyuan/issues/4609 { language,