#mdbook #table #toc #contents #pagetoc

bin+lib mdbook-pagetoc

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

8 releases

0.1.7 Mar 12, 2023
0.1.6 Mar 5, 2023
0.1.5 Sep 21, 2022
0.1.4 Jul 15, 2022
0.1.0 Apr 5, 2022

#460 in Text processing

Download history 132/week @ 2023-08-05 117/week @ 2023-08-12 176/week @ 2023-08-19 109/week @ 2023-08-26 137/week @ 2023-09-02 159/week @ 2023-09-09 159/week @ 2023-09-16 245/week @ 2023-09-23 145/week @ 2023-09-30 117/week @ 2023-10-07 75/week @ 2023-10-14 86/week @ 2023-10-21 96/week @ 2023-10-28 113/week @ 2023-11-04 85/week @ 2023-11-11 118/week @ 2023-11-18

429 downloads per month

MPL-2.0 license

17KB
174 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 three files index.hbs, 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"]
    
  • If using a custom index.hbs, the place marker <div class="sidetoc"><nav class="pagetoc"></nav></div> can be inserted manually inside the <main> tag. ie. Replace

    <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/index.hbs
    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

~10–21MB
~290K SLoC