Skip to main content

Module sections

Module sections 

Source
Expand description

Section numbering and table-of-contents construction over the document model.

number_sections splices a section number into each numbered heading: a leading header-section-number span carrying the number, a following space, and a number key/value attribute. build_toc produces a nested bullet list linking to the document’s headings, which a writer renders into the toc template variable. Both number headings the same way — a counter per level, the result joined from the document’s shallowest heading level — so a heading and its contents entry always carry the same number.

Functions§

build_toc
Build a nested bullet list linking to the document’s headings down to depth, or None when no heading qualifies. With numbered, each entry carries a leading toc-section-number span holding the heading’s number (computed exactly as number_sections does); without it, entries carry only the heading text. With anchors, each entry’s link carries its own toc--prefixed id so it can be linked back to; formats that cannot represent an inline identifier pass false to omit it. Footnotes are dropped and links unwrapped, so an entry never nests an anchor or a note marker.
number_sections
Splice section numbers into the headings of blocks, walking nested sections in document order. A numbered heading gains a leading header-section-number span holding its number, a following space, and a number key/value attribute; an unnumbered heading is left untouched.