diff --git a/components/page.js b/components/page.js index 2233ee9..a9bac7a 100644 --- a/components/page.js +++ b/components/page.js @@ -107,9 +107,22 @@ export class Page extends HTMLElement { const frames = wrap.getElementsByTagName('iframe') this.frame = frames[frames.length - 1] this.textArea.addEventListener('blur', e => { - const msg = ['srcdoc', e.target.value] -this.frame.contentWindow.postMessage(msg, '*') + this.display(e.target.value) }) + this.frame.addEventListener('load', () => { + this.display(this.body) + }) + } + + display(value) { + let doc = value + if (!(/<\w/).test(doc.substring(0, 30))) { + doc = `
` +
+        doc.replace("<", "<").replace(">", ">") +
+      `
` + } + const msg = ['srcdoc', doc] + this.frame.contentWindow.postMessage(msg, '*') } set body(value) {