grunt-doctoc

0.1.1 • Public • Published

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"
    },
    your_target: {
        // doctoc is a multi task, so create one 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 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.

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: {}
  },
});

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)

/grunt-doctoc/

    Package Sidebar

    Install

    npm i grunt-doctoc

    Weekly Downloads

    6

    Version

    0.1.1

    License

    none

    Last publish

    Collaborators

    • nickyout