| 1 |
--- |
| 2 |
icon: lucide/list |
| 3 |
--- |
| 4 |
[:octicons-file-code-24:][_fancylists]{: .source-link } |
| 5 |
|
| 6 |
# FancyLists |
| 7 |
|
| 8 |
## Overview |
| 9 |
|
| 10 |
FancyLists is inspired by [Pandoc's list handling][pandoc-lists]. FancyLists extends the list handling formats to |
| 11 |
support parenthesis style lists along with additional ordered formats. |
| 12 |
|
| 13 |
``` |
| 14 |
1) Item 1 |
| 15 |
2) Item 2 |
| 16 |
i. Item 1 |
| 17 |
ii. Item 2 |
| 18 |
a. Item a |
| 19 |
b. Item b |
| 20 |
#. Item 1 |
| 21 |
#. Item 2 |
| 22 |
``` |
| 23 |
|
| 24 |
///// html | div.result |
| 25 |
1) Item 1 |
| 26 |
2) Item 2 |
| 27 |
i. Item 1 |
| 28 |
ii. Item 2 |
| 29 |
a. Item a |
| 30 |
b. Item b |
| 31 |
#. Item 1 |
| 32 |
#. Item 2 |
| 33 |
///// |
| 34 |
|
| 35 |
FancyLists adds the following features: |
| 36 |
|
| 37 |
- Support ordered lists with either a trailing dot or single right-parenthesis: `1.` or `1)`. |
| 38 |
- Support ordered lists with roman numeral formats, both lowercase and uppercase. Uppercase is treated as a different |
| 39 |
list type than lowercase. |
| 40 |
- Support ordered lists with alphabetical format, both lowercase and uppercase. Uppercase is treated as a different |
| 41 |
list type than lowercase. |
| 42 |
- Support a generic ordered list marker via `#.` or `#)`. These can be used in place of numerals and will inherit the |
| 43 |
type of the current list as long as they use the same convention (`.` or `)`). If used to start a list, decimal |
| 44 |
format will be assumed. Requires [SaneHeaders](./saneheaders.md) to be enabled. |
| 45 |
- Using a different list type will start a new list. Trailing dot vs parenthesis are treated as separate types. |
| 46 |
- Ordered lists are sensitive to the starting value and can restart a list or create a new list using the first value |
| 47 |
in the list. |
| 48 |
|
| 49 |
Additional ordered list types such as Roman numeral, alphabetical, and generic are optional and can be disabled via |
| 50 |
[options](#options). |
| 51 |
|
| 52 |
Ordered types are controlled by setting the `type` attribute to the appropriate value on the `#!html <ol>` element. If |
| 53 |
you have CSS that overrides styling, you may not see the appropriate types, so if you want control at the Markdown |
| 54 |
level, make sure CSS doesn't override the list styles or see the [styling](#styling) section for more info. |
| 55 |
|
| 56 |
List\ Types | HTML\ List\ Type |
| 57 |
----------------------- | ---------------- |
| 58 |
Decimal | 1 |
| 59 |
Lowercase Alphabetical | a |
| 60 |
Uppercase Alphabetical | A |
| 61 |
Lowercase Roman Numeral | i |
| 62 |
Uppercase Roman Numeral | I |
| 63 |
|
| 64 |
/// note |
| 65 |
We do not support Pandoc's list notation that includes full parentheses (`(marker)`). |
| 66 |
/// |
| 67 |
|
| 68 |
```py3 |
| 69 |
import markdown |
| 70 |
# SaneHeaders required for generic ordered styles `#.` and `#)` |
| 71 |
md = markdown.Markdown(extensions=['pymdownx.fancylists', 'pymdownx.saneheaders']) |
| 72 |
``` |
| 73 |
|
| 74 |
## Syntax |
| 75 |
|
| 76 |
Ordered lists have a number rules to determine when a list item is recognized and when a new list is created/restarted |
| 77 |
vs an item appended to the previous list. |
| 78 |
|
| 79 |
### Ordered List Rules |
| 80 |
|
| 81 |
1. A new list will be created if the list type changes. This occurs with: |
| 82 |
a. A switch between unordered and ordered. |
| 83 |
|
| 84 |
``` |
| 85 |
- Item 1 |
| 86 |
- Item 2 |
| 87 |
1. Item 1 |
| 88 |
2. Item 2 |
| 89 |
``` |
| 90 |
|
| 91 |
/// html | div.result |
| 92 |
- Item 1 |
| 93 |
- Item 2 |
| 94 |
1. Item 1 |
| 95 |
2. Item 2 |
| 96 |
/// |
| 97 |
|
| 98 |
b. Change from using trailing dot or single right-parenthesis. |
| 99 |
|
| 100 |
``` |
| 101 |
1. Item 1 |
| 102 |
1. Item 2 |
| 103 |
1) Item 1 |
| 104 |
2) Item 2 |
| 105 |
``` |
| 106 |
|
| 107 |
/// html | div.result |
| 108 |
1. Item 1 |
| 109 |
2. Item 2 |
| 110 |
1) Item 1 |
| 111 |
2) Item 2 |
| 112 |
/// |
| 113 |
|
| 114 |
c. A change between using uppercase and lowercase. |
| 115 |
``` |
| 116 |
a. Item a |
| 117 |
b. Item a |
| 118 |
A. Item A |
| 119 |
B. Item B |
| 120 |
``` |
| 121 |
|
| 122 |
/// html | div.result |
| 123 |
a. Item a |
| 124 |
b. Item b |
| 125 |
A. Item A |
| 126 |
B. Item B |
| 127 |
/// |
| 128 |
|
| 129 |
d. A change in ordered type: numerical, roman numeral, alphabetical, or generic. |
| 130 |
|
| 131 |
``` |
| 132 |
#. Item 1 |
| 133 |
#. Item 2 |
| 134 |
a. Item a |
| 135 |
b. Item b |
| 136 |
1. Item 1 |
| 137 |
2. Item 2 |
| 138 |
``` |
| 139 |
|
| 140 |
/// html | div.result |
| 141 |
#. Item 1 |
| 142 |
#. Item 2 |
| 143 |
a. Item a |
| 144 |
b. Item b |
| 145 |
1. Item 1 |
| 146 |
2. Item 2 |
| 147 |
/// |
| 148 |
|
| 149 |
2. Generic list items inherit type from the current list and if starting a new list will assume the decimal type. List |
| 150 |
items following a generic list will not cause a new list as long as the list item is consistent with the current |
| 151 |
list type. |
| 152 |
|
| 153 |
``` |
| 154 |
i. item i |
| 155 |
#. item ii |
| 156 |
#. item iii |
| 157 |
iv. item iv |
| 158 |
``` |
| 159 |
|
| 160 |
//// html | div.result |
| 161 |
i. item i |
| 162 |
#. item ii |
| 163 |
#. item iii |
| 164 |
iv. item iv |
| 165 |
//// |
| 166 |
|
| 167 |
3. If using uppercase list markers, a list marker consisting of a single uppercase letter followed by a dot will |
| 168 |
require two spaces after the marker instead of the usual 1 to avoid false positive matches with names that start |
| 169 |
with an initial. |
| 170 |
|
| 171 |
``` |
| 172 |
B. Russell was an English philosopher. |
| 173 |
|
| 174 |
A. This is a list. |
| 175 |
``` |
| 176 |
|
| 177 |
/// html | div.result |
| 178 |
B. Russell was an English philosopher. |
| 179 |
|
| 180 |
A. This is a list. |
| 181 |
/// |
| 182 |
|
| 183 |
4. If a roman numeral consisting of a single letter is used within an alphabetical list (assuming no indication of a |
| 184 |
list type change) the list item will be treated as an alphabetical list item. See [special cases](#special-cases) |
| 185 |
on how to navigate these edge cases. |
| 186 |
|
| 187 |
``` |
| 188 |
iii. Item 3 |
| 189 |
iv. Item 4 |
| 190 |
v. Item 5 |
| 191 |
|
| 192 |
--- |
| 193 |
|
| 194 |
v. Item v |
| 195 |
w. Item w |
| 196 |
x. Item x |
| 197 |
``` |
| 198 |
|
| 199 |
/// html | div.result |
| 200 |
iii. Item 3 |
| 201 |
iv. Item 4 |
| 202 |
v. Item 5 |
| 203 |
|
| 204 |
--- |
| 205 |
|
| 206 |
v. Item v |
| 207 |
w. Item w |
| 208 |
x. Item x |
| 209 |
/// |
| 210 |
|
| 211 |
5. If a single letter is used to start a list, it is assumed to be an alphabetical list unless the first letter is `i` |
| 212 |
or `I`. See [special cases](#special-cases) |
| 213 |
on how to navigate these edge cases. |
| 214 |
|
| 215 |
``` |
| 216 |
h. Item h |
| 217 |
i. Item i |
| 218 |
j. Item j |
| 219 |
|
| 220 |
--- |
| 221 |
|
| 222 |
i. Item 1 |
| 223 |
ii. Item 2 |
| 224 |
iii. Item 3 |
| 225 |
``` |
| 226 |
|
| 227 |
/// html | div.result |
| 228 |
h. Item h |
| 229 |
i. Item i |
| 230 |
j. Item j |
| 231 |
|
| 232 |
--- |
| 233 |
|
| 234 |
i. Item 1 |
| 235 |
ii. Item 2 |
| 236 |
iii. Item 3 |
| 237 |
/// |
| 238 |
|
| 239 |
### Roman Numeral Rules |
| 240 |
|
| 241 |
The Roman numeral system consists of 7 numerals that are combined to make all the numbers in the system. |
| 242 |
|
| 243 |
Numeral | Decimal |
| 244 |
------- | ------- |
| 245 |
I | 1 |
| 246 |
V | 5 |
| 247 |
X | 10 |
| 248 |
L | 50 |
| 249 |
C | 100 |
| 250 |
D | 500 |
| 251 |
M | 1000 |
| 252 |
|
| 253 |
These numbers, depending on how they are combined, are added and subtracted to make bigger numbers. |
| 254 |
|
| 255 |
In modern day, many assume more strict rules, but looking at historical examples, the system was for less strict. |
| 256 |
FancyLists airs on the side of being a little less strict to be more forgiving of user inputs, browsers will always |
| 257 |
render them in a more strict form regardless of what the user inputs. |
| 258 |
|
| 259 |
#### Rules of Addition |
| 260 |
|
| 261 |
When Roman numerals are chained in descending order according to denomination, the values are just added together. |
| 262 |
With that said, there are a few rules as to how the numerals are allowed to be sequenced. |
| 263 |
|
| 264 |
1. Numerals must be arranged in descending order of size. |
| 265 |
2. `D`, `L`, and `V` can each only appear once. |
| 266 |
3. `M`, `C`, and `X` cannot be equaled or exceeded by smaller denominations. |
| 267 |
|
| 268 |
It should be noted that while the user is encouraged to generally follow rule 3 as it is outlined, this is the only rule |
| 269 |
that FancyLists does not explicitly enforce. FancyLists actually enforces the rule as shown below. |
| 270 |
|
| 271 |
> `M`, `C`, and `X` cannot be exceeded by smaller denominations. |
| 272 |
|
| 273 |
Generally, it is recommended to use higher denomination numerals when possible, like using `X` instead of `VIIIII`. |
| 274 |
Despite this recommendation, we allow some flexibility in this area for user input. Additionally, this flexibility makes |
| 275 |
it easier to handle certain [special cases](#special-cases) that we will be covered later. Regardless of how the user |
| 276 |
inputs the numbers, browsers will use a more strict rendering. |
| 277 |
|
| 278 |
#### Rules of Subtraction |
| 279 |
|
| 280 |
When using only additive rules, many Roman numerals can get quite long. Subtractive rules allow for shortening additive |
| 281 |
sequences with shorter subtractive sequences. In subtractive sequences, certain lesser denomination can actually be |
| 282 |
placed before larger denominations, and when done, the lesser denomination is subtracted from the larger denomination. |
| 283 |
As an example, with subtractive rules, `IIII` can be written more simply as `IV` which subtracts 1 from 5. The rules are |
| 284 |
specified below. |
| 285 |
|
| 286 |
1. Only one `I`, `X`, and `C` can be used as the leading numeral in part of a subtractive pair. |
| 287 |
2. When `I`, `X`, and `C` are used as the lead in a subtractive pair, they can't be used immediately after the |
| 288 |
subtractive pair. So `IXI` is invalid. |
| 289 |
2. `I` can only be placed before `V` and `X`. |
| 290 |
3. `X` can only be placed before `L` and `C`. |
| 291 |
4. `C` can only be placed before `D` and `M`. |
| 292 |
|
| 293 |
### Special Cases |
| 294 |
|
| 295 |
If you've been paying attention, you may have noticed that when alphabetical lists and Roman numeral lists are **both** |
| 296 |
enabled, there arises some ambiguous cases. Currently if `I` occurs in the middle of an alphabetical list, it is assumed |
| 297 |
to be an alphabetical list item, but if it starts a list, it is assumed to be a Roman numeral list item. The reverse is |
| 298 |
true for `M`, `D`, `C`, `L`, `X`, and `V` where it is assumed that these are Roman numeral list items if they occur in |
| 299 |
the middle of a Roman numeral list, but are assumed to be alphabetical list items if they start a list. |
| 300 |
|
| 301 |
/// note |
| 302 |
It should be noted that these issues exists in pretty much all implementations that support this way of including both |
| 303 |
alphabetically ordered and Roman numeral ordered lists. This is not an issue specific to this implementation. |
| 304 |
/// |
| 305 |
|
| 306 |
In the example below, we can see that using `v` in the middle of a Roman numeral list works just fine, but if we try |
| 307 |
and restart/start a new list with `v`, we get an alphabetically ordered list. |
| 308 |
|
| 309 |
``` |
| 310 |
iii. item 3 |
| 311 |
iv. item 4 |
| 312 |
v. item 5 |
| 313 |
|
| 314 |
--- |
| 315 |
|
| 316 |
v. v |
| 317 |
w. w |
| 318 |
``` |
| 319 |
|
| 320 |
/// html | div.result |
| 321 |
iii. item 3 |
| 322 |
iv. item 4 |
| 323 |
v. item 5 |
| 324 |
|
| 325 |
--- |
| 326 |
|
| 327 |
v. item v |
| 328 |
w. item w |
| 329 |
/// |
| 330 |
|
| 331 |
As noted in ["additive rules"](#rules-of-addition), while we encourage users to generally not represent numerals such as |
| 332 |
`X` with `VIIIII`, we do not enforce the restriction. The reason is for these specific edge cases. In these few |
| 333 |
instances ignoring this rule can help bypass this conflict. If you need to start or restart a Roman numeral list value |
| 334 |
consisting of a single numeral (that is not `I`), we can use the flexibility in the rules to mitigate the issue. |
| 335 |
Regardless of our input, browsers will render these list items in the more common, strict format. |
| 336 |
|
| 337 |
``` |
| 338 |
IIIII. Roman numeral V |
| 339 |
|
| 340 |
--- |
| 341 |
|
| 342 |
VIIIII. Roman numeral X |
| 343 |
|
| 344 |
--- |
| 345 |
|
| 346 |
XXXXX. Roman numeral L |
| 347 |
|
| 348 |
--- |
| 349 |
|
| 350 |
LXXXXX. Roman numeral C |
| 351 |
|
| 352 |
--- |
| 353 |
|
| 354 |
CCCCC. Roman numeral D |
| 355 |
|
| 356 |
--- |
| 357 |
|
| 358 |
DCCCCC. Roman numeral M |
| 359 |
|
| 360 |
``` |
| 361 |
|
| 362 |
/// html | div.result |
| 363 |
IIIII. Roman numeral V |
| 364 |
|
| 365 |
--- |
| 366 |
|
| 367 |
VIIIII. Roman numeral X |
| 368 |
|
| 369 |
--- |
| 370 |
|
| 371 |
XXXXX. Roman numeral L |
| 372 |
|
| 373 |
--- |
| 374 |
|
| 375 |
LXXXXX. Roman numeral C |
| 376 |
|
| 377 |
--- |
| 378 |
|
| 379 |
CCCCC. Roman numeral D |
| 380 |
|
| 381 |
--- |
| 382 |
|
| 383 |
DCCCCC. Roman numeral M |
| 384 |
/// |
| 385 |
|
| 386 |
The reverse case, where alphabetical lists cannot start with `I` (or `i`), cannot be mitigated in the aforementioned |
| 387 |
manner, but we can wrap it in a special [Block](./blocks/index.md) and specify the `start` and/or `type` manually. By |
| 388 |
setting the `type` to `a`, we will force the creation of a lowercase alphabetic list and the first list item will be |
| 389 |
included under it, parsing it under the assumption of a lowercase alphabetical list (if possible). If a `start` is |
| 390 |
given, the actual value of the first list item will be ignored. |
| 391 |
|
| 392 |
``` |
| 393 |
/// fancylists | type=a |
| 394 |
i. item i |
| 395 |
j. item j |
| 396 |
/// |
| 397 |
``` |
| 398 |
|
| 399 |
//// html | div.result |
| 400 |
/// fancylists | type=a |
| 401 |
i. item i |
| 402 |
j. item j |
| 403 |
/// |
| 404 |
//// |
| 405 |
|
| 406 |
This can also be applied to generic lists by also adding `start` value to anchor the first value. |
| 407 |
|
| 408 |
``` |
| 409 |
/// fancylists | type=a start=9 |
| 410 |
#. item i |
| 411 |
#. item j |
| 412 |
/// |
| 413 |
``` |
| 414 |
|
| 415 |
//// html | div.result |
| 416 |
/// fancylists | type=a start=9 |
| 417 |
#. item i |
| 418 |
#. item j |
| 419 |
/// |
| 420 |
//// |
| 421 |
|
| 422 |
If a more "strictly correct" mitigation is desired for the earlier mentioned Roman numeral conflict cases, wrapping |
| 423 |
the Roman numeral list will work as well. This allows for the use of more _proper_ Roman numerals. |
| 424 |
|
| 425 |
``` |
| 426 |
/// fancylists | type=I |
| 427 |
V. item V |
| 428 |
VI. item VI |
| 429 |
/// |
| 430 |
``` |
| 431 |
|
| 432 |
//// html | div.result |
| 433 |
/// fancylists | type=I |
| 434 |
V. item V |
| 435 |
VI. item VI |
| 436 |
/// |
| 437 |
//// |
| 438 |
|
| 439 |
## Styling |
| 440 |
|
| 441 |
By default, browsers should style ordered list types without any issues, but if you are displaying your content in HTML |
| 442 |
that already provides CSS for lists, you may have to override the CSS. This can sometimes be difficult, and if you want |
| 443 |
to style each type appropriately, CSS is currently lacking as the case sensitive attribute flag is not implemented in |
| 444 |
all browsers to properly target `type=a` vs `type=A`. |
| 445 |
|
| 446 |
To make styling easier, if you are struggling with getting the types properly styled, you can enable the `inject_style` |
| 447 |
[option](#options) to inject a style attribute on each `#!html <ol>` tag that sets the `list-style-type` to the |
| 448 |
appropriate value. |
| 449 |
|
| 450 |
If more advanced CSS styling is desired, and many browsers have not yet implemented the case-sensitive `s` flag for |
| 451 |
attribute selectors, it can be very hard to target an uppercase vs lowercase ordered list. To mitigate this issue, |
| 452 |
a class indicating the current list type can be injected into the `#!html <ol>` element. |
| 453 |
|
| 454 |
CSS\ Classes | |
| 455 |
------------------------ | |
| 456 |
`fancylists-decimal` | |
| 457 |
`fancylists-lower-alpha` | |
| 458 |
`fancylists-upper-alpha` | |
| 459 |
`fancylists-lower-roman` | |
| 460 |
`fancylists-upper-roman` | |
| 461 |
|
| 462 |
## Options |
| 463 |
|
| 464 |
Option | Type | Default | Description |
| 465 |
--------------------------- | -------- | ------------------------------------- | ------------ |
| 466 |
`additional_ordered_styles` | [string] | `#!py3 ['roman', 'alpha', 'generic']` | A list of additional ordered list styles. Accepted inputs: `roman`, `alpha`, and `generic`. |
| 467 |
`inject_style` | bool | `#!py3 False` | Inject styling into `ol` for list styling. |
| 468 |
`inject_class` | bool | `#!py3 False` | Inject class into `ol` for list styling. |