From 9a135bb7ef0ff1f18131c4f9423c43bb438359b4 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 30 Aug 2022 23:05:19 +0800 Subject: [PATCH] :bug: https://github.com/siyuan-note/siyuan/issues/5762 --- app/stage/protyle/js/protyle-html.js | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/app/stage/protyle/js/protyle-html.js b/app/stage/protyle/js/protyle-html.js index ef0f720ba..9fa38ac0c 100644 --- a/app/stage/protyle/js/protyle-html.js +++ b/app/stage/protyle/js/protyle-html.js @@ -1,5 +1,5 @@ class ProtyleHtml extends HTMLElement { - constructor() { + constructor () { super() const shadowRoot = this.attachShadow({mode: 'open'}) this.display = this.shadowRoot @@ -7,22 +7,31 @@ class ProtyleHtml extends HTMLElement { this.display.innerHTML = dataContent } - static get observedAttributes() { + static get observedAttributes () { return ['data-content'] } - attributeChangedCallback(name, oldValue, newValue) { + attributeChangedCallback (name, oldValue, newValue) { if (name === 'data-content') { - const dataContent = Lute.UnEscapeHTMLStr(this.getAttribute('data-content')) + const dataContent = Lute.UnEscapeHTMLStr( + this.getAttribute('data-content')) this.display.innerHTML = dataContent - const el = document.createElement('div'); - el.innerHTML = dataContent; - const scripts = el.getElementsByTagName("script") + const el = document.createElement('div') + el.innerHTML = dataContent + const scripts = el.getElementsByTagName('script') + let fatalHTML = '' for (let i = 0; i < scripts.length; i++) { - const s = document.createElement('script'); - s.textContent = scripts[i].textContent; - this.display.appendChild(s); + const s = document.createElement('script') + if (scripts[i].textContent.indexOf('document.write') > -1) { + fatalHTML += `
${window.siyuan.languages.htmlBlockError}
` + } else { + s.textContent = scripts[i].textContent + } + this.display.appendChild(s) + } + if (fatalHTML) { + this.display.innerHTML += fatalHTML } } }