Skip to content

Commit

Permalink
Use 3 spaces by default for -tman/-tms lists.
Browse files Browse the repository at this point in the history
Ordered and unordered lists get 3 spaces minimum, with space increasing
depending upon an ordered list's ending marker number.
  • Loading branch information
kristapsdz committed Apr 2, 2023
1 parent 0156f59 commit d6d0714
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 32 deletions.
37 changes: 35 additions & 2 deletions nroff.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ struct bnode {
TAILQ_ENTRY(bnode) entries;
};

/*
* When creating space for list markers (e.g., "1."), what is the
* minimum space used. This is what's used for bullets and as a
* starting width for lists under 10 items.
*/
static const size_t NROFF_MIN_LI_MARK_WIDTH = 3;

TAILQ_HEAD(bnodeq, bnode);

/*
Expand Down Expand Up @@ -964,12 +971,37 @@ rndr_listitem(struct bnodeq *obq, const struct lowdown_node *n,
{
struct bnode *bn;
const char *box;
size_t total = 0, numsize;

/*
* When indenting for the number of bullet preceding the line of
* text, use 3 spaces as the default, which fits bullets and any
* list numbering up to 10. For ordered lists beyond 10 in
* total count, increase the spacing accordingly, capping at 10.
*/

if (param->flags & HLIST_FL_ORDERED) {
if (n->parent != NULL &&
n->parent->type == LOWDOWN_LIST)
total = n->parent->rndr_list.items +
(n->parent->rndr_list.start - 1);

/* Yes, a little ridiculous, but doesn't hurt. */

numsize = total < 10 ? 0 :
total < 100 ? 1 :
total < 1000 ? 2 :
total < 10000 ? 3 :
total < 100000 ? 4 :
total < 1000000 ? 5 :
total < 10000000 ? 6 :
7;

numsize += NROFF_MIN_LI_MARK_WIDTH;
if ((bn = bqueue_block(obq, ".IP")) == NULL)
return 0;
if (asprintf(&bn->nargs,
"\"%zu. \"", param->num) == -1)
"\"%zu.\" %zu", param->num, numsize) == -1)
return 0;
} else if (param->flags & HLIST_FL_UNORDERED) {
if (param->flags & HLIST_FL_CHECKED)
Expand All @@ -980,7 +1012,8 @@ rndr_listitem(struct bnodeq *obq, const struct lowdown_node *n,
box = "(bu";
if ((bn = bqueue_block(obq, ".IP")) == NULL)
return 0;
if (asprintf(&bn->nargs, "\"\\%s\" 2", box) == -1)
if (asprintf(&bn->nargs, "\"\\%s\" %zu",
box, NROFF_MIN_LI_MARK_WIDTH) == -1)
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion regress/footnote-in-table.man
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Now\u\s-34\s+3\d
\0\fI\u\s-33\s+3\d\fP\0three
.PP
hello
.IP "\(bu" 2
.IP "\(bu" 3
world
.LP
\0\fI\u\s-34\s+3\d\fP\0four
2 changes: 1 addition & 1 deletion regress/footnote-in-table.ms
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ two
three
.PP
hello
.IP "\(bu" 2
.IP "\(bu" 3
world
.FE
T}
Expand Down
15 changes: 15 additions & 0 deletions regress/list-marker-alignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- 3 spaces
* 3 spaces
1. 3 spaces
2. 3 spaces

a

10. 4 spaces

b

100. 5 spaces
100. 5 spaces

still 5 spaces
4 changes: 2 additions & 2 deletions regress/list-with-sublists.man
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.IP "\(bu" 2
.IP "\(bu" 3
list
.IP
with paragraph
.RS
.IP "\(bu" 2
.IP "\(bu" 3
inner list
.IP
inner para
Expand Down
4 changes: 2 additions & 2 deletions regress/list-with-sublists.ms
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.IP "\(bu" 2
.IP "\(bu" 3
list
.IP
with paragraph
.RS
.IP "\(bu" 2
.IP "\(bu" 3
inner list
.IP
inner para
Expand Down
24 changes: 12 additions & 12 deletions regress/simple.man
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ Paragraphs are separated by a blank line.
.PP
2nd paragraph. \fIItalic\fR, \fBbold\fR, and \fCmonospace\fR. Itemized lists
look like:
.IP "\(bu" 2
.IP "\(bu" 3
this one
.if n \
.sp -1
.if t \
.sp -0.25v
.IP "\(bu" 2
.IP "\(bu" 3
that one
.if n \
.sp -1
.if t \
.sp -0.25v
.IP "\(bu" 2
.IP "\(bu" 3
the other one
.LP
Note that \(em not considering the asterisk \(em the actual text
Expand All @@ -38,19 +38,19 @@ Unicode is supported. ☺
An h2 header
.LP
Here\(cqs a numbered list:
.IP "1. "
.IP "1." 3
first item
.if n \
.sp -1
.if t \
.sp -0.25v
.IP "2. "
.IP "2." 3
second item
.if n \
.sp -1
.if t \
.sp -0.25v
.IP "3. "
.IP "3." 3
third item
.LP
Note again how the actual text starts at 4 columns in (4 characters
Expand Down Expand Up @@ -85,27 +85,27 @@ for i in range(10):
An h3 header
.LP
Now a nested list:
.IP "1. "
.IP "1." 3
First, get these ingredients:
.RS
.IP "\(bu" 2
.IP "\(bu" 3
carrots
.if n \
.sp -1
.if t \
.sp -0.25v
.IP "\(bu" 2
.IP "\(bu" 3
celery
.if n \
.sp -1
.if t \
.sp -0.25v
.IP "\(bu" 2
.IP "\(bu" 3
lentils
.RE
.IP "2. "
.IP "2." 3
Boil some water.
.IP "3. "
.IP "3." 3
Dump everything in the pot and follow
this algorithm:
.LP
Expand Down
24 changes: 12 additions & 12 deletions regress/simple.ms
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ Paragraphs are separated by a blank line.
.PP
2nd paragraph. \fIItalic\fR, \fBbold\fR, and \fCmonospace\fR. Itemized lists
look like:
.IP "\(bu" 2
.IP "\(bu" 3
this one
.if n \
.sp -1
.if t \
.sp -0.25v
.IP "\(bu" 2
.IP "\(bu" 3
that one
.if n \
.sp -1
.if t \
.sp -0.25v
.IP "\(bu" 2
.IP "\(bu" 3
the other one
.LP
Note that \(em not considering the asterisk \(em the actual text
Expand All @@ -42,19 +42,19 @@ An h2 header
.pdfhref M an-h2-header
.LP
Here\(cqs a numbered list:
.IP "1. "
.IP "1." 3
first item
.if n \
.sp -1
.if t \
.sp -0.25v
.IP "2. "
.IP "2." 3
second item
.if n \
.sp -1
.if t \
.sp -0.25v
.IP "3. "
.IP "3." 3
third item
.LP
Note again how the actual text starts at 4 columns in (4 characters
Expand Down Expand Up @@ -97,27 +97,27 @@ An h3 header
.pdfhref M an-h3-header
.LP
Now a nested list:
.IP "1. "
.IP "1." 3
First, get these ingredients:
.RS
.IP "\(bu" 2
.IP "\(bu" 3
carrots
.if n \
.sp -1
.if t \
.sp -0.25v
.IP "\(bu" 2
.IP "\(bu" 3
celery
.if n \
.sp -1
.if t \
.sp -0.25v
.IP "\(bu" 2
.IP "\(bu" 3
lentils
.RE
.IP "2. "
.IP "2." 3
Boil some water.
.IP "3. "
.IP "3." 3
Dump everything in the pot and follow
this algorithm:
.LP
Expand Down

0 comments on commit d6d0714

Please sign in to comment.