picosh / pico

hacker labs - open source and managed web services leveraging SSH
https://pico.sh
MIT License
741 stars 25 forks source link

Toc #107

Closed CosmicToast closed 3 months ago

CosmicToast commented 3 months ago

This adds a table of contents generator. It's based on #106 (and includes it in-line).

Since the toc generator is purely ast-based, we simply insert it into our own ast transformation pipeline. This bypasses the cost of re-parsing, which is typically O(n^4), and makes it near-free when disabled.

This also adds some configurability on the user-end. The toc frontmatter can have the values "true", "false", or an integer. True is equivalent to 0, false to -1, and values >0 are translated to a maxheading of the value +1 (to account for titles being level 2).