Skip to content

jakewrfoster/grunt-doctoc-recursive

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grunt-doctoc

Why does this grunt plugin not exist yet? Perhaps because bitbucket has a [TOC] tag.

Look, this is generated by the plugin:

Table of Contents

Also, the repo of the doctoc script is: https://github.com/thlorenz/doctoc

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-doctoc --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-doctoc');

The "doctoc" task

Overview

In your project's Gruntfile, add a section named doctoc to the data object passed into grunt.initConfig().

grunt.initConfig({
  doctoc: {
    options: {
      bitbucket: false,
      target: "./README.md",
      removeAd: true,
      header: "**Table of Contents**"
      listFiles: null,
      listFilesHeader: "**Nested README Files**"
    },
    your_target: {
        // doctoc is a multi task, so create an object like this
    },
  },
});

Options

options.target

Type: String Default value: './README.md'

Point to a single file. It gets the doctoc treatment. This means, unless already added, the following tags will be prepended to your file:

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

**Table of Contents**
...

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

The toc will be between the tags. After re-running, the toc will be placed between the tags again. Copy the above one if you want.

Oh yeah, bitbucket currently (2014-07-25) shows html entities as strings. Enjoy the html tags.

options.header

  • Type: String (markdown)
  • Default value: "**Table of Contents**"

You can change the header with this. The doctoc script hardcoded prints out this default header, so this is the option to swap that line. Oh yeah, the plugin just does str-replace of the first hit, so I recommend keeping your toc on top of the file, or not using the exact string "**Table of Contents**" in your md.

options.bitbucket

  • Type: Boolean
  • Default value: false

Outputs TOC in bitbucket format. In case you do not want the automatically generated [TOC] one, I guess. I swear, they should at least add that feature to the bitbucket markdown demo page.

options.removeAd

  • Type: Boolean
  • Default value: true

By default, the doctoc script will add a message saying it is generated with DocToc. Screw that. So much free software on github that does without. Set it to false to make it show up again.

options.listFiles

  • Type: String|Array
  • Default Value: null

Append the TOC with a list of links to the files specified here. Supports globbing patterns, documentation can be found here.

options.listFilesHeader

  • Type: String (markdown)
  • Default Value: "**Nested README Files**"
  • Contingency: options.listFiles must be truthy

Displayed as the header of the list of files created with the option listFiles.

Usage Examples

Default Options

Assuming you have a README.md file in your base directory, the default options should do well. Since it's a multitask, you probably want to create an empty object regardless. Oh yeah, the default header is bold text, so... suppose you want that to be another header:

grunt.initConfig({
  doctoc: {
    options: {
      header: "## Table of contents"
    },
    readme: {}
  },
});

Add a file list

Listing all README.md files in all sub directories of the repo root.

grunt.initConfig({
  doctoc: {
    options: {
      target: "./README.md",
      header: "# Table of Contents",
      listFiles: "./**/README.md",
      listFilesHeader: "## All repository READMEs"
    }
  }
});

Listing all README.md files in all sub directories of the repo root while excluding all matches from the directories /node_modules AND /bower_components. Note: when excluding paths (with !), you need to be sure to match everything included by the globbing pattern(s) preceding the exclusion pattern(s).

grunt.initConfig({
  doctoc: {
    options: {
      target: "./README.md",
      header: "# Table of Contents",
      listFiles: [
        "./**/README.md",
        "!./**/node_modules/**/README.md",
        "!./bower_components/**/README.md"
      ],
      listFilesHeader: "## All repository READMEs"
    }
  }
});

Listing all .md files found recursively from within a specified subdirectory only.

grunt.initConfig({
  doctoc: {
    options: {
      target: "./README.md",
      header: "# Table of Contents",
      listFiles: "./docs/**/*.md"
    }
  }
});

Custom Options

If you want to use it on several files, for instance ./doc/README.md and ./wiki/index.md, you can do:

grunt.initConfig({
  doctoc: {
    options: {
      header: "## Table of contents"
    },
    doc: {
      options: {
        target: "./doc/README.md"
      }
    },
    wiki: {
      options: {
        target: "./wiki/index.md"
      }
    }
  },
});

Contributing

Sure, add/fix whatever you want.

Release History

(Nothing yet)

About

Why is there no grunt plugin for doctoc yet?

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%