Skip to content

Commit 8169f24

Browse files
numbered list counter fix
1 parent 76cc177 commit 8169f24

File tree

1 file changed

+68
-3
lines changed

1 file changed

+68
-3
lines changed

typescript/src/renderer/styles/lists.css

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,73 @@
2828
align-items: flex-start;
2929
}
3030

31-
/* Counter for numbered lists */
31+
/*
32+
33+
Numbered List Counter System
34+
35+
CSS counters automatically number list items:
36+
- counter-increment: Adds 1 to 'list-number' counter for each numbered list item
37+
- counter-reset: Resets 'list-number' to 0 when starting a new sequence
38+
39+
Counter resets in two scenarios:
40+
1. :first-child - First numbered list in any container
41+
2. After non-list content - When numbered list follows paragraph, code, etc.
42+
43+
Example HTML structure:
44+
<div class="page-content">
45+
<li class="notion-numbered_list-block">Item 1</li> ← :first-child reset
46+
<li class="notion-numbered_list-block">Item 2</li> ← Continue sequence
47+
<p class="notion-paragraph-block">Text</p> ← Non-list content
48+
<li class="notion-numbered_list-block">Item 1</li> ← Adjacent sibling reset
49+
<li class="notion-numbered_list-block">Item 2</li> ← Continue sequence
50+
</div>
51+
52+
*/
53+
54+
/* Increment counter for each numbered list item */
3255
.notion-numbered_list-block {
3356
counter-increment: list-number 1;
3457
}
3558

36-
/* Reset counter for first numbered list item or when starting a new sequence */
59+
/*
60+
Reset counter when starting a new numbered list sequence
61+
62+
Selector: .notion-numbered_list-block:first-child
63+
Targets: Numbered list items that are the very first element in their container
64+
65+
Example HTML structure:
66+
<div class="page-content">
67+
<li class="notion-numbered_list-block">Item 1</li> ← :first-child - Reset counter here
68+
<li class="notion-numbered_list-block">Item 2</li> ← Continue sequence
69+
<li class="notion-numbered_list-block">Item 3</li> ← Continue sequence
70+
</div>
71+
72+
*/
3773
.notion-numbered_list-block:first-child {
3874
counter-reset: list-number 0;
3975
}
4076

41-
/* Alternative: Reset when previous sibling is not a numbered list */
77+
/*
78+
Reset counter when numbered list follows non-list content
79+
80+
Selector: *:not(.notion-numbered_list-block) + .notion-numbered_list-block
81+
82+
Breakdown:
83+
- *:not(.notion-numbered_list-block) = Any element that is NOT a numbered list item
84+
- + = Adjacent sibling combinator (immediately followed by)
85+
- .notion-numbered_list-block = A numbered list item
86+
87+
Example HTML structure:
88+
<div class="page-content">
89+
<p class="notion-paragraph-block">Some text</p>
90+
<li class="notion-numbered_list-block">Item 1</li> ← Reset counter here (follows paragraph)
91+
<li class="notion-numbered_list-block">Item 2</li> ← Continue sequence
92+
<pre class="notion-code-block">Code</pre>
93+
<li class="notion-numbered_list-block">Item 1</li> ← Reset counter here (follows code)
94+
<li class="notion-numbered_list-block">Item 2</li> ← Continue sequence
95+
</div>
96+
97+
*/
4298
*:not(.notion-numbered_list-block) + .notion-numbered_list-block {
4399
counter-reset: list-number 0;
44100
}
@@ -53,6 +109,15 @@
53109
line-height: var(--jsondoc-line-height-tight);
54110
}
55111

112+
/*
113+
Display the counter value as visible numbers
114+
115+
counter(list-number): Reads current value of 'list-number' counter and displays it
116+
counter(list-number) returns "1", "2", "3", etc.
117+
Combined with ". " to create "1. ", "2. ", "3. " format
118+
min-width + text-align: right ensures consistent alignment regardless of digit count
119+
120+
*/
56121
.notion-numbered_list-block::before {
57122
content: counter(list-number) ". ";
58123
font-size: var(--jsondoc-font-size-body);

0 commit comments

Comments
 (0)