jgm / djot.js

JavaScript implementation of djot
MIT License
146 stars 16 forks source link

Automatic enumeration for roman numeral lists #38

Closed hellux closed 1 year ago

hellux commented 1 year ago

Both decimal and alphabetic lists can be automatically enumerated, e.g:

0. a
0. b
0. c

a. c
a. b
a. c

yields

<ol>
<li>
a
</li>
<li>
b
</li>
<li>
c
</li>
</ol>
<ol type="a">
<li>
a
</li>
<li>
b
</li>
<li>
c
</li>
</ol>

However, trying to do the same with roman numerals instead yields an alphabetic list, starting at 'i':

i. a
i. b
i. c
<ol start="9" type="a">
<li>
a
</li>
<li>
b
</li>
<li>
c
</li>
</ol>

Currently, one seems to need at least two consecutive numbers to turn it into a roman numeral list:

i. a
ii. b
i. c
<ol type="i">
<li>
a
</li>
<li>
b
</li>
<li>
c
</li>
</ol>

This decreases the value of letting it automatically enumerate.

Would it be better to prioritize the roman over the alphabetic numbering in the previous case? One could for example consider any list that contains only roman digits to be a roman numeral list until the first non-roman digit is encountered. This would also remove the need to parse any numbers during the block parsing stage.

jgm commented 1 year ago

One could for example consider any list that contains only roman digits to be a roman numeral list until the first non-roman digit is encountered. This would also remove the need to parse any numbers during the block parsing stage.

I think we want a list

i. one
j. two

to be alpha-numbered.

The relevant code is getListStyles in src/blocks.ts. You'll see that there are two clauses that return two values (in an array). Swapping the order of these would prioritize roman numerals in ambiguous cases. That's probably a sensible thing to do, because lettered lists starting with i, v, c, l, m, d, and x and not continuing with another letter that would disambiguate things will be relatively rare. We'd want to make a similar change in djot.lua.

hellux commented 1 year ago

My suggestion was actually to consider

i. one
j. two

to be considered a single alpha-numbered list, because j is not a roman numeral. My suggestion was not to split it into two lists, one roman and one alpha-numbered. Instead, consider alpha-numbered compatible with roman-numbered and change the list type if a non-roman alphabetic number is encountered.

However, one possible caveat is that it may unexpectedly merge two lists, i.e.:

i. one
ii. two

a. one
b. two

would become one single loose alpha-numbered list.

I think your suggestion of simply prioritizing roman-numbering when there is ambiguity is reasonable also.