From aa4eb5ba9eea67b0a8c07a22445ac745a9bfd59a Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 29 Apr 2025 17:20:51 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/14719 --- app/src/protyle/export/index.ts | 2 +- app/src/protyle/render/highlightRender.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/protyle/export/index.ts b/app/src/protyle/export/index.ts index 241e0746a..f5d0c3d1d 100644 --- a/app/src/protyle/export/index.ts +++ b/app/src/protyle/export/index.ts @@ -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'); diff --git a/app/src/protyle/render/highlightRender.ts b/app/src/protyle/render/highlightRender.ts index 585d36c90..dfd3ba675 100644 --- a/app/src/protyle/render/highlightRender.ts +++ b/app/src/protyle/render/highlightRender.ts @@ -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; 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};