Numbered List in a `TOC` Class by Python Markdown

331 views Asked by At

I generate an HTML document using Python Markdown.
The Table of Content is embedded inside a toc class.

I would like the list to be numbers:

1. Subject 001
1.1. Sub Subject 001
1.2. Sub Subject 002
2. Subject 002
2.1. Sub Subject 001
2.2. Sub Subject 002
2.2.1. Sub Sub Subject 001
2.2.2. Sub Sub Subject 002
3. Subject 003
3.1. Sub Subject 001
3.2. Sub Subject 002

So it basically needs to take into accounting the nesting ul and li elements.

I looked at Can ordered list produce result that looks like 1.1, 1.2, 1.3 (instead of just 1, 2, 3, ...) with css?
I came up with:

.toc ul { counter-reset: outItem; list-style: none }
.toc ul > li{ counter-reset: nestedItem }
.toc ul > li:before { content: counters(outItem, ".") ". "; counter-increment: outItem; margin-left: -2em; }

Yet I'm not sure it will support any number of nesting.
Is there a more correct to do so?

1

There are 1 answers

0
Royi On

I have this solution so far:

.toc ul { counter-reset: ulItem; list-style: none }
.toc ul > li:before { content: counters(ulItem, ".") ". "; counter-increment: ulItem; margin-left: -2em; }