-
Notifications
You must be signed in to change notification settings - Fork 151
Cherry picking which documentation appears in output
1. If you're writing a custom output template (for use with --template
) it's possible to pick and choose exactly which class/function/module/etc identifiers appear in the output. To achieve this there are several block helpers you can use, the "selector helpers":
-
{{#globals}}
- Iterates over each identifier in global scope -
{{#modules}}
- Iterates over each module -
{{#classes}}
- Iterates over each class -
{{#functions}}
- Iterates over each function -
{{#identifiers}}
- Iterates over all identifiers -
{{#orphans}}
- Iterates over all identifiers with no parent (modules and globals) -
{{#module}}
- Picks a single module -
{{#class}}
- Picks a single class -
{{#function}}
- Picks a single function -
{{#namespace}}
- Picks a single namespace -
{{#enum}}
- Picks a single enum -
{{#identifier}}
- Picks a single identifier
2. For example, create this source code (in a file named 'example.js'):
/**
* Addition
*/
function add () {}
/**
* Subtraction
*/
function subtract () {}
/**
* Multiplication
*/
function multiply () {}
3. If you inspect the template data (using jsdoc2md --json example.js
) you will see this:
[
{
"id": "add",
"longname": "add",
"name": "add",
"kind": "function",
"scope": "global",
"description": "Addition",
"params": [],
"meta": {
"lineno": 4,
"filename": "0-src.js",
"path": "/Users/lloydb/Documents/jsdoc2md/testbed/build/jsdoc2md/templating/selector-helpers/functions"
},
"order": 0
},
{
"id": "subtract",
"longname": "subtract",
"name": "subtract",
"kind": "function",
"scope": "global",
"description": "Subtraction",
"params": [],
"meta": {
"lineno": 9,
"filename": "0-src.js",
"path": "/Users/lloydb/Documents/jsdoc2md/testbed/build/jsdoc2md/templating/selector-helpers/functions"
},
"order": 1
},
{
"id": "multiply",
"longname": "multiply",
"name": "multiply",
"kind": "function",
"scope": "global",
"description": "Multiplication",
"params": [],
"meta": {
"lineno": 14,
"filename": "0-src.js",
"path": "/Users/lloydb/Documents/jsdoc2md/testbed/build/jsdoc2md/templating/selector-helpers/functions"
},
"order": 2
}
]
4. You could write a custom template (e.g. 'template.hbs') which uses selector helpers to list the names and descriptions of each function:
{{#functions}}
* {{name}} - {{description}}
{{/functions}}
5. Now, running the command jsdoc2md --template template.hbs --files example.js
would output:
* add - Addition
* subtract - Subtraction
* multiply - Multiplication
6. You can filter which identifiers are cherry-picked by adding attributes to the helper, which act as queries. For example, this helper will output docs for the jsdoc-to-markdown
module only:
{{#module name="jsdoc-to-markdown"}}
{{>docs}}
{{/module}}
- 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