├── .gitignore ├── LICENSE ├── README.md ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Hongzheng Wang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #gitbook-plugin-toc 2 | This plugin will add table of content to the page and provide navigation function inside a page. 3 | 4 | Add `` to the markdown files. When you build the book, it will insert a table of content where you insert `` 5 | 6 | 7 | `book.json` Config: 8 | 9 | 10 | ``` 11 | { 12 | "plugins": ["toc"], 13 | "pluginsConfig": { 14 | "toc": { 15 | "addClass": true, 16 | "className": "toc" 17 | } 18 | } 19 | } 20 | ``` 21 | 22 | You can add this config to add a HTML ClassName to the TOC `ul` element 23 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var toc = require('markdown-toc'); 2 | 3 | module.exports = { 4 | book: {}, 5 | hooks: { 6 | "page:before": function (page) { 7 | page.content = toc.insert(page.content, { 8 | slugify: function (str) { 9 | return encodeURI(str.toLowerCase()).replace(/%20/g, '-'); 10 | } 11 | }); 12 | if (this.options.pluginsConfig.toc.addClass) { 13 | var className = this.options.pluginsConfig.toc.className || 'toc'; 14 | page.content = page.content + '\n\n\n'; 15 | } 16 | return page; 17 | } 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gitbook-plugin-toc", 3 | "description": "Add table of content to page", 4 | "main": "index.js", 5 | "version": "0.0.2", 6 | "engines": { 7 | "gitbook": "*" 8 | }, 9 | "homepage": "https://github.com/whzhyh/gitbook-plugin-toc", 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/whzhyh/gitbook-plugin-toc.git" 13 | }, 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/whzhyh/gitbook-plugin-toc/issues" 17 | }, 18 | "dependencies": { 19 | "markdown-toc": "^0.11.0" 20 | }, 21 | "keywords": [ 22 | "gitbook", 23 | "plugin" 24 | ], 25 | "author": "Hongzheng Wang " 26 | } 27 | --------------------------------------------------------------------------------