#mdbook #content #table #page-table #toc #pagetoc

bin+lib mdbook-pagetoc

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

11 releases

0.2.0 Apr 29, 2024
0.1.9 Jan 23, 2024
0.1.8 Dec 30, 2023
0.1.7 Mar 12, 2023
0.1.0 Apr 5, 2022

#473 in Text processing

Download history 101/week @ 2024-06-30 90/week @ 2024-07-07 33/week @ 2024-07-14 16/week @ 2024-07-21 115/week @ 2024-07-28 27/week @ 2024-08-04 27/week @ 2024-08-11 39/week @ 2024-08-18 153/week @ 2024-08-25 99/week @ 2024-09-01 104/week @ 2024-09-08 96/week @ 2024-09-15 134/week @ 2024-09-22 145/week @ 2024-09-29 110/week @ 2024-10-06 103/week @ 2024-10-13

496 downloads per month

MPL-2.0 license

17KB
185 lines

mdbook-pagetoc

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

Show me

Sample image from mdBook-pagetoc:

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.

Configuration:

  • Add to book.toml config:

    [preprocessor.pagetoc]
    [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;
    }
    

Acknowledgments

Alternative

Dependencies

~11–22MB
~327K SLoC