Skip to content
Lloyd Brookes edited this page Oct 9, 2016 · 2 revisions

You can customise the generated documentation to taste by overriding or adding partials and/or helpers.

For example, let's say you wanted this datestamp at the bottom of your generated docs:

**documentation generated on Sun, 01 Mar 2015 09:30:17 GMT**

You need to do two things:

  1. Write a helper method to return the date in your preferred format
  2. Override the appropriate partial, inserting a mustache tag (e.g. {{datestamp}}) where you would like it to appear. We'll override the main partial.

Write a new helper

A helper file is just a plain commonJS module. Each method exposed on the module will be available as a helper in your templates. So, our new helper module:

exports.generatedDate = function(){
    return new Date().toUTCString();
}

Read more about helpers in the handlebars documentation.

Write a new main partial

Create a duplicate of the main partial (typically in the project you are documenting) containing your new footer:

{{>main-index~}}
{{>all-docs~}}

**documentation generated on {{generatedDate}}**

the file basename of a partial is significant - if you wish to override main (invoked by {{>main}}) then the filename of your partial must be main.hbs.

Employ

To use the overrides, pass their filenames as options to jsdoc2md:

$ jsdoc2md --partial main.hbs --helper generatedDate.js --files example.js

If you have multiple overrides, the syntax is

$ jsdoc2md --partial override1.hbs override2.hbs --files example.js

Globbing also works:

$ jsdoc2md --partial overrides/*.hbs --files example.js

Create a plugin

If you wish to version-control and/or share your customisations you can create a plugin for distribution via npm. See dmd-plugin-example as an example and boilerplate to get you started.

Once you have your plugin, install it where required as a dev-dependency. Then supply the plugin package name(s) to the --plugin option, for example:

$ cd my-project
$ npm install dmd-plugin-example --save-dev
$ jsdoc2md --plugin dmd-plugin-example --files lib/my-module.js
Clone this wiki locally