A long page with many headings can benefit from a table of contents.
headings.md
# Section 1
Introduction for section 1…
## Section 1.1
Text of section 1.1…
## Section 1.2
Text of section 1.2…
# Section 2
## Section 2.1
Introduction for section 2.1…
### Section 2.1.1
Text of section 2.1.1…
Origami’s markdown outline function regroups markdown content into an object reflecting the document’s heading structure.
$ ori Origami.mdOutline headings.md
Section 1:
_text: Introduction for section 1…
Section 1.1: Text of section 1.1…
Section 1.2: Text of section 1.2…
Section 2:
Section 2.1:
_text: Introduction for section 2.1…
Section 2.1.1: Text of section 2.1.1…
$
Use a template to turn that structure into links!
headings.ori
// Given an outline, return navigation links. If a given heading has
// subheadings, this template calls itself recursively.
(outline) => Tree.indent`
<ul>
${ Tree.map(outline, (content, heading) =>
heading === "_text"
? ""
: Tree.indent`
<li>
<a href="#${ Origami.slug(heading) }">${ heading }</a>
</li>
${ Tree.isMaplike(content) ? headings.ori(content) : "" }
`
) }
</ul>
`
This lets you give a page a table of contents with links to all the headings!
http://localhost:5000/rules.html
Section 1
Introduction for section 1…
Section 1.1
Text of section 1.1…
Section 1.2
Text of section 1.2…
Section 2
Section 2.1
Introduction for section 2.1…
Section 2.1.1
Text of section 2.1.1…
The same function can also break up a long document into multiple pages.
Read more: Origami.mdOutline builtin function