
'use strict';require('earlgrey-runtime/6');let $targ$0;let accum$0;let accum$1;let accum$2;let accum$3;let accum$4;let accum$5;let accum$7;let $targ$8;let dom$0;let path$0;let marked$0;let hljs$0;let fix__minus__script__minus__tags$0;let re__minus__source$0;let extract__minus__raw$0;let formats$0;let format$0;dom$0=require("earlgrey-runtime/std/dom");path$0=require("path");marked$0=require("marked");hljs$0=require("highlight.js");if((typeof(document)==="undefined")){$targ$0=undefined;(global["document"]=$targ$0);(void 0);}fix__minus__script__minus__tags$0=(function fixScriptTags(node$0){let m$0;let acc$0;let temp$0;acc$0=[];temp$0=null;m$0=null;$1:for(m$0 of node$0.querySelectorAll("script")){let $targ$3;let s2$0;let $targ$1;let $targ$2;let s$0;s$0=m$0;s2$0=document.createElement("script");$targ$1=s$0.type;(s2$0["type"]=$targ$1);if(s$0.src){$targ$3=s$0.src;(s2$0["src"]=$targ$3);(void 0);}$targ$2=s$0.textContent;(s2$0["textContent"]=$targ$2);temp$0=s$0.parentNode.replaceChild(s2$0,s$0);acc$0.push(temp$0);}return acc$0;});re__minus__source$0=(function reSource(root$0,dir$0){let m$2;let m$3;let acc$1;let temp$1;let helper$0;helper$0=(function helper(node$1,attr$0){let p$0;let m$1$0;m$1$0=node$1.getAttribute(attr$0);if(getChecker(RegExp("^/",""))(m$1$0)){return undefined;}else{if(getChecker(RegExp("://",""))(m$1$0)){return undefined;}else{p$0=m$1$0;return node$1.setAttribute(attr$0,path$0.join(dir$0,p$0));}}});m$2=null;$2:for(m$2 of root$0.querySelectorAll("a, link")){let node$2;node$2=m$2;helper$0(node$2,"href");}acc$1=[];temp$1=null;m$3=null;$3:for(m$3 of root$0.querySelectorAll("img, script, iframe")){let node$3;node$3=m$3;temp$1=helper$0(node$3,"src");acc$1.push(temp$1);}return acc$1;});extract__minus__raw$0=(function extractRaw(text$0,directory$0){let xs$0;let x$0;let t0$0;let m$4$0;let dummy$0;let $targ$4;dummy$0=document.createElement("div");$targ$4=text$0;(dummy$0["innerHTML"]=$targ$4);if(directory$0){re__minus__source$0(dummy$0,directory$0);}fix__minus__script__minus__tags$0(dummy$0);m$4$0=consume(dummy$0.childNodes);if((Array.isArray(m$4$0)&&((t0$0=m$4$0.length),(t0$0===1)))){x$0=m$4$0[0];return x$0;}else{xs$0=m$4$0;return xs$0;}});formats$0=__amp____colon__(((accum$0=({})),(accum$0["direct"]=(function direct(node$4,options$0){return node$4;})),accum$0),__amp____colon__(((accum$1=({})),(accum$1["enode"]=(function enode(enode$0,options$1){return dom$0(enode$0);})),accum$1),__amp____colon__(((accum$2=({})),(accum$2["text"]=(function text(text$1,options$2){return document.createTextNode(text$1);})),accum$2),__amp____colon__(((accum$3=({})),(accum$3["source"]=(function source(code$0,options$3){let node$5;let $targ$5;let lang$0;let m$5$0;m$5$0=options$3.language;if((m$5$0===(void 0))){return dom$0(ENode(["pre"],({}),code$0));}else{lang$0=m$5$0;if(hljs$0.getLanguage(lang$0)){node$5=dom$0(ENode(["pre"],({}),[]));$targ$5=hljs$0.highlight(lang$0,code$0).value;(node$5["innerHTML"]=$targ$5);return node$5;}else{return dom$0(ENode(["pre"],({}),code$0));}}})),accum$3),__amp____colon__(((accum$4=({})),(accum$4["stdout"]=(function stdout(text$2,options$4){return dom$0(ENode(["span",".stdout"],({}),text$2));})),accum$4),__amp____colon__(((accum$5=({})),(accum$5["markdown"]=(function markdown(text$3,options$5){let accum$6;let rval$0;let $targ$6;rval$0=document.createElement("div");$targ$6=marked$0(text$3,((accum$6=({})),(accum$6["highlight"]=(function highlight(code$1,temp$2$0){let t0$1;let $$2673$0;let lang$1;let ph$0$0;t0$1=temp$2$0;lang$1=t0$1;ph$0$0=t0$1;if((ph$0$0===(void 0))){return code$1;}else{if(hljs$0.getLanguage(lang$1)){return hljs$0.highlight(lang$1,code$1).value;}else{return code$1;}}})),accum$6));(rval$0["innerHTML"]=$targ$6);if(options$5.directory){re__minus__source$0(rval$0,options$5.directory);}return rval$0;})),accum$5),__amp____colon__(((accum$7=({})),(accum$7["html"]=(function html(text$4,options$6){return extract__minus__raw$0(text$4,options$6.directory);})),accum$7),({"md":"markdown","txt":"text"}))))))));format$0=(function format(fmt$0,obj$0){let name$1;let m$6$0;let t0$2;let t1$0;let $targ$7;let name$0;let options$7;let formatter$0;m$6$0=fmt$0;if((typeof(m$6$0)==="string")){$targ$7=[fmt$0,({"name":fmt$0})];}else{if(___hasprop(m$6$0,"name")){name$1=m$6$0.name;$targ$7=[name$1,fmt$0];}else{throw (new Error((("Cannot parse format: \""+fmt$0)+"\"")));}}t0$2=$targ$7;if((Array.isArray(t0$2)&&((t1$0=t0$2.length),(t1$0===2)))){name$0=t0$2[0];options$7=t0$2[1];}else{___match_error($targ$7,"{name, options}");}[name$0,options$7];formatter$0=send(formats$0,name$0);$4:while((typeof(formatter$0)==="string")){formatter$0=send(formats$0,formatter$0);formatter$0;}if((!formatter$0)){throw (new Error((("Unknown format: \""+name$0)+"\"")));}return formatter$0(obj$0,options$7);});$targ$8=format$0;(exports["format"]=$targ$8);(void 0);
//# sourceMappingURL=format.js.map

