nihdoc

WIP markup parser (txt -> html)
git clone git://git.alexkarle.com.com/blag
Log | Files | Refs | README | LICENSE

commit 413ca68a9606500ea8766ad7c4d1d0cf91c1287d (patch)
parent a6dc7f2f92162dc9a9930c3fe676c23a03ef35b8
Author: Alex Karle <alex@alexkarle.com>
Date:   Wed, 15 Dec 2021 21:57:13 -0500

Add support for wrapped lists

Diffstat:
Mblag.c | 30++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/blag.c b/blag.c @@ -10,9 +10,9 @@ * * <p> tags around paragraphs * - * * bullets (non-nested) + * * bullets (non-nested), breaks allowed if indented * - * 1. numerical lists (non-nested) + * 1. numerical lists (non-nested), breaks allowed if indented * * > quotes * @@ -77,16 +77,14 @@ int closeblock(int in, int hlvl) { printf("</blockquote>\n"); } else if (in == ULIST) { in = ULIST_BREAK; - printf("</li>"); } else if (in == ULIST_BREAK) { in = NONE; - printf("</ul>\n"); + printf("\n</li>\n</ul>\n"); } else if (in == OLIST) { in = OLIST_BREAK; - printf("</li>"); } else if (in == OLIST_BREAK) { in = NONE; - printf("</ol>\n"); + printf("\n</li>\n</ol>\n"); } else { /* keep in as is */ } @@ -151,19 +149,25 @@ int parse() { printf("<h%d>", hlvl); in = HEADER; } else if (in == ULIST_START) { - printf("<ul>\n <li>"); + printf("<ul>\n<li>\n"); in = ULIST; } else if (in == ULIST_PARSE) { - printf(" <li>"); + printf("\n</li>\n<li>\n"); in = ULIST; } else if (in == OLIST_START) { - printf("<ol>\n <li>"); + printf("<ol>\n<li>\n"); in = OLIST; } else if (in == OLIST_PARSE) { - printf(" <li>"); + printf("\n</li>\n<li>\n"); in = OLIST; - } else if (in == NONE || in == OLIST_BREAK || in == ULIST_BREAK) { + } else if (in == NONE) { /* no op */ + } else if (in == ULIST_BREAK) { + /* assume it's a continuation! */ + in = ULIST; + } else if (in == OLIST_BREAK) { + /* assume it's a continuation! */ + in = OLIST; } else { putchar(c); } @@ -269,7 +273,9 @@ int parse() { break; case '\n': in = closeblock(in, hlvl); - putchar(c); + if (in != ULIST_BREAK && in != OLIST_BREAK) { + putchar(c); + } break; default: if (in == NONE) {