mirror of
https://github.com/google/styleguide.git
synced 2026-10-28 08:25:21 +08:00
This is a port of the existing styleguide.js auto TOC logic from the
HTML guides to the newer markdown guides. Rather than generate the
entire TOC in JS, rely on GH's generator to create, and then process
it slightly with minimal CSS+JS.
While GH's builtin markdown renderer automatically creates sidepanel
TOCs, the GH pages export does not. Use the `* TOC {:toc}` form so
the export automatically generates for us. The downside is that it
also shows up in GH's builtin markdown renderer, but it's only one
line at the top, so it shouldn't be onerous.
The CSS logic tweaks which levels are displayed in the generated
TOC: we hide the single top-level, and omit levels deeper than 2.
The JS logic puts the TOC into a <details> HTML element (internally
called a zippy) so that it's collapsed by default.
While the old auto TOC codebase supported "horizontal" and "vertical"
formats, the new one only supports "vertical". Most of our guides do
not care and take the default since that's what internal & external
markdown renderers use, but notably some are using horizontal still:
* C++, HTML/CSS, Java, JS, TS: external, but not internal
* shell: internal & external (via manual TOC)
We'll leave the shell guide alone, but the rest will be switched over
in the future as we regenerate things, and discuss with respective
maintainers.