scdoc2mdoc

A fork of scdoc to output mdoc(7)
git clone git://git.sgregoratto.me/scdoc2mdoc
Log | Files | Refs | README | LICENSE

commit ac51eba95d7ae4cc9c5e0e2e723cb4a8f2840c2b
parent 4f0f1b778c1928571a0b90abe525e1af2579bd0f
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 10 Dec 2017 12:21:50 -0500

Add numbered lists

Diffstat:
Mscdoc.1.scd | 19++++++++++++++++++-
Msrc/main.c | 29++++++++++++++++++++++-------
2 files changed, 40 insertions(+), 8 deletions(-)

diff --git 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 @@ -95,6 +95,23 @@ level, plus two spaces. They will be rendered as a single list entry. - 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 You may turn off scdoc formatting and output literal text with escape codes and diff --git a/src/main.c b/src/main.c @@ -176,22 +176,33 @@ static int parse_indent(struct parser *p, int *indent, bool write) { 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 @@ static void parse_list(struct parser *p, int *indent) { 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 @@ static void parse_document(struct parser *p) { 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);