[writan/format] add image support [visual-snow] add visual example
This commit is contained in:
parent
2ddd255454
commit
7980699b35
3
TODO.org
3
TODO.org
|
@ -1,12 +1,9 @@
|
|||
Writan:
|
||||
- Image support.
|
||||
- Additional error handling in the formatter.
|
||||
- Remove extraneous <p> tags in output.
|
||||
|
||||
Pages:
|
||||
- Add a category theory page (more general, math).
|
||||
- Improve visual snow page with graphic examples.
|
||||
|
||||
Orphan pages:
|
||||
- Visual snow
|
||||
- Emacs
|
||||
|
|
40
format.c
40
format.c
|
@ -1,3 +1,4 @@
|
|||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
@ -277,6 +278,29 @@ emit_blockquote(FILE *input, FILE *output)
|
|||
fprintf(output, "</blockquote>\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, "<img src=\"../resources/img/%s\" />", 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, "<p>");
|
||||
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);
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 248 KiB |
|
@ -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
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue