Skip to content

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

:art: improve script in HTML block

颖逸41ef76ed7491
diff --git a/app/stage/protyle/js/protyle-html.js b/app/stage/protyle/js/protyle-html.js
index d85d7b0abe..38d7b26ad2 100644
--- a/app/stage/protyle/js/protyle-html.js
+++ b/app/stage/protyle/js/protyle-html.js
@@ -20,13 +20,16 @@ class ProtyleHtml extends HTMLElement {
el.innerHTML = dataContent
const scripts = el.getElementsByTagName('script')
let fatalHTML = ''
- for (let i = 0; i < scripts.length; i++) {
- if (scripts[i].textContent.indexOf('document.write') > -1) {
+ for (const script of scripts) {
+ if (script.textContent.indexOf('document.write') > -1) {
fatalHTML += `<div style="color:var(--b3-theme-error);font-size: 12px">${window.siyuan.languages.htmlBlockError}</div>
-<textarea style="width: 100%;box-sizing: border-box;height: 120px"><script>${scripts[i].textContent}</script></textarea>`
+<textarea style="width: 100%;box-sizing: border-box;height: 120px"><script>${script.textContent}</script></textarea>`
} else {
const s = document.createElement('script')
- s.textContent = scripts[i].textContent
+ for (const attr of script.attributes) {
+ s.setAttribute(attr.name, attr.value);
+ }
+ s.textContent = script.textContent
this.display.appendChild(s)
}
}