From 292a17b7803a6a066583bafb941dce0c48211a8e Mon Sep 17 00:00:00 2001 From: the little girl Date: Mon, 22 Sep 2014 21:24:14 +0900 Subject: wiki -> ukulele --- Makefile | 6 +- ukulele.c | 332 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ukulele.css | 31 ++++++ ukulele.js | 129 +++++++++++++++++++++++ wiki.c | 332 ------------------------------------------------------------ wiki.css | 31 ------ wiki.js | 129 ----------------------- 7 files changed, 495 insertions(+), 495 deletions(-) create mode 100644 ukulele.c create mode 100644 ukulele.css create mode 100644 ukulele.js delete mode 100644 wiki.c delete mode 100644 wiki.css delete mode 100644 wiki.js diff --git a/Makefile b/Makefile index 0b7ccbf..f23818e 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ -all: wiki.cgi +all: ukulele.cgi -wiki.cgi: config.h wiki.c +ukulele.cgi: config.h wiki.c ${CC} -std=c99 -pedantic -Os -o $@ wiki.c -lmarxup config.h: cp config.def.h $@ clean: - rm -f wiki.cgi + rm -f ukulele.cgi again: clean all diff --git a/ukulele.c b/ukulele.c new file mode 100644 index 0000000..ba854a5 --- /dev/null +++ b/ukulele.c @@ -0,0 +1,332 @@ +#define _POSIX_C_SOURCE 200809L +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "config.h" + +static const char *badchars = "\\?%:|\"<> "; + +int writable(char *path) { + struct stat s; + if(!stat(path, &s)) { + if(S_ISREG(s.st_mode)) + return !eaccess(path, W_OK); + else if(S_ISDIR(s.st_mode)) + return 0; + } + char *dir = dirname(strdup(path)); + if(!stat(dir, &s)) { + if(S_ISDIR(s.st_mode)) + return !eaccess(dir, W_OK); + } + return 0; +} + +void head(char *page, char *link, char *what) { + printf("Content-Type: text/html; charset=utf-8\n\n"); + printf("\n"); + printf("%s · %s\n", title, page); + printf("\n", base); + printf("\n", base); + printf("

"); + if(link && what && !strcmp(what, "rediger")) + printf("%s", what, link, page); + else if(link && what) + printf("%s", what, base, link, page); + else + printf("%s", page); + printf("

\n"); +} + +void foot(int file) { + printf("
\n"); + printf("

"); + for(int i = 0; *links[i]; i++) { + if(*links[i][1] == '/' || strstr(links[i][1], "://")) + printf("%s ", links[i][1], links[i][0]); + else + printf("%s ", script, links[i][1], links[i][0]); + } + if(!file) return; + printf("%s text/plain\n", id); +} + +char *clean(char *p) { + char *dup = strdup(basename(p)); + char *x = dup; + while(*x) { + if(*x == '-') *x = ' '; + x++; + } + return dup; +} + +int legit(char *page) { + if(!page) return 0; + if(!strcmp(page, "/")) return 0; + if(strstr(page, "..")) return 0; + if(strcspn(page, badchars) < strlen(page)) return 0; + // strlen(page) + return 1; +} + +int problem(int status, char *message) { + printf("Status: %d\n", status); + printf("Content-Type: text/plain\n\n"); + printf("%s\n", message); + return 1; +} + +int redirect(char *path, char *prefix) { + printf("Status: 303\n"); + switch(*path) { + case '?': printf("Location: %s\n\n", path); break; + case '#': + printf("Location: %s/%s?m=", script, path); + // skrive ut ++path + printf("\n"); + default: + if(prefix) { + printf("Location: %s/%s/%s\n\n", script, prefix, path); break; + } else { + printf("Location: %s/%s\n\n", script, path); break; + } + } + return 0; +} + +int unauthorized(int status) { + printf("Status: %d\n", status); + if(status == 401) + printf("WWW-Authenticate: Basic realm='%s'\n", realm); + printf("Content-Type: text/plain; charset=utf-8\n\n"); + printf("No.\n"); + return 1; +} + +int edit(char *path) { + if(!writable(path)) return unauthorized(403); + FILE *fp = fopen(path, "r"); + fp ? head(path, path, "vis") : head(path, NULL, NULL); + char buffer[sysconf(_SC_PAGESIZE)]; + printf("

\n"); + printf("

\n"); + if(orz) + printf("@picto
\n"); + printf("\n"); + printf("

"); + printf("

"); + foot(1); + if(fp) fclose(fp); + return 0; +} + +// v fæl +int store(char *raw, int len) { + char *dir = dirname(strdup(raw)); + char *id = basename(strdup(raw)); + if(chdir(dir)) + return problem(404, "Not found"); + char path[strlen(loft) + strlen(id) + 256]; + int epoch = time(NULL); + snprintf(path, strlen(loft) + strlen(id) + 256, "%s/%s.%d", loft, id, epoch); + FILE *fp = fopen(path, "w"); + if(!fp) return redirect("fff", NULL); + int pos = 0; + unsigned int decoded; + char buffer[3] = { 0 }; + for(int i = 0; i < len; i++) { + buffer[pos] = getchar(); + if(buffer[pos] == '+') buffer[pos] = ' '; + if(buffer[pos] == '&') { buffer[pos] = '\0'; break; } + if(pos == 2) { + if(buffer[0] == '%' && isxdigit(buffer[1]) && isxdigit(buffer[2])) { + sscanf(buffer, "%%%2x", &decoded); + fprintf(fp, "%c", decoded); + memset(buffer, 0, 3); + pos = 0; + } else { + fprintf(fp, "%c", buffer[0]); + memmove(buffer, &buffer[1], 2); + buffer[2] = 0; + } + } + else pos++; + } + fprintf(fp, "%.3s", buffer); + fputc('\0', fp); + fclose(fp); + unlink(id); + symlink(path, id); + return 0; +} + +int post(char *path) { + char *header; + int clen; + header = getenv("CONTENT_LENGTH"); + if(!header) return redirect(path, NULL); + clen = atoi(header); + while(clen > 1) + if(clen--, getchar() == 't') + if(clen--, getchar() == '=') + store(path, clen); + return redirect(path, NULL); +} + +// gjør denne penere! +int list(char *raw, int dir, int inc) { + int len = strlen(raw); + char *pattern = malloc(len + 3); + if(len > 0 && raw[len - 1] == '/') + raw[len - 1] = '\0'; + if(dir) + snprintf(pattern, len + 3, "%s/*", raw); + else + snprintf(pattern, len + 1, "%s", raw); + glob_t res; + if(glob(pattern, GLOB_MARK, NULL, &res)) { + if(!inc) { + head("ingen treff", NULL, NULL); + foot(0); + } + return 0; + } + if(!inc) + head("treff", NULL, NULL); + char *path; + printf("
    "); + for(int i = 0; i < res.gl_pathc; i++) { + path = res.gl_pathv[i]; + if(*path == '.' && *path + 1 == '/') path += 2; + printf("
  • %s", script, path, path); + } + printf("
"); + if(!inc) + foot(0); + free(pattern); + return 0; +} + +int text(char *path, char *type) { + FILE *fp = fopen(path, "r"); + if(fp) { + char buffer[sysconf(_SC_PAGESIZE)]; + printf("Content-Type: %s; charset=utf-8\n\n", type); + while(fgets(buffer, sizeof(buffer), fp)) + printf("%s", buffer); + } + fclose(fp); + return 0; +} + +void include(FILE *out, char *path) { + struct stat s; + int plain = 0; + if(*path == 't') + plain = 1, path++; + while(isspace(*path)) path++; + if(!legit(path)) return; + if(*path == '/') return; + stat(path, &s); + if(S_ISDIR(s.st_mode)) { + list(path, 1, 1); + return; + } + FILE *fp = fopen(path, "r"); + if(!fp) return; + if(plain) { + printf("
");
+    int c;
+    while((c = fgetc(fp)) != EOF) {
+      switch(c) {
+        case '&': printf("&"); break;
+        case '<': printf("<"); break;
+        case '>': printf(">"); break;
+        default: putc(c, stdout);
+      }
+    }
+    printf("
"); + } else { + marxup(fp, out, NULL); + } + fclose(fp); +} + +void magic(FILE *out, char *line) { + switch(*line++) { + case 'i': include(out, line); break; + default: fprintf(out, "WHAT: %s\n", line); return; + } +} + +int view(char *path) { + struct stat s; + stat(path, &s); + if(S_ISDIR(s.st_mode)) { + if(dirlist) + return list(path, 1, 0); + return redirect(home, path); + } + FILE *fp = fopen(path, "r"); + if(!fp) return redirect("?e", NULL); + writable(path) ? head(path, "?e", "rediger") : head(path, NULL, NULL); + marxup(fp, stdout, magic); + foot(1); + return 0; +} + +int main(int argc, char **argv) { + char *page = getenv("PATH_INFO"); + char *qstr = getenv("QUERY_STRING"); + char *verb = getenv("REQUEST_METHOD"); + + if(!page && argc > 1) page = argv[1]; + if(!qstr && argc > 2) qstr = argv[2]; + + if(!verb) verb = "GET"; + + if(!script) script = getenv("SCRIPT_NAME"); + if(!script) script = ""; + if(!base) base = strdup(dirname(strdup(script))); + + if(authenticate && !(id = authenticate())) return unauthorized(401); + if(!legit(page++)) return redirect(home, NULL); + + setenv("MARXUP_HEADER", "2", 1); + setenv("MARXUP_PREFIX", base, 1); + setenv("MARXUP_WIKI", "1", 1); + + if(chdir(pages)) + return problem(503, "Service unavailable"); + + if(!strncmp(verb, "POST", 4)) return post(page); + if(strchr(page, '*')) + return list(page, 0, 0); + + while(qstr && *qstr) { + switch(*qstr) { + case 'e': return edit(page); + case 't': return text(page, "text/plain"); + case 'c': return text(page, "text/css"); + } + qstr++; + } + return view(page); +} + diff --git a/ukulele.css b/ukulele.css new file mode 100644 index 0000000..d1d17dc --- /dev/null +++ b/ukulele.css @@ -0,0 +1,31 @@ +body { font: 16px/1.2 sans-serif; width: 90%; margin: 0 auto; max-width: 64em; background: white; } +textarea { font: inherit; width: 100%; } +h1 { text-transform: uppercase; } +hr { clear: both; } +img { border: none; } +img[align=left] { margin: 0 1em 1em 0; } +img[align=right] { margin: 0 0 1em 1em; } +ul { list-style: inside square; } +ul.glob { list-style: inside circle; padding: 0; text-transform: uppercase; } +table { text-align: left; border-collapse: collapse; background: #eee; } +th, td { padding: 4px 8px 4px 8px; } +tr:nth-child(2n) { background: #fff; } +a { text-decoration: none; color: red; } +a:hover, a:visited { color: Crimson; } +h1 a:hover:after { content: " »" attr(data-text); color: #aaa; } +pre { border: 1px dotted gray; padding: 0.5em; background: GhostWhite; } +textarea { font-family: monospace; } +tt { font-weight: bold; } +.edit a { margin-right: 1em; } +.meny { float: right; padding: 1em; clear: right; margin: 0 1em 1em 1em; width: 240px; background: #ddd; border-left: 4px solid #000; box-shadow: 5px 5px 10px #777; } +.meny h2, .meny h3 { font-size: large; margin-top: 0; text-transform: uppercase; } +.meny ul { padding: 0; margin: 0; } +.marxuplol { padding: 1em; background: #ddd; } +.rosa { color: DeepPink; }pre { overflow: hidden; } +@media screen and (max-width: 640px) { + .meny { float: none; margin: 0; } + .magisk { display: none; } +} + +img { image-rendering: optimizeSpeed; image-rendering: -moz-crisp-edges; image-rendering: -o-crisp-edges; image-rendering: -webkit-optimize-contrast; image-rendering: optimize-contrast; image-rendering: crisp-edges; image-rendering: pixelated; -ms-interpolation-mdoe: nearest-neighbor; max-width: 100%; } + diff --git a/ukulele.js b/ukulele.js new file mode 100644 index 0000000..1d47062 --- /dev/null +++ b/ukulele.js @@ -0,0 +1,129 @@ +function insert(text) { + var t = document.getElementsByName('t')[0]; + if(!t) return; + if(t.selectionStart || t.selectionStart == '0') { + var pos = t.selectionStart; + var end = t.selectionEnd; + t.value = t.value.substring(0, pos) + text + t.value.substring(end, t.value.length); + } + t.focus(); + var cpos = t.selectionStart; + t.setSelectionRange(cpos, cpos); +} + +function wrap(prefix, postfix) { + var t = document.getElementsByName('t')[0]; + if(!t) return; + if(t.selectionStart || t.selectionStart == '0') { + var pos = t.selectionStart; + var end = t.selectionEnd; + var n = t.value.indexOf("\n", pos); + if(n > 0 && n < end) end = n; + t.value = t.value.substring(0, pos) + prefix + t.value.substring(pos, end) + postfix + t.value.substring(end, t.value.length); + } + t.focus(); + var cpos = t.selectionEnd + prefix.length + postfix.length; + t.setSelectionRange(cpos, cpos); +} + +function prepend(text) { + var t = document.getElementsByName('t')[0]; + if(!t) return; + if(t.selectionStart || t.selectionStart == '0') { + var pos = t.selectionStart; + var end = t.selectionEnd; + for(;pos < end; pos++) { + if(t.value.charAt(pos) != "\n") break; + } + for(;end > pos; end--) { + if(t.value.charAt(end - 1) != "\n") break; + } + var quote = ""; + var cpos = end; + if(t.value.charAt(pos - 1) != "\n") { + quote += "\n"; + cpos += 1; + } + if(pos == end) { + quote += text; + cpos += text.length; + } else { + var lines = t.value.substring(pos, end).split("\n"); + for(var i=0; i < lines.length; i++) { + quote += text + lines[i] + "\n"; + cpos += text.length; + } + quote = quote.slice(0, -1); + } + t.value = t.value.substring(0, pos) + quote + t.value.substring(end, t.value.length); + } + t.focus(); + t.setSelectionRange(cpos, cpos); +} + +function marxup_bold(e) { + wrap("*", "*"); +} + +function marxup_header(e) { + prepend("= "); +} + +function marxup_italics(e) { + wrap("_", "_"); +} + +function marxup_link(e) { + wrap("[", "]"); +} + +function marxup_quote(e) { + prepend("> "); +} + +function marxup_list(e) { + prepend("* "); +} + +function button(node, html, fun) { + var a = document.createElement("a"); + a.innerHTML = html; + a.href = "#"; + a.onclick = fun; + node.parentNode.insertBefore(a, node.nextSibling); +} + +function orz(src) { + insert("\n@" + src.replace(".t.jpg", "") + "\n"); +} + +document.addEventListener("DOMContentLoaded", function(e) { + var title = document.getElementsByTagName('h1')[0]; + var headers = document.getElementsByTagName("h2"); + if(headers.length > 0) { + var menu = document.createElement("div"); menu.className = 'magisk meny'; + for(var i = 0; i < headers.length; i++) { + var a = document.createElement("a"); + var id = "h-" + i; headers[i].id = id; a.href = "#" + id; + a.textContent = headers[i].textContent; + menu.appendChild(a); + menu.appendChild(document.createElement("br")); + } + title.parentNode.insertBefore(menu, title.nextSibling); + } + + var orz = document.getElementById('orz'); + if(orz) { + orz.onclick = function(e) { + window.open("/orz"); + return false; + } + button(orz, "> sitat", marxup_quote); + button(orz, "* liste", marxup_list); + button(orz, "[lenke]", marxup_link); + button(orz, "_kursiv_", marxup_italics); + button(orz, "*fet*", marxup_bold); + button(orz, "= overskrift", marxup_header); + } +}); + diff --git a/wiki.c b/wiki.c deleted file mode 100644 index ba854a5..0000000 --- a/wiki.c +++ /dev/null @@ -1,332 +0,0 @@ -#define _POSIX_C_SOURCE 200809L -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "config.h" - -static const char *badchars = "\\?%:|\"<> "; - -int writable(char *path) { - struct stat s; - if(!stat(path, &s)) { - if(S_ISREG(s.st_mode)) - return !eaccess(path, W_OK); - else if(S_ISDIR(s.st_mode)) - return 0; - } - char *dir = dirname(strdup(path)); - if(!stat(dir, &s)) { - if(S_ISDIR(s.st_mode)) - return !eaccess(dir, W_OK); - } - return 0; -} - -void head(char *page, char *link, char *what) { - printf("Content-Type: text/html; charset=utf-8\n\n"); - printf("\n"); - printf("%s · %s\n", title, page); - printf("\n", base); - printf("\n", base); - printf("

"); - if(link && what && !strcmp(what, "rediger")) - printf("%s", what, link, page); - else if(link && what) - printf("%s", what, base, link, page); - else - printf("%s", page); - printf("

\n"); -} - -void foot(int file) { - printf("
\n"); - printf("

"); - for(int i = 0; *links[i]; i++) { - if(*links[i][1] == '/' || strstr(links[i][1], "://")) - printf("%s ", links[i][1], links[i][0]); - else - printf("%s ", script, links[i][1], links[i][0]); - } - if(!file) return; - printf("%s text/plain\n", id); -} - -char *clean(char *p) { - char *dup = strdup(basename(p)); - char *x = dup; - while(*x) { - if(*x == '-') *x = ' '; - x++; - } - return dup; -} - -int legit(char *page) { - if(!page) return 0; - if(!strcmp(page, "/")) return 0; - if(strstr(page, "..")) return 0; - if(strcspn(page, badchars) < strlen(page)) return 0; - // strlen(page) - return 1; -} - -int problem(int status, char *message) { - printf("Status: %d\n", status); - printf("Content-Type: text/plain\n\n"); - printf("%s\n", message); - return 1; -} - -int redirect(char *path, char *prefix) { - printf("Status: 303\n"); - switch(*path) { - case '?': printf("Location: %s\n\n", path); break; - case '#': - printf("Location: %s/%s?m=", script, path); - // skrive ut ++path - printf("\n"); - default: - if(prefix) { - printf("Location: %s/%s/%s\n\n", script, prefix, path); break; - } else { - printf("Location: %s/%s\n\n", script, path); break; - } - } - return 0; -} - -int unauthorized(int status) { - printf("Status: %d\n", status); - if(status == 401) - printf("WWW-Authenticate: Basic realm='%s'\n", realm); - printf("Content-Type: text/plain; charset=utf-8\n\n"); - printf("No.\n"); - return 1; -} - -int edit(char *path) { - if(!writable(path)) return unauthorized(403); - FILE *fp = fopen(path, "r"); - fp ? head(path, path, "vis") : head(path, NULL, NULL); - char buffer[sysconf(_SC_PAGESIZE)]; - printf("

\n"); - printf("

\n"); - if(orz) - printf("@picto
\n"); - printf("\n"); - printf("

"); - printf("

"); - foot(1); - if(fp) fclose(fp); - return 0; -} - -// v fæl -int store(char *raw, int len) { - char *dir = dirname(strdup(raw)); - char *id = basename(strdup(raw)); - if(chdir(dir)) - return problem(404, "Not found"); - char path[strlen(loft) + strlen(id) + 256]; - int epoch = time(NULL); - snprintf(path, strlen(loft) + strlen(id) + 256, "%s/%s.%d", loft, id, epoch); - FILE *fp = fopen(path, "w"); - if(!fp) return redirect("fff", NULL); - int pos = 0; - unsigned int decoded; - char buffer[3] = { 0 }; - for(int i = 0; i < len; i++) { - buffer[pos] = getchar(); - if(buffer[pos] == '+') buffer[pos] = ' '; - if(buffer[pos] == '&') { buffer[pos] = '\0'; break; } - if(pos == 2) { - if(buffer[0] == '%' && isxdigit(buffer[1]) && isxdigit(buffer[2])) { - sscanf(buffer, "%%%2x", &decoded); - fprintf(fp, "%c", decoded); - memset(buffer, 0, 3); - pos = 0; - } else { - fprintf(fp, "%c", buffer[0]); - memmove(buffer, &buffer[1], 2); - buffer[2] = 0; - } - } - else pos++; - } - fprintf(fp, "%.3s", buffer); - fputc('\0', fp); - fclose(fp); - unlink(id); - symlink(path, id); - return 0; -} - -int post(char *path) { - char *header; - int clen; - header = getenv("CONTENT_LENGTH"); - if(!header) return redirect(path, NULL); - clen = atoi(header); - while(clen > 1) - if(clen--, getchar() == 't') - if(clen--, getchar() == '=') - store(path, clen); - return redirect(path, NULL); -} - -// gjør denne penere! -int list(char *raw, int dir, int inc) { - int len = strlen(raw); - char *pattern = malloc(len + 3); - if(len > 0 && raw[len - 1] == '/') - raw[len - 1] = '\0'; - if(dir) - snprintf(pattern, len + 3, "%s/*", raw); - else - snprintf(pattern, len + 1, "%s", raw); - glob_t res; - if(glob(pattern, GLOB_MARK, NULL, &res)) { - if(!inc) { - head("ingen treff", NULL, NULL); - foot(0); - } - return 0; - } - if(!inc) - head("treff", NULL, NULL); - char *path; - printf("
    "); - for(int i = 0; i < res.gl_pathc; i++) { - path = res.gl_pathv[i]; - if(*path == '.' && *path + 1 == '/') path += 2; - printf("
  • %s", script, path, path); - } - printf("
"); - if(!inc) - foot(0); - free(pattern); - return 0; -} - -int text(char *path, char *type) { - FILE *fp = fopen(path, "r"); - if(fp) { - char buffer[sysconf(_SC_PAGESIZE)]; - printf("Content-Type: %s; charset=utf-8\n\n", type); - while(fgets(buffer, sizeof(buffer), fp)) - printf("%s", buffer); - } - fclose(fp); - return 0; -} - -void include(FILE *out, char *path) { - struct stat s; - int plain = 0; - if(*path == 't') - plain = 1, path++; - while(isspace(*path)) path++; - if(!legit(path)) return; - if(*path == '/') return; - stat(path, &s); - if(S_ISDIR(s.st_mode)) { - list(path, 1, 1); - return; - } - FILE *fp = fopen(path, "r"); - if(!fp) return; - if(plain) { - printf("
");
-    int c;
-    while((c = fgetc(fp)) != EOF) {
-      switch(c) {
-        case '&': printf("&"); break;
-        case '<': printf("<"); break;
-        case '>': printf(">"); break;
-        default: putc(c, stdout);
-      }
-    }
-    printf("
"); - } else { - marxup(fp, out, NULL); - } - fclose(fp); -} - -void magic(FILE *out, char *line) { - switch(*line++) { - case 'i': include(out, line); break; - default: fprintf(out, "WHAT: %s\n", line); return; - } -} - -int view(char *path) { - struct stat s; - stat(path, &s); - if(S_ISDIR(s.st_mode)) { - if(dirlist) - return list(path, 1, 0); - return redirect(home, path); - } - FILE *fp = fopen(path, "r"); - if(!fp) return redirect("?e", NULL); - writable(path) ? head(path, "?e", "rediger") : head(path, NULL, NULL); - marxup(fp, stdout, magic); - foot(1); - return 0; -} - -int main(int argc, char **argv) { - char *page = getenv("PATH_INFO"); - char *qstr = getenv("QUERY_STRING"); - char *verb = getenv("REQUEST_METHOD"); - - if(!page && argc > 1) page = argv[1]; - if(!qstr && argc > 2) qstr = argv[2]; - - if(!verb) verb = "GET"; - - if(!script) script = getenv("SCRIPT_NAME"); - if(!script) script = ""; - if(!base) base = strdup(dirname(strdup(script))); - - if(authenticate && !(id = authenticate())) return unauthorized(401); - if(!legit(page++)) return redirect(home, NULL); - - setenv("MARXUP_HEADER", "2", 1); - setenv("MARXUP_PREFIX", base, 1); - setenv("MARXUP_WIKI", "1", 1); - - if(chdir(pages)) - return problem(503, "Service unavailable"); - - if(!strncmp(verb, "POST", 4)) return post(page); - if(strchr(page, '*')) - return list(page, 0, 0); - - while(qstr && *qstr) { - switch(*qstr) { - case 'e': return edit(page); - case 't': return text(page, "text/plain"); - case 'c': return text(page, "text/css"); - } - qstr++; - } - return view(page); -} - diff --git a/wiki.css b/wiki.css deleted file mode 100644 index d1d17dc..0000000 --- a/wiki.css +++ /dev/null @@ -1,31 +0,0 @@ -body { font: 16px/1.2 sans-serif; width: 90%; margin: 0 auto; max-width: 64em; background: white; } -textarea { font: inherit; width: 100%; } -h1 { text-transform: uppercase; } -hr { clear: both; } -img { border: none; } -img[align=left] { margin: 0 1em 1em 0; } -img[align=right] { margin: 0 0 1em 1em; } -ul { list-style: inside square; } -ul.glob { list-style: inside circle; padding: 0; text-transform: uppercase; } -table { text-align: left; border-collapse: collapse; background: #eee; } -th, td { padding: 4px 8px 4px 8px; } -tr:nth-child(2n) { background: #fff; } -a { text-decoration: none; color: red; } -a:hover, a:visited { color: Crimson; } -h1 a:hover:after { content: " »" attr(data-text); color: #aaa; } -pre { border: 1px dotted gray; padding: 0.5em; background: GhostWhite; } -textarea { font-family: monospace; } -tt { font-weight: bold; } -.edit a { margin-right: 1em; } -.meny { float: right; padding: 1em; clear: right; margin: 0 1em 1em 1em; width: 240px; background: #ddd; border-left: 4px solid #000; box-shadow: 5px 5px 10px #777; } -.meny h2, .meny h3 { font-size: large; margin-top: 0; text-transform: uppercase; } -.meny ul { padding: 0; margin: 0; } -.marxuplol { padding: 1em; background: #ddd; } -.rosa { color: DeepPink; }pre { overflow: hidden; } -@media screen and (max-width: 640px) { - .meny { float: none; margin: 0; } - .magisk { display: none; } -} - -img { image-rendering: optimizeSpeed; image-rendering: -moz-crisp-edges; image-rendering: -o-crisp-edges; image-rendering: -webkit-optimize-contrast; image-rendering: optimize-contrast; image-rendering: crisp-edges; image-rendering: pixelated; -ms-interpolation-mdoe: nearest-neighbor; max-width: 100%; } - diff --git a/wiki.js b/wiki.js deleted file mode 100644 index 1d47062..0000000 --- a/wiki.js +++ /dev/null @@ -1,129 +0,0 @@ -function insert(text) { - var t = document.getElementsByName('t')[0]; - if(!t) return; - if(t.selectionStart || t.selectionStart == '0') { - var pos = t.selectionStart; - var end = t.selectionEnd; - t.value = t.value.substring(0, pos) + text + t.value.substring(end, t.value.length); - } - t.focus(); - var cpos = t.selectionStart; - t.setSelectionRange(cpos, cpos); -} - -function wrap(prefix, postfix) { - var t = document.getElementsByName('t')[0]; - if(!t) return; - if(t.selectionStart || t.selectionStart == '0') { - var pos = t.selectionStart; - var end = t.selectionEnd; - var n = t.value.indexOf("\n", pos); - if(n > 0 && n < end) end = n; - t.value = t.value.substring(0, pos) + prefix + t.value.substring(pos, end) + postfix + t.value.substring(end, t.value.length); - } - t.focus(); - var cpos = t.selectionEnd + prefix.length + postfix.length; - t.setSelectionRange(cpos, cpos); -} - -function prepend(text) { - var t = document.getElementsByName('t')[0]; - if(!t) return; - if(t.selectionStart || t.selectionStart == '0') { - var pos = t.selectionStart; - var end = t.selectionEnd; - for(;pos < end; pos++) { - if(t.value.charAt(pos) != "\n") break; - } - for(;end > pos; end--) { - if(t.value.charAt(end - 1) != "\n") break; - } - var quote = ""; - var cpos = end; - if(t.value.charAt(pos - 1) != "\n") { - quote += "\n"; - cpos += 1; - } - if(pos == end) { - quote += text; - cpos += text.length; - } else { - var lines = t.value.substring(pos, end).split("\n"); - for(var i=0; i < lines.length; i++) { - quote += text + lines[i] + "\n"; - cpos += text.length; - } - quote = quote.slice(0, -1); - } - t.value = t.value.substring(0, pos) + quote + t.value.substring(end, t.value.length); - } - t.focus(); - t.setSelectionRange(cpos, cpos); -} - -function marxup_bold(e) { - wrap("*", "*"); -} - -function marxup_header(e) { - prepend("= "); -} - -function marxup_italics(e) { - wrap("_", "_"); -} - -function marxup_link(e) { - wrap("[", "]"); -} - -function marxup_quote(e) { - prepend("> "); -} - -function marxup_list(e) { - prepend("* "); -} - -function button(node, html, fun) { - var a = document.createElement("a"); - a.innerHTML = html; - a.href = "#"; - a.onclick = fun; - node.parentNode.insertBefore(a, node.nextSibling); -} - -function orz(src) { - insert("\n@" + src.replace(".t.jpg", "") + "\n"); -} - -document.addEventListener("DOMContentLoaded", function(e) { - var title = document.getElementsByTagName('h1')[0]; - var headers = document.getElementsByTagName("h2"); - if(headers.length > 0) { - var menu = document.createElement("div"); menu.className = 'magisk meny'; - for(var i = 0; i < headers.length; i++) { - var a = document.createElement("a"); - var id = "h-" + i; headers[i].id = id; a.href = "#" + id; - a.textContent = headers[i].textContent; - menu.appendChild(a); - menu.appendChild(document.createElement("br")); - } - title.parentNode.insertBefore(menu, title.nextSibling); - } - - var orz = document.getElementById('orz'); - if(orz) { - orz.onclick = function(e) { - window.open("/orz"); - return false; - } - button(orz, "> sitat", marxup_quote); - button(orz, "* liste", marxup_list); - button(orz, "[lenke]", marxup_link); - button(orz, "_kursiv_", marxup_italics); - button(orz, "*fet*", marxup_bold); - button(orz, "= overskrift", marxup_header); - } -}); - -- cgit v1.0