From 0ba2202cec670e5e3ce8c077b74392f4d805853a Mon Sep 17 00:00:00 2001 From: opfez Date: Sat, 21 Aug 2021 19:52:20 +0200 Subject: [PATCH] [writan] make implicit links better --- format.c | 26 +++++++++++++++----------- gen.sh | 5 ++++- resources/style-formatted.css | 23 +++++++---------------- site-src/c.wtn | 8 ++++---- site-src/emacs.wtn | 2 +- site-src/index.wtn | 8 ++++---- site-src/programming-languages.wtn | 6 +++--- site-src/writan.wtn | 4 ++-- 8 files changed, 40 insertions(+), 42 deletions(-) diff --git a/format.c b/format.c index 954d7fb..1543919 100644 --- a/format.c +++ b/format.c @@ -136,7 +136,12 @@ void get_link(FILE *input, char *out) { char c; - while (((c = fgetc(input)) != ' ') && c != '\n') { + + /* some links add the initial { for some reason */ + if (fgetc(input) != '{') + fseek(input, -1L, SEEK_CUR); + + while (((c = fgetc(input)) != ' ') && c != '\n' && c != '}') { if (c == EOF) die("End of file encountered while parsing link."); *(out)++ = c; @@ -161,20 +166,19 @@ emit_internal_implicit_link(FILE *input, FILE *output) { fseek(input, -1, SEEK_CUR); + char link[1024]; char page[1024]; - char *page_ptr = page; + get_link(input, link); - while ((*(page_ptr++) = fgetc(input)) != '}'); - *(page_ptr - 1) = '\0'; + memcpy(page, link, 1024); - char pagename[1024]; - size_t i; - for (i = 0; page[i] != '\0'; i++) { - pagename[i] = (page[i] == '-' ? ' ' : page[i]); - } - pagename[i] = '\0'; + for (size_t i = 0; link[i] != '\0'; i++) + if (link[i] >= 'A' && link[i] <= 'Z') link[i] = link[i] + 32; - fprintf(output, "{%s}", page, pagename); + for (size_t i = 0; page[i] != '\0'; i++) + if (page[i] == '-') page[i] = ' '; + + fprintf(output, "{%s}", link, page); } bool diff --git a/gen.sh b/gen.sh index 14badf2..570517b 100755 --- a/gen.sh +++ b/gen.sh @@ -2,7 +2,10 @@ # Strip the CSS file of whitespace to reduce file size echo "Generating CSS" -tr -d " \t\n\r" < resources/style-formatted.css > resources/style.css +sed "s/FG/#ddd/g" < resources/style-formatted.css | + sed "s/BG/#111/g" | + sed "s/CODEBG/#1a1a1a/g" | + tr -d " \t\n\r" > resources/style.css # Generate HTML pages from Writan sources echo "Generating pages" diff --git a/resources/style-formatted.css b/resources/style-formatted.css index 445db51..a71296a 100644 --- a/resources/style-formatted.css +++ b/resources/style-formatted.css @@ -1,15 +1,6 @@ -:root { - --fg: #ddd; - --bg: #111; - --code-bg: #1a1a1a; - /* --bg: #eee; */ - /* --fg: #111; */ - /* --code-bg: #dedede */ -} - body { - color: var(--fg); - background: var(--bg); + color: FG; + background: BG; font-family: serif; margin: 2em; max-width: 50em; @@ -18,22 +9,22 @@ body { } a { - color: var(--fg); + color: FG; text-decoration: none; } a:hover { - color: var(--bg); - background: var(--fg); + color: BG; + background: FG; } pre { - background: var(--code-bg); + background: BG; padding: 0.5em; } code { - background: var(--code-bg); + background: CODEBG; padding: 0.2em; } diff --git a/site-src/c.wtn b/site-src/c.wtn index 9304a3c..5af594d 100644 --- a/site-src/c.wtn +++ b/site-src/c.wtn @@ -1,9 +1,9 @@ * C -The C {programming-language} was developed at Bell Labs in the 1970s to -implement the original UNIX kernel and userland. It's a general purpose, -imperative systems programming language with a weak, static typing dicipline -(due to void* and dynamic type casts). +The C {programming-languages programming language} was developed at Bell Labs in +the 1970s to implement the original UNIX kernel and userland. It's a general +purpose, imperative systems programming language with a static, weak typing +dicipline (due to void* and dynamic type casts). It is an extremely portable language, with compilers available on most systems. diff --git a/site-src/emacs.wtn b/site-src/emacs.wtn index ad9b90d..8c31172 100644 --- a/site-src/emacs.wtn +++ b/site-src/emacs.wtn @@ -6,7 +6,7 @@ GNU Emacs. Others include edwin for the MIT/GNU Scheme system and Zmacs for the Open Genera OS. Emacs editors are configured through some programming language, usually a -dialect of {lisp Lisp}. This is what gives them their powerful extension +dialect of {Lisp}. This is what gives them their powerful extension properties. GNU Emacs and XEmacs uses Emacs Lisp, a Common Lisp inspired dialect. Because of its extensibility, Emacs has become a target for applications on its own, trancending the original intent of being merely a text diff --git a/site-src/index.wtn b/site-src/index.wtn index fc2bd7e..8768cd5 100644 --- a/site-src/index.wtn +++ b/site-src/index.wtn @@ -1,6 +1,6 @@ * Index -Welcome to {codex Codex}. +Welcome to {Codex}. {site-index Full list of pages in Codex} @@ -8,6 +8,6 @@ Welcome to {codex Codex}. ** Topics -{computation Computation} -{language Language} -{aesthetic Aesthetic} +{Computation} +{Language} +{Aesthetic} diff --git a/site-src/programming-languages.wtn b/site-src/programming-languages.wtn index 7ef456f..17d3c2c 100644 --- a/site-src/programming-languages.wtn +++ b/site-src/programming-languages.wtn @@ -2,6 +2,6 @@ Programming languages are formal languages used to express computational logic. -{c C} -{lisp Lisp} -{haskell Haskell} +{Lisp} +{C} +{Haskell} diff --git a/site-src/writan.wtn b/site-src/writan.wtn index f64c84c..1609eda 100644 --- a/site-src/writan.wtn +++ b/site-src/writan.wtn @@ -1,7 +1,7 @@ * Writan -Writan is the formatting language used to generate pages for {codex Codex}. It -only has a few distinct formatting rules. +Writan is the formatting language used to generate pages for {Codex}. It only +has a few distinct formatting rules. It uses the file extension ".wtn".