Last active
May 7, 2024 07:57
-
-
Save myfonj/c8ce74bf549e19600026ce9022388df8 to your computer and use it in GitHub Desktop.
HTML sandbox - editor in data URI (890 bytes v1, 1165 v2), with live preview and persistence.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data:text/html;charset=utf-8;verbatim,<!doctype html><title>HTML sandbox 2.0.2</title><meta name=color-scheme content="dark light"><meta name=viewport content=width=device-width,initial-scale=1><body style=margin:0;display:flex;height:100vh onload="OT=(DC=document).title,A.value=decodeURIComponent((L=location).hash.slice(1)||'')||A.value;T=W=0;E=RegExp('^'+(D='data:text/html;charset=utf-8,'));F=()=>{if(W!=(V=A.value))W=V,M=V.match(/(^data:.+?(;verbatim)?,)?([^]*)/),I.src=M[2]?V:(M[1]||D)+encodeURIComponent(M[3]),DC.title=NT=((TM=V.match(/<title\b[^]*?\x3E([^]*?)<\/title\b/m))&&(NT=TM[1])&&(NT=NT.trim())&&(DC.title=NT+' @ '+OT))||OT};F()"><textarea autocapitalize=off style=resize:horizontal;width:50vw;border:inset autofocus id=A onkeyup=clearTimeout(T);T=setTimeout(F,400) onblur=try{history.pushState({},NT,'\u0023'+(S=I.src.replace(E,'')))}catch(e){L.hash=S}><!doctype html><html lang="en"><title>%0A%0A</title><meta name="color-scheme" content="dark light">%0A<meta name="viewport" content="width=device-width, initial-scale=1">%0A<style>%0A%0A</style>%0A<body>%0A%0A<script>%0A%0A</script>%0A</textarea><iframe style=flex-grow:1;width:0;border:0 id=I> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data:text/html;charset=utf-8,<title>HTML sandbox 1.1.4</title><meta name=viewport content=width=device-width,initial-scale=1><body style=margin:0;display:flex;height:100vh;background:black onload="OT=(DC=document).title,A.value=decodeURIComponent((L=location).hash.slice(1)||'');T=W=0;E=RegExp('^'+(D='data:text/html;charset=utf-8,'));F=()=>{if(W!=(V=A.value))W=V,M=V.match(/(^data:.+?,)?([^]*)/),I.src=M[1]?V:D+encodeURIComponent(M[2]),DC.title=NT=((TM=V.match(/<title\b[^]*?\x3E([^]*?)<\/title\b/m))&&(NT=TM[1])&&(NT=NT.trim())&&(DC.title=NT+' @ '+OT))||OT};F()"><textarea style=resize:horizontal;width:50vw;border:inset;opacity:.7;color:snow;background:transparent autofocus id=A onkeyup=clearTimeout(T);T=setTimeout(F,400) onblur=try{history.pushState({},NT,'\u0023'+(S=I.src.replace(E,'')))}catch(e){L.hash=S}></textarea><iframe style=flex-grow:1;width:0;border:0;background:grey id=I>#%3C!doctype html%3E%3Chtml lang%3D""%3E%3Ctitle%3E%0A%0A%3C%2Ftitle%3E%0A%3Cmeta name%3D"viewport" content%3D"width%3Ddevice-width%2C initial-scale%3D1"%3E%0A%3Cstyle%3E%0A%3Aroot %7B background%3A dimgray%3B color%3A snow%3B %7D%0A%3Alink %7B color%3A aqua%3B %7D %3Avisited %7B color%3A lime%3B %7D%0A%0A%3C%2Fstyle%3E%0A%3Cbody%3E%0A%0A%3Cscript%3E%0A%0A%3C%2Fscript%3E%0A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Changelog
color-scheme="dark"
(must be present in document as well); • made "verbatim" mode derived from explicit;verbatim,
in datauri prologue instead of sole prologue presence; • possibility to have default content even when used as physical file.Features
text/html
data:application/xhtml+xml,
/data:image/svg+xml,
/data:text/plain,
;verbatim,
in prefix to have plain non-encoded readable value in the hash (or more precisely, leave it on the browser)#
:%23
%
:%25
yourself#hash
after editor blur event%s
in bookmark URL for query substitutionA
, URL ends with#<b>%s</b>
enteringA bar
in URLbar will produce<b>bar</b>
in editorThis frame > Show only this frame
(or Open frame in new tab/window) (Firefox)#
) from URLTechnical restrictions
locaStorage
. The only mean to save some state across iframe reloads is to (ab)usewindow.name
.Notes
location.hash
assignment but it throws onhistory.pushState
;location.hash
assignment (as it was top level navigation) but allowshistory.pushState
. If my memory serves, old versions of Chrome treated hash as content continuation and wrote it into document, sodata:text/html,content?search#hash
had contentcontent?search#hash
andlocation.hash
empty, now both browsers agree that content iscontent?search
and location.hash is#hash
. DataURI docs say nothing about#hash
part.Online variation of this, served over HTTP: https://myfonj.github.io/sandbox.html