diff --git a/TODO.org b/TODO.org index 80cdecd..83c964c 100644 --- a/TODO.org +++ b/TODO.org @@ -1,12 +1,9 @@ Writan: - - Image support. - Additional error handling in the formatter. - Remove extraneous

tags in output. Pages: - Add a category theory page (more general, math). - - Improve visual snow page with graphic examples. Orphan pages: - - Visual snow - Emacs diff --git a/format.c b/format.c index 834b2b7..954d7fb 100644 --- a/format.c +++ b/format.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -277,6 +278,29 @@ emit_blockquote(FILE *input, FILE *output) fprintf(output, "\n"); } +void +emit_image(FILE *input, FILE *output) +{ + char buf[80]; + char *bufptr = buf; + + for(;;) { + char c = fgetc(input); + if (isspace(c)) + break; + else if (c == EOF) + die("EOF encountered while parsing image filename."); + else + *(bufptr++) = c; + } + + *bufptr = '\0'; + + fprintf(output, "", buf); + + fseek(input, -1L, SEEK_CUR); +} + /* main formatter */ void format(FILE *input, FILE *output) @@ -298,6 +322,21 @@ format(FILE *input, FILE *output) fprintf(output, "

"); emit_link(input, output); } + else if (c == '$') { /* maybe image */ + char buf[5]; + size_t i; + for (i = 0; i < 4; i++) + buf[i] = fgetc(input); + buf[i] = '\0'; + + if (!strcmp(buf, "img ")) { + emit_image(input, output); + } + else { + fseek(input, -4L, SEEK_CUR); + emit_sanitized_char(c, output); + } + } else if (c == '_') { fprintf(output, "%s", em_tags[in_em]); in_em = !in_em; @@ -360,7 +399,6 @@ main(int argc, char *argv[]) format(in, out); write_file(out, "resources/footer.html"); - fclose(in); fclose(out); } diff --git a/resources/img/visual-snow.gif b/resources/img/visual-snow.gif new file mode 100644 index 0000000..d6605de Binary files /dev/null and b/resources/img/visual-snow.gif differ diff --git a/resources/writan-example.txt b/resources/txt/writan-example.txt similarity index 87% rename from resources/writan-example.txt rename to resources/txt/writan-example.txt index 05bea77..452bb19 100644 --- a/resources/writan-example.txt +++ b/resources/txt/writan-example.txt @@ -34,3 +34,8 @@ You can inline ``code`` blocks. > multiple lines. One can mark emphasis by surrounding a word with _underscores_. + +An image is embedded like follows. The filename is expanded to +resources/img/image-file.png. + +$img image-file.png diff --git a/site-src/c.wtn b/site-src/c.wtn index 431a570..9304a3c 100644 --- a/site-src/c.wtn +++ b/site-src/c.wtn @@ -111,6 +111,6 @@ Casts to ``void*`` are implicit in C, so do not explicitly cast pointers to Indentation is done with 4 spaces. -I do not ``typedef`` my structs. +I do not ``typedef`` my structs nor my enums. Everything is named in snake case with all lower case letters. diff --git a/site-src/visual-snow.wtn b/site-src/visual-snow.wtn index ba448db..b917db2 100644 --- a/site-src/visual-snow.wtn +++ b/site-src/visual-snow.wtn @@ -1,5 +1,7 @@ * Visual snow +$img visual-snow.gif + Visual snow is a visual impairment which makes those affected see black, white or coloured semi-transparent dots in part of or the whole visual field. The effect tends to be more prevalent at lower light levels. Additional symptoms diff --git a/site-src/writan.wtn b/site-src/writan.wtn index 0915db0..f64c84c 100644 --- a/site-src/writan.wtn +++ b/site-src/writan.wtn @@ -5,7 +5,7 @@ only has a few distinct formatting rules. It uses the file extension ".wtn". -To get an overview over how it works, take a look at the {../resources/writan-example.txt +To get an overview over how it works, take a look at the {../resources/txt/writan-example.txt example document}. {https://tildegit.org/opfez/codex/branch/master/format.c Source code of the