html minify/expand
by jcubed111
CSS
body{
font-family: Consolas;
}
JavaScript
const source =`
#ui
#ss
h1{- Time Wars -}
i.25{s,,,15,-20}
h3#a{Start}
a[href=https://github.com/jcubed111/13kGameAlpha][target=_blank]
h3{GitHub}
#ps
h2{Select a Ship}
.grid
h3.ship*6
hr
#j.left
h3#b{Back}
#lm1
.tabs
h3.act{Store}
h3#c{Ship}
h3#g{Inventory}
h2{LaserMart}
.grid
h3.item*3
hr
#e.left
h3#f{Depart ->}
#lm2
.tabs
h3#d{Store}
h3.act{Ship}
h3#g{Inventory}
h2
.grid
.sys
.b.e*3
.b.f*2
i.30{c,,,5,9,}
.sys*5
h4{Equipped Augments}
.grid
h3.item*3
hr
#h.left
h3#f{Depart ->}
#lm3
.tabs
h3#d{Store}
h3#c{Ship}
h3.act{Inventory}
h4{Equipped Weapons}
.grid
h3.item.w*3
h4{Storage}
.grid
h3.item.i*3
hr
#i.left
#f{Depart}
`;
function condenseShortHtml(source) {
let lines = source.split('\n').filter(line => line != '');
let lastIndent = -1;
let out = '';
lines.forEach(line => {
let indent = line.search(/[^ \t]/);
if(indent > lastIndent) out += '>';
if(indent == lastIndent) out += '+';
if(indent < lastIndent) out += '<'.repeat((lastIndent - indent) / 4);
lastIndent = indent;
out += line.trim();
});
return out;
}
document.body.innerText = condenseShortHtml(source);
function short2html(source) {
// stack elements: [tag, id, class, attrs, innerHtml, multiply]
let stack = [];
source = '>'+source;
function popStack() {
// removes the last stack element and makes it part of the previous element's innerHTML
let current = stack.pop();
let attrs =...