[writan] make implicit links better

This commit is contained in:
opfez 2021-08-21 19:52:20 +02:00
parent c6628b5bce
commit 0ba2202cec
8 changed files with 40 additions and 42 deletions

View File

@ -136,7 +136,12 @@ void
get_link(FILE *input, char *out) get_link(FILE *input, char *out)
{ {
char c; 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) if (c == EOF)
die("End of file encountered while parsing link."); die("End of file encountered while parsing link.");
*(out)++ = c; *(out)++ = c;
@ -161,20 +166,19 @@ emit_internal_implicit_link(FILE *input, FILE *output)
{ {
fseek(input, -1, SEEK_CUR); fseek(input, -1, SEEK_CUR);
char link[1024];
char page[1024]; char page[1024];
char *page_ptr = page; get_link(input, link);
while ((*(page_ptr++) = fgetc(input)) != '}'); memcpy(page, link, 1024);
*(page_ptr - 1) = '\0';
char pagename[1024]; for (size_t i = 0; link[i] != '\0'; i++)
size_t i; if (link[i] >= 'A' && link[i] <= 'Z') link[i] = link[i] + 32;
for (i = 0; page[i] != '\0'; i++) {
pagename[i] = (page[i] == '-' ? ' ' : page[i]);
}
pagename[i] = '\0';
fprintf(output, "<a href=\"%s.html\">{%s}</a>", page, pagename); for (size_t i = 0; page[i] != '\0'; i++)
if (page[i] == '-') page[i] = ' ';
fprintf(output, "<a href=\"%s.html\">{%s}</a>", link, page);
} }
bool bool

5
gen.sh
View File

@ -2,7 +2,10 @@
# Strip the CSS file of whitespace to reduce file size # Strip the CSS file of whitespace to reduce file size
echo "Generating CSS" 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 # Generate HTML pages from Writan sources
echo "Generating pages" echo "Generating pages"

View File

@ -1,15 +1,6 @@
:root {
--fg: #ddd;
--bg: #111;
--code-bg: #1a1a1a;
/* --bg: #eee; */
/* --fg: #111; */
/* --code-bg: #dedede */
}
body { body {
color: var(--fg); color: FG;
background: var(--bg); background: BG;
font-family: serif; font-family: serif;
margin: 2em; margin: 2em;
max-width: 50em; max-width: 50em;
@ -18,22 +9,22 @@ body {
} }
a { a {
color: var(--fg); color: FG;
text-decoration: none; text-decoration: none;
} }
a:hover { a:hover {
color: var(--bg); color: BG;
background: var(--fg); background: FG;
} }
pre { pre {
background: var(--code-bg); background: BG;
padding: 0.5em; padding: 0.5em;
} }
code { code {
background: var(--code-bg); background: CODEBG;
padding: 0.2em; padding: 0.2em;
} }

View File

@ -1,9 +1,9 @@
* C * C
The C {programming-language} was developed at Bell Labs in the 1970s to The C {programming-languages programming language} was developed at Bell Labs in
implement the original UNIX kernel and userland. It's a general purpose, the 1970s to implement the original UNIX kernel and userland. It's a general
imperative systems programming language with a weak, static typing dicipline purpose, imperative systems programming language with a static, weak typing
(due to void* and dynamic type casts). dicipline (due to void* and dynamic type casts).
It is an extremely portable language, with compilers available on most systems. It is an extremely portable language, with compilers available on most systems.

View File

@ -6,7 +6,7 @@ GNU Emacs. Others include edwin for the MIT/GNU Scheme system and Zmacs for the
Open Genera OS. Open Genera OS.
Emacs editors are configured through some programming language, usually a 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 properties. GNU Emacs and XEmacs uses Emacs Lisp, a Common Lisp inspired
dialect. Because of its extensibility, Emacs has become a target for dialect. Because of its extensibility, Emacs has become a target for
applications on its own, trancending the original intent of being merely a text applications on its own, trancending the original intent of being merely a text

View File

@ -1,6 +1,6 @@
* Index * Index
Welcome to {codex Codex}. Welcome to {Codex}.
{site-index Full list of pages in Codex} {site-index Full list of pages in Codex}
@ -8,6 +8,6 @@ Welcome to {codex Codex}.
** Topics ** Topics
{computation Computation} {Computation}
{language Language} {Language}
{aesthetic Aesthetic} {Aesthetic}

View File

@ -2,6 +2,6 @@
Programming languages are formal languages used to express computational logic. Programming languages are formal languages used to express computational logic.
{c C} {Lisp}
{lisp Lisp} {C}
{haskell Haskell} {Haskell}

View File

@ -1,7 +1,7 @@
* Writan * Writan
Writan is the formatting language used to generate pages for {codex Codex}. It Writan is the formatting language used to generate pages for {Codex}. It only
only has a few distinct formatting rules. has a few distinct formatting rules.
It uses the file extension ".wtn". It uses the file extension ".wtn".