Browse Source

:bug: https://github.com/siyuan-note/siyuan/issues/5762

Vanessa 2 năm trước cách đây
mục cha
commit
9a135bb7ef
1 tập tin đã thay đổi với 19 bổ sung10 xóa
  1. 19 10
      app/stage/protyle/js/protyle-html.js

+ 19 - 10
app/stage/protyle/js/protyle-html.js

@@ -1,5 +1,5 @@
 class ProtyleHtml extends HTMLElement {
 class ProtyleHtml extends HTMLElement {
-  constructor() {
+  constructor () {
     super()
     super()
     const shadowRoot = this.attachShadow({mode: 'open'})
     const shadowRoot = this.attachShadow({mode: 'open'})
     this.display = this.shadowRoot
     this.display = this.shadowRoot
@@ -7,22 +7,31 @@ class ProtyleHtml extends HTMLElement {
     this.display.innerHTML = dataContent
     this.display.innerHTML = dataContent
   }
   }
 
 
-  static get observedAttributes() {
+  static get observedAttributes () {
     return ['data-content']
     return ['data-content']
   }
   }
 
 
-  attributeChangedCallback(name, oldValue, newValue) {
+  attributeChangedCallback (name, oldValue, newValue) {
     if (name === 'data-content') {
     if (name === 'data-content') {
-      const dataContent = Lute.UnEscapeHTMLStr(this.getAttribute('data-content'))
+      const dataContent = Lute.UnEscapeHTMLStr(
+        this.getAttribute('data-content'))
       this.display.innerHTML = dataContent
       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++) {
       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 += `<div style="color:#d23f31;font-size: 12px">${window.siyuan.languages.htmlBlockError}</div><textarea style="width: 100%;box-sizing: border-box;height: 120px"><script>${scripts[i].textContent}</script></textarea>`
+        } else {
+          s.textContent = scripts[i].textContent
+        }
+        this.display.appendChild(s)
+      }
+      if (fatalHTML) {
+        this.display.innerHTML += fatalHTML
       }
       }
     }
     }
   }
   }