This commit is contained in:
Vanessa 2024-08-29 11:52:27 +08:00
parent 0ac17d30f7
commit 17d1316268
2 changed files with 4 additions and 6 deletions

View File

@ -304,7 +304,6 @@
} }
.hljs { .hljs {
border-radius: var(--b3-border-radius);
font-size: 85%; font-size: 85%;
overflow: auto; overflow: auto;
font-family: var(--b3-font-family-code); font-family: var(--b3-font-family-code);

View File

@ -86,18 +86,17 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
} else { } else {
block.style.fontVariantLigatures = "none"; block.style.fontVariantLigatures = "none";
} }
const codeText = block.textContent; const codeText = block.lastElementChild.textContent;
if (!isPreview && (lineNumber === "true" || (lineNumber !== "false" && window.siyuan.config.editor.codeSyntaxHighlightLineNum))) { if (!isPreview && (lineNumber === "true" || (lineNumber !== "false" && window.siyuan.config.editor.codeSyntaxHighlightLineNum))) {
// 需要先添加 class 以防止抖动 https://ld246.com/article/1648116585443 // 需要先添加 class 以防止抖动 https://ld246.com/article/1648116585443
block.firstElementChild.classList.add("protyle-linenumber__rows"); block.firstElementChild.className = "protyle-linenumber__rows";
block.firstElementChild.setAttribute("contenteditable", "false"); block.firstElementChild.setAttribute("contenteditable", "false");
lineNumberRender(block); lineNumberRender(block);
} else { } else {
block.firstElementChild.classList.remove("protyle-linenumber__rows"); block.firstElementChild.className = "fn__none";
block.firstElementChild.innerHTML = ""; block.firstElementChild.innerHTML = "";
} }
block.lastElementChild.innerHTML = window.hljs.highlight(
(block.childElementCount === 2 ? block.lastElementChild : block).innerHTML = window.hljs.highlight(
codeText + (codeText.endsWith("\n") ? "" : "\n"), // https://github.com/siyuan-note/siyuan/issues/4609 codeText + (codeText.endsWith("\n") ? "" : "\n"), // https://github.com/siyuan-note/siyuan/issues/4609
{ {
language, language,