summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos <christos@bauherren.ovh>2025-01-01 00:07:38 +0000
committerChristos <christos@bauherren.ovh>2025-01-01 00:07:38 +0000
commitca1b2ce4289980e4e8d3d20fac5ef09ec6dd213b (patch)
tree17c54717a8d76e8804291ecf56a218d1ba90095d
First commit
-rw-r--r--cork-base.rc77
-rw-r--r--cork.rc56
-rw-r--r--mh122
3 files changed, 255 insertions, 0 deletions
diff --git a/cork-base.rc b/cork-base.rc
new file mode 100644
index 0000000..1beacf7
--- /dev/null
+++ b/cork-base.rc
@@ -0,0 +1,77 @@
+#!/bin/rc
+path=(. /bin)
+fn run {
+ lpaf=home$REQUEST_URI
+ rpafs='/'; wd='/'; ifs='/';
+ arg = `{echo $REQUEST_URI}
+ if (test -d $lpaf) {
+ lpaf=$lpaf^'i'
+ }
+ for (i in $arg) {
+ wd=$wd^$i
+ rpafs=($rpafs $wd)
+ wd=$wd'/'
+ }
+ echo;
+ for (h in $bar) { $$h }
+ mh $lpaf.md
+}
+fn sbar {
+ echo -n 'ENTER HTML PREAMBLE HERE'
+ ls -F home/./$rpafs | sed -e 's,/+\./+,/,g' \
+ -e '/\/i\.(md)$/d' \
+ -e 's/\.(md)$//' -e 's!^home!!' | sort | awk -F/ '
+ function p(x, y, s) { for (i=0; i<x-y; i++) printf s }
+ BEGIN { lNF = 2 }
+ {
+ sub("/$", "", $0)
+ p(NF, lNF, "<ul>"); p(lNF, NF, "</ul><hr>")
+ lNF = NF; fp = $NF
+ printf "<li><a href=\%s\>%s</a>", $0, fp
+ }
+ END { p(lNF, 2, "</ul><hr>"); printf "</ul></nav></small><article>" }'}
+fn add {
+ _l = $1^_^$#$1
+ $_l = $*(2-)
+ $1 = ($$1 $_l)
+}
+add bar sbar; run
+ (avsbq) | cat cork-base
+#!/bin/rc
+path=(. /bin)
+fn run {
+ lpaf=home$REQUEST_URI
+ rpafs='/'; wd='/'; ifs='/';
+ arg = `{echo $REQUEST_URI}
+ if (test -d $lpaf) {
+ lpaf=$lpaf^'i'
+ }
+ for (i in $arg) {
+ wd=$wd^$i
+ rpafs=($rpafs $wd)
+ wd=$wd'/'
+ }
+ echo;
+ for (h in $bar) { $$h }
+ mh $lpaf.md
+}
+fn sbar {
+ echo -n '<style>img{width:150px;}nav li ul{padding-left:.5em}body{display:flex;flex-wrap:wrap;margin:20 24%}article{flex:1}nav{min-width:12em}ul{list-style: none}#t{flex:2;position:fixed;right:calc(5vw + 10px);width:222px;max-height:80vh;overflow-y:auto;box-sizing:border-box;background-color:#fff;z-index:10;}</style><meta charset=utf-8><small><nav><ul>'
+ ls -F home/./$rpafs | sed -e 's,/+\./+,/,g' \
+ -e '/\/i\.(md)$/d' \
+ -e 's/\.(md)$//' -e 's!^home!!' | sort | awk -F/ '
+ function p(x, y, s) { for (i=0; i<x-y; i++) printf s }
+ BEGIN { lNF = 2 }
+ {
+ sub("/$", "", $0)
+ p(NF, lNF, "<ul>"); p(lNF, NF, "</ul><hr>")
+ lNF = NF; fp = $NF
+ printf "<li><a href=\%s\>%s</a>", $0, fp
+ }
+ END { p(lNF, 2, "</ul><hr>"); printf "</ul></nav></small><article>" }'}
+fn add {
+ _l = $1^_^$#$1
+ $_l = $*(2-)
+ $1 = ($$1 $_l)
+}
+add bar sbar; run
diff --git a/cork.rc b/cork.rc
new file mode 100644
index 0000000..0b2f0aa
--- /dev/null
+++ b/cork.rc
@@ -0,0 +1,56 @@
+#!/bin/rc
+
+path=(. /bin)
+req_p=`{echo -n $REQUEST_URI }
+fn run {
+ lpaf=home$REQUEST_URI
+ rpafs='/'; wd='/'; ifs='/';
+ arg = `{echo -n $REQUEST_URI}
+ if (test -d $lpaf) {
+ lpaf=$lpaf^'i'
+ }
+ for (i in $arg) {
+ wd=$wd^$i
+ rpafs=($rpafs $wd)
+ wd=$wd'/'
+ }
+http_content_type='text/html'
+echo Content-Type: $http_content_type
+ echo;
+ for (h in $bar) { $$h }
+ mh $lpaf.md
+}
+fn sbar {
+ echo -n 'ENTER HTML PREAMBLE HERE'
+ ls -F home/./$rpafs | sed -e 's,/+\./+,/,g' \
+ -e '/\/i\.(md)$/d' \
+ -e 's/\.(md)$//' -e 's!^home!!' | sort | awk -F/ '
+ function p(x, y, s) { for(i=0; i < x-y; i+=1) printf s }
+ BEGIN { lNF=2; printf "<ul>" }
+ {
+ d = ""
+ if(match($0, "/$"))
+ d = "/"
+ sub("/$", "") # Strip trailing / for dirs so NF is consistent
+ p(NF, lNF, " тоз<ul>")
+ p(lNF, NF, "</ul><hr>")
+ lNF = NF
+ bname = $NF d
+ path = $0 d
+ gsub(/[\-_]/, " ", bname)
+ # Trailing / avoids false pattern matching
+ pa = path
+ gsub(/[^\/]$/, "&/", pa)
+ if(index(ENVIRON["req_p"] "/", pa) == 1)
+ printf "<li><a href="path" class=\"c\">"bname"</a>"
+ else
+ printf "<li><a href="path">"bname"</a>"
+ }
+ END { p(lNF, 2, "</ul>"); printf "</ul></nav><article>" }'
+}
+fn add {
+ _l = $1^_^$#$1
+ $_l = $*(2-)
+ $1 = ($$1 $_l)
+}
+add bar sbar; run
diff --git a/mh b/mh
new file mode 100644
index 0000000..a961ca1
--- /dev/null
+++ b/mh
@@ -0,0 +1,122 @@
+#!/bin/awk -f
+function eschtml(t) {
+gsub("<", "\\&lt;", t);
+gsub("%", "\\&#37;", t);
+ return t; }
+function oprint(t) { if(nr == 0) otext = otext t; else otext = otext t; }
+function nextil(t) {
+ if(!match(t, /[`<\[*_\\]|(\!\[)/)) return t
+ t1 = substr(t, 1, RSTART - 1)
+ tag = substr(t, RSTART, RLENGTH)
+ t2 = substr(t, RSTART + RLENGTH)
+ if(ilcode && tag != "`")
+ return eschtml(t1 tag) nextil(t2);
+ if(tag == "`"){
+ if(sub(/^`/, "", t2)){
+ if(!match(t2, /``/))
+ return t1 "&#8221;" nextil(t2);
+ ilcode2 = !ilcode2;
+ }
+ else if(ilcode2)
+ return t1 tag nextil(t2);
+ tag = "<pre>";
+ if(ilcode){
+# t1 = eschtml(t1);
+ tag = "</pre>";
+ }
+ ilcode = !ilcode;
+ return t1 tag nextil(t2);
+ }
+ if(tag == "\\"){ if(match(t2, /^[\\*_{}\[\]()#+\-\.!]/)){ tag = substr(t2, 1, 1)
+ t2 = substr(t2, 2); }
+ return t1 tag nextil(t2); }
+ if(tag == "<"){
+ if(match(t2, /^[A-Za-z\/!][^>]*>/)){
+ tag = tag substr(t2, RSTART, RLENGTH)
+ t2 = substr(t2, RLENGTH + 1)
+ return t1 tag nextil(t2);
+ }
+ return t1 "&lt;" nextil(t2);
+ }
+ if(tag == "["){
+ if(!match(t2, /(\[.*\])|(\(.*\))/)) return t1 tag nextil(t2); match(t2, /^[^\]]*(\[[^\]]*\][^\]]*)*/)
+ linktext = substr(t2, 1, RLENGTH)
+ t2 = substr(t2, RLENGTH + 2); if(match(t2, /^\(/)){ match(t2, /^[^\)]+(\([^\)]+\)[^\)]*)*/)
+ url = substr(t2, 2, RLENGTH - 1)
+ pt2 = substr(t2, RLENGTH + 2)
+ title = ""
+ if(match(url, /[ ]+\".*\"[ ]*$/)){ title = substr(url, RSTART, RLENGTH)
+ url = substr(url, 1, RSTART - 1)
+ match(title, /\".*\"/)
+ title = " title=\"" substr(title, RSTART + 1, RLENGTH - 2) "\""; } if(match(url, /^<.*>$/)) url = substr(url, 2, RLENGTH - 2)
+# url = eschtml(url)
+ return t1 "<a href="url""title">"nextil(linktext)"</a>" nextil(pt2); }
+ }
+ if(match(tag, /[*_]/)){ ntag = tag; if(sub("^" tag, "", t2)){ if(stag[ns] == tag && match(t2, "^" tag)) t2 = tag t2; else ntag = tag tag; } n = length(ntag)
+ tag = (n == 2) ? "b" : "i"
+ if(match(t1, / $/) && match(t2, /^ /)) return t1 tag nextil(t2)
+ if(stag[ns] == ntag){ tag = "/" tag; ns--; } else stag[++ns] = ntag
+ tag = "<" tag ">"
+ return t1 tag nextil(t2); } }
+function inline(t){ ilcode = 0; ilcode2 = 0; ns = 0; return nextil(t); }
+function printp(tag){ if(!match(text, /^[ ]*$/)){ text = inline(text);if(tag != "") oprint("<" tag ">" text "</" tag ">"); else oprint(text); } text = ""; }
+# function printp(tag){if(match(text,/^[ ]*$/)){text="";return}text=inline(text);if(tag=="p"){oprint("<"tag">"text)}else{oprint("<"tag">"text"</"tag">")};text=""}
+# ELSE function printp(tag){if(!match(text,/^[ ]*$/)){text=inline(text);if(tag=="p"){oprint("<"tag">"text)}else{oprint("<"tag">"text"</"tag">")}}text=""}
+BEGIN{blank=0;hr=0;nl=0;nr=0;text="";par="p";}
+{
+ for(nnl = 0; nnl < nl; nnl++)
+ if((match(block[nnl + 1], /[ou]l/) && !sub(/^( | )/, "")) || \
+ (block[nnl + 1] == "blockquote" && !sub(/^> ?/, "")))
+ break;
+}
+nnl < nl && !blank && text && ! /^ ? ? ?([*+-]|([0-9]+\.)+)( +| )/ { nnl = nl; }
+{ hr = 0; }
+block[nl] ~ /[ou]l/ && /^$/ {
+ blank = 1;
+ next;
+}
+{ newli = 0; }
+!hr && (nnl != nl || !text || block[nl] ~ /[ou]l/) && /^ ? ? ?[*+-]( +| )/ {
+ sub(/^ ? ? ?[*+-]( +| )/, "");
+ nnl++;
+ nblock[nnl] = "ul";
+ newli = 1;
+}
+newli {
+ if(blank && nnl == nl && !par)
+ par = "p";
+ blank = 0;
+ printp(par);
+ if(nnl == nl && block[nl] == nblock[nl])
+ oprint("<li>");
+}
+blank && ! /^$/ {
+ if(match(block[nnl], /[ou]l/) && !par)
+ par = "p";
+ printp(par);
+ par = "p";
+ blank = 0;
+}
+nnl != nl || nblock[nl] != block[nl] {
+ printp(par);
+ b = (nnl > nl) ? nblock[nnl] : block[nl];
+ par = (match(b, /[ou]l/)) ? "" : "p";
+}
+nnl < nl || (nnl == nl && nblock[nl] != block[nl]) {
+ for(; nl > nnl || (nnl == nl && pblock[nl] != block[nl]); nl--){
+ oprint("</" block[nl] ">");
+ }
+}
+nnl > nl {
+ for(; nl < nnl; nl++){
+ block[nl + 1] = nblock[nl + 1];
+ oprint("<" block[nl + 1] ">");
+ if(match(block[nl + 1], /[ou]l/))
+ oprint("<li>");
+ }
+}
+/^#+/ && (!newli || par=="p" || /^##/) { for(n = 0; n < 6 && sub(/^# */, ""); n++) sub(/#$/, ""); par = "h" n; }
+/^$/ { printp(par); par = "p"; next; }
+{ text = (text ? text " " : "") $0; }
+END{printp(par);printf(otext);printf("ENTER FOOTER HERE")}
+# maybe treat par as you do #h1 so to avoid closing tag