From ac51eba95d7ae4cc9c5e0e2e723cb4a8f2840c2b Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 10 Dec 2017 12:21:50 -0500 Subject: [PATCH] Add numbered lists --- scdoc.1.scd | 19 ++++++++++++++++++- src/main.c | 29 ++++++++++++++++++++++------- diff --git a/scdoc.1.scd b/scdoc.1.scd index 012645b2161469e79b13472b6bae5bf73083fe48..0391a16e4355359224e4b5715973de220c26b65c 100644 --- a/scdoc.1.scd +++ b/scdoc.1.scd @@ -60,7 +60,7 @@ depth. ## LISTS -You may start bulleted lists with dashes, like so: +You may start bulleted lists with dashes (-), like so: ``` - Item 1 @@ -94,6 +94,23 @@ break it up onto two lines - Item 2 is shorter - But its children can go on for a while + +## NUMBERED LISTS + +Numbered lists are similar to normal lists, but begin with periods (.) instead +of dashes (-), like so: + +``` +. Item 1 +. Item 2 +. Item 3, + with multiple lines +``` + +. Item 1 +. Item 2 +. Item 3, + with multiple lines ## LITERAL TEXT diff --git a/src/main.c b/src/main.c index bede16439a577cd995d4ca578412dfb9efcdd5da..e6eaa67912ee2bdcfa920cc31ae0a527ba610653 100644 --- a/src/main.c +++ b/src/main.c @@ -176,22 +176,33 @@ *indent = i; return i; } -static void list_header(struct parser *p, const char *sym) { +static void list_header(struct parser *p, int *num) { roff_macro(p, "RS", "4", NULL); fprintf(p->output, ".ie n \\{\\\n"); - fprintf(p->output, "\\h'-04'%s\\h'+03'\\c\n", sym); + if (*num == -1) { + fprintf(p->output, "\\h'-0%d'%s\\h'+03'\\c\n", + *num >= 10 ? 5 : 4, "\\(bu"); + } else { + fprintf(p->output, "\\h'-0%d'%d.\\h'+03'\\c\n", + *num >= 10 ? 5 : 4, *num); + } fprintf(p->output, ".\\}\n"); fprintf(p->output, ".el \\{\\\n"); - roff_macro(p, "IP", sym, "4", NULL); + if (*num == -1) { + fprintf(p->output, ".IP %s 4\n", "\\(bu"); + } else { + fprintf(p->output, ".IP %d. 4\n", *num); + *num = *num + 1; + } fprintf(p->output, ".\\}\n"); } -static void parse_list(struct parser *p, int *indent) { +static void parse_list(struct parser *p, int *indent, int num) { uint32_t ch; if ((ch = parser_getch(p)) != ' ') { parser_fatal(p, "Expected space before start of list entry"); } - list_header(p, "\\(bu"); + list_header(p, &num); parse_text(p); bool closed = false; do { @@ -207,13 +218,14 @@ } parse_text(p); break; case '-': + case '.': if ((ch = parser_getch(p)) != ' ') { parser_fatal(p, "Expected space before start of list entry"); } if (!closed) { roff_macro(p, "RE", NULL); } - list_header(p, "\\(bu"); + list_header(p, &num); parse_text(p); closed = false; break; @@ -306,7 +318,10 @@ } parse_heading(p); break; case '-': - parse_list(p, &indent); + parse_list(p, &indent, -1); + break; + case '.': + parse_list(p, &indent, 1); break; case '`': parse_literal(p, &indent); -- 2.48.1