Add numbered lists

master
Drew DeVault 7 years ago
parent 4f0f1b778c
commit ac51eba95d
  1. 19
      scdoc.1.scd
  2. 29
      src/main.c

@ -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

@ -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);

Loading…
Cancel
Save