-
Notifications
You must be signed in to change notification settings - Fork 152
Create a plugin
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:
- Write a helper method to return the date in your preferred format
- Override the appropriate partial, inserting a mustache tag (e.g.
{{datestamp}}
) where you would like it to appear. We'll override the main partial.
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
.
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
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
- Home
- How jsdoc2md works
- Additional jsdoc tags supported
- Cherry picking which documentation appears in output
- Showcase ...
- Create ...
- How To ...
- How to use with npm run
- How to use with gulp
- How to create one output file per class
- How to document a AMD module
- How to document a CommonJS module (exports)
- How to document a CommonJS module (module.exports)
- How to document an ES2015 module (multiple named exports)
- How to document an ES2015 module (single default export)
- How to document Promises (using custom tags)
- How to document a ToDo list
- How to document ES2017 features
- How to document TypeScript
- The @typicalname tag
- Linking to external resources
- Param list format options
- Listing namepaths
- Troubleshooting