Skip to content

Commit be77c14

Browse files
committed
Auto-generate number-based TOC lists and headings
See #324
1 parent ab98c45 commit be77c14

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

src/assets/sass/modules/_lists.scss

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,91 @@ dd {
285285
content: "\2016" "\00A0"; // parallel bars
286286
}
287287
}
288+
289+
/**
290+
* Documentation custom TOC lists. Allows for 2 sub-levels of nesting.
291+
*
292+
* Example HTML:
293+
*
294+
* <ul id="markdown-toc"> (generated via Kramdown)
295+
* <ul class="list--toc">
296+
*/
297+
298+
/* stylelint-disable max-nesting-depth, selector-max-combinators, selector-max-compound-selectors, selector-max-type */
299+
300+
#markdown-toc,
301+
.list--toc {
302+
padding: 0;
303+
list-style: none;
304+
counter-reset: toc-counter;
305+
306+
> li {
307+
counter-increment: toc-counter;
308+
309+
&::before {
310+
content: counter(toc-counter, decimal-leading-zero) "\00A0" "\00A0";
311+
}
312+
313+
> ul {
314+
list-style: none;
315+
counter-reset: toc-sub-counter;
316+
317+
> li {
318+
counter-increment: toc-sub-counter;
319+
320+
&::before {
321+
content: counter(toc-counter, decimal-leading-zero) "\002E" counter(toc-sub-counter) "\00A0" "\00A0";
322+
}
323+
}
324+
325+
ul {
326+
list-style: none;
327+
counter-reset: toc-sub-sub-counter;
328+
329+
li {
330+
counter-increment: toc-sub-sub-counter;
331+
332+
&::before {
333+
content: counter(toc-counter, decimal-leading-zero) "\002E" counter(toc-sub-counter) "\002E" counter(toc-sub-sub-counter) "\00A0" "\00A0";
334+
}
335+
}
336+
}
337+
}
338+
}
339+
}
340+
341+
/**
342+
* Article sequentially-numbered h2/h3/h4 headings to complement TOC above.
343+
*
344+
* Example HTML:
345+
*
346+
* <article class="article-with-toc">
347+
* <ul class="list--toc">
348+
*/
349+
350+
.article--with-toc {
351+
counter-reset: heading-counter;
352+
353+
h2 {
354+
counter-reset: heading-sub-counter;
355+
}
356+
357+
h2::before {
358+
content: counter(heading-counter, decimal-leading-zero) "\00A0" "\00A0";
359+
counter-increment: heading-counter;
360+
}
361+
362+
h3 {
363+
counter-reset: heading-sub-sub-counter;
364+
}
365+
366+
h3::before {
367+
content: counter(heading-counter, decimal-leading-zero) "\002E" counter(heading-sub-counter) "\00A0" "\00A0";
368+
counter-increment: heading-sub-counter;
369+
}
370+
371+
h4::before {
372+
content: counter(heading-counter, decimal-leading-zero) "\002E" counter(heading-sub-counter) "\002E" counter(heading-sub-sub-counter) "\00A0" "\00A0";
373+
counter-increment: heading-sub-sub-counter;
374+
}
375+
}

0 commit comments

Comments
 (0)