#content #mdbook #toc #pagetoc

bin+lib mdbook-pagetoc

A mdbook plugin that provides a table of contents for each page

14 releases

Uses new Rust 2024

0.3.0 Nov 27, 2025
0.2.0 Apr 29, 2024
0.1.9 Jan 23, 2024
0.1.8 Dec 30, 2023
0.1.4 Jul 15, 2022

#1140 in Text processing

Download history 67/week @ 2026-01-18 72/week @ 2026-01-25 61/week @ 2026-02-01 110/week @ 2026-02-08 99/week @ 2026-02-15 145/week @ 2026-02-22 197/week @ 2026-03-01 66/week @ 2026-03-08 85/week @ 2026-03-15 81/week @ 2026-03-22 269/week @ 2026-03-29 147/week @ 2026-04-05 153/week @ 2026-04-12 89/week @ 2026-04-19 142/week @ 2026-04-26 56/week @ 2026-05-03

446 downloads per month

MPL-2.0 license

160KB
192 lines

mdbook-pagetoc

A mdbook plugin that provides a table of contents for each page. Uses css/js from mdBook-pagetoc.

Show me

mdbook-pagetoc screenshot

Notes:

  • Only supports the html renderer.

  • On the first run of mdbook build, it creates two files pagetoc.css and pagetoc.js.

  • You can customize any of them after the first run.

  • mdbook 0.5 now ships with built-in support for showing the page table of contents in the sidebar, see PR 2822

Configuration:

  • Add to book.toml config:

    [preprocessor.pagetoc]
    scroll_offset = 10  # pixels added to scroll position for active header detection (default: 10)
    
    [output.html]
    additional-css = ["theme/pagetoc.css"]
    additional-js  = ["theme/pagetoc.js"]
    
  • The place marker <div class="sidetoc"><nav class="pagetoc"></nav></div> will be inserted inside the <main> tag. ie. This replaces

    <main>
      {{{content}}}
    </main>
    

    with:

    <main><div class="sidetoc"><nav class="pagetoc"></nav></div>
      {{{content}}}
    </main>
    
  • If not customizing, you may want to add entries as appropriate to .gitignore to keep your repo clean:

    theme/pagetoc.css
    theme/pagetoc.js
    
  • Customization: To autohide when only single header, add this snippet to pagetoc.css:

    a[class^="pagetoc-H"]:only-child {
      display: none;
    }
    
  • Customization: To hide a header from the table of content:

    ## Hidden from TOC {.toc-ignore}
    

Acknowledgments

Alternative

Dependencies

~9–14MB
~176K SLoC