Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/5520

Vanessa70c369e43550
diff --git a/app/src/protyle/markdown/highlightRender.ts b/app/src/protyle/markdown/highlightRender.ts
index a9398f616a..121932d6bf 100644
--- a/app/src/protyle/markdown/highlightRender.ts
+++ b/app/src/protyle/markdown/highlightRender.ts
@@ -64,14 +64,6 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
language = "plaintext";
}
block.classList.add("hljs");
- // TODO 等待讨论是否需要渲染 if (!hasClosestByAttribute(block, "id", "searchPreview", true) || isPreview) {
- block.innerHTML = hljs.highlight(
- block.textContent + (block.textContent.endsWith("\n") ? "" : "\n"), // https://github.com/siyuan-note/siyuan/issues/4609
- {
- language,
- ignoreIllegals: true
- }).value;
- // }
block.setAttribute("data-render", "true");
const autoEnter = block.parentElement.getAttribute("linewrap");
const ligatures = block.parentElement.getAttribute("ligatures");
@@ -106,7 +98,17 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
languageElement.style.marginLeft = "";
}
}
-
+ const matchElement = block.querySelector('span[data-type="search-mark"]');
+ if (matchElement) {
+ // 搜索定位
+ matchElement.scrollIntoView();
+ }
+ block.innerHTML = hljs.highlight(
+ block.textContent + (block.textContent.endsWith("\n") ? "" : "\n"), // https://github.com/siyuan-note/siyuan/issues/4609
+ {
+ language,
+ ignoreIllegals: true
+ }).value;
if (wbrElement && getSelection().rangeCount > 0) {
focusByOffset(block, startIndex, startIndex);
}