An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: The pasted code block cannot be automatically recognized Fix https://github.com/siyuan-note/siyuan/issues/8934
Daniel7cf196c40614
diff --git a/app/src/protyle/util/processCode.ts b/app/src/protyle/util/processCode.tsindex 9590065bb8..6ee9134f99 100644--- a/app/src/protyle/util/processCode.ts+++ b/app/src/protyle/util/processCode.ts@@ -32,16 +32,8 @@ export const processPasteCode = (html: string, text: string) => {if (isCode) {let code = text || html;if (/\n/.test(code)) {- return `<div data-type="NodeCodeBlock" class="code-block" data-node-id="${Lute.NewNodeID()}">- <div class="protyle-action">- <span class="protyle-action--first protyle-action__language" contenteditable="false">${window.siyuan.storage[Constants.LOCAL_CODELANG]}</span>- <span class="fn__flex-1"></span>- <span aria-label="${window.siyuan.languages.copy}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__copy"><svg><use xlink:href="#iconCopy"></use></svg></span>- <span aria-label="${window.siyuan.languages.more}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--last protyle-action__menu"><svg><use xlink:href="#iconMore"></use></svg></span>- </div>- <div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}">${code.replace(/&/g, "&").replace(/</g, "<")}<wbr></div>- <div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div>-</div>`;+ // 不要格式化为多行代码块,否则 Lute 解析会出错 https://github.com/siyuan-note/siyuan/issues/8934+ return `<div data-type="NodeCodeBlock" class="code-block" data-node-id="${Lute.NewNodeID()}"><div class="protyle-action"><span class="protyle-action--first protyle-action__language" contenteditable="false">${window.siyuan.storage[Constants.LOCAL_CODELANG]}</span><span class="fn__flex-1"></span><span aria-label="${window.siyuan.languages.copy}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--first protyle-action__copy"><svg><use xlink:href="#iconCopy"></use></svg></span><span aria-label="${window.siyuan.languages.more}" class="b3-tooltips__nw b3-tooltips protyle-icon protyle-icon--last protyle-action__menu"><svg><use xlink:href="#iconMore"></use></svg></span></div><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}">${code.replace(/&/g, "&").replace(/</g, "<")}<wbr></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`;} else {// Paste code from IDE no longer escape `<` and `>` https://github.com/siyuan-note/siyuan/issues/8340code = code.replace("<", "<").replace(">", ">");