#mdbook #table #contents #pagetoc #toc

bin+lib mdbook-pagetoc

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

8 releases

new 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

#324 in Text processing

Download history 7/week @ 2022-11-25 10/week @ 2022-12-02 11/week @ 2022-12-09 8/week @ 2022-12-16 3/week @ 2022-12-23 11/week @ 2022-12-30 17/week @ 2023-01-06 41/week @ 2023-01-13 28/week @ 2023-01-20 18/week @ 2023-01-27 7/week @ 2023-02-03 30/week @ 2023-02-10 19/week @ 2023-02-17 8/week @ 2023-02-24 69/week @ 2023-03-03 55/week @ 2023-03-10

156 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

~8–16MB
~285K SLoC