Vanessa 2025-04-29 17:20:51 +08:00
parent 6892ebf164
commit aa4eb5ba9e
2 changed files with 5 additions and 5 deletions

View File

@ -323,7 +323,7 @@ const renderPDF = async (id: string) => {
item.parentElement.style.width = Math.min(item.parentElement.clientWidth, width) + "px";
item.removeAttribute('data-render');
})
Protyle.highlightRender(previewElement, "${servePath}/stage/protyle");
Protyle.highlightRender(previewElement, "${servePath}/stage/protyle", document.querySelector("#scale").value);
previewElement.querySelectorAll('[data-type="NodeMathBlock"]').forEach((item) => {
// 超级块内不能移除 width https://github.com/siyuan-note/siyuan/issues/14318
item.removeAttribute('data-render');

View File

@ -3,7 +3,7 @@ import {Constants} from "../../constants";
import {focusByOffset} from "../util/selection";
import {setCodeTheme} from "../../util/assets";
export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) => {
export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN, zoom = 1) => {
let codeElements: NodeListOf<Element>;
let isPreview = false;
if (element.classList.contains("code-block")) {
@ -93,7 +93,7 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
// 需要先添加 class 以防止抖动 https://ld246.com/article/1648116585443
block.firstElementChild.className = "protyle-linenumber__rows";
block.firstElementChild.setAttribute("contenteditable", "false");
lineNumberRender(block);
lineNumberRender(block, zoom);
block.style.display = "";
} else {
block.firstElementChild.className = "fn__none";
@ -116,7 +116,7 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
});
};
export const lineNumberRender = (block: HTMLElement) => {
export const lineNumberRender = (block: HTMLElement, zoom = 1) => {
const lineNumber = block.parentElement.getAttribute("lineNumber");
if (lineNumber === "false") {
return;
@ -140,7 +140,7 @@ export const lineNumberRender = (block: HTMLElement) => {
lineNumberTemp.className = "hljs";
// 不能使用 codeElement.clientWidth被忽略小数点导致宽度不一致
lineNumberTemp.setAttribute("style", `padding-left:${codeElement.style.paddingLeft};
width: ${codeElement.getBoundingClientRect().width}px;
width: ${codeElement.getBoundingClientRect().width / zoom}px;
white-space:${codeElement.style.whiteSpace};
word-break:${codeElement.style.wordBreak};
font-variant-ligatures:${codeElement.style.fontVariantLigatures};