This documentation is a work-in-progress
jsdoc documented source code in, markdown format API documentation out.
write documented code:
/**
a quite wonderful function
@param {object} - privacy gown
@param {object} - security
@returns {survival}
*/
function protection(cloak, dagger){}
run a command:
$ jsdoc2md example/src/protection.js
get markdown docs! (in github-flavored-markdown format by default)
this command achieves the same result:
$ jsdoc-parse example/function.js | dmd
- Insert API documention into a README, or any arbitrary document.
- Customisable to a granular level. If the output doesn't suit you, change it.
- Package your modifications, publish to npm and share with others (e.g. dmd-bitbucket)
- Also documents javascript within html input files (experimental - more)
- Extends the jsdoc with some new tags (more)
Some example output creating using jsdoc2md
.
These projects insert jsdoc2md output into a readme template.
Project | Notes |
---|---|
handbrake-js |
A module exposing two methods and an inner class. The API docs are inserted into this README template by this command: |
array-tools | Very simple module exporting a collection of static methods. Demonstrates use of @typicalname (set to a ) and the @category tag to group identifiers in the member-list. |
ansi-escape-sequences | Demonstrates usage of @enum {type} (rendered in table format). |
file-set | Simple module exporting a class. |
You can see an example of how each jsdoc tag looks when rendered here.
To get an idea of the affects the various options have:
If you can't achieve what you need using the command-line tool you can write a custom script.
The default jsdoc2md output might not always suit you. You can supply your using own template using the template
option.
- Cherry-pick which documentation appears in the output using selector helpers.
First, document your source code using correct jsdoc syntax then run it through jsdoc-to-markdown using one of the following methods.
All these methods are tested on Mac OSX, Linux, Windows 8.1 and Windows XP.
To install the jsdoc2md
command-line tool globally, run:
$ npm install -g jsdoc-to-markdown
Some typical use cases:
$ # dump everything you have into a single file
$ jsdoc2md "src/**/*.js" > api.md
$ # split into separate files
$ jsdoc2md src/main-module.js > main-module.md
$ jsdoc2md src/important-class.js > important-class.md
$ # embed documentation into a template you made
$ jsdoc2md "src/**/*.js" --template readme.hbs > README.md
General rule: if your file expression contains **
, yet recursion is failing, wrap the expression in quotes (e.g. "lib/**/*.js"
).
If wrapped in quotes, bash (or your shell) will not attempt file-name expansion on the expression. If you do not use quotes you will require bash version 4+ with globstar enabled for recursion to work.
This is the most lightweight way to add the task - no additional task-running software required.
$ npm install jsdoc-to-markdown --save-dev
Then, in the "scripts"
section of package.json
, add a docs
task. For example:
{
"scripts": {
"docs": "jsdoc2md lib/*.js > api.md"
}
}
Now, project documentation is generated like so:
$ npm run docs
Issue reports and patches are encouraged. And the project would benefit from an additional maintainer..
Essentially, jsdocm2d connects the output of jsdoc-parse to the input of dmd. dmd uses the ddata helper library (also shared by dhtml) and stream-handlebars to generate the output.
Example
var jsdoc2md = require("jsdoc-to-markdown");
jsdoc2md([options]) ⇒ TransformStream
⏏
Transforms jsdoc into markdown documentation.
Kind: Exported function
Params
- [options]
DmdOptions
|ParseOptions
- the options
Example
Two ways to use jsdoc2md
. Either pass in filepaths (**
glob matching supported) of javascript source files:
> jsdoc2md({ src: "lib/*.js" }).pipe(process.stdout);
or pipe in source code from another source:
> fs.createReadStream("lib/main.js").pipe(jsdoc2md()).pipe(process.stdout);
All dmd options and their defaults
Kind: inner class of dmd
- ~DmdOptions
- .template :
string
- .heading-depth :
number
- .example-lang :
string
- .plugin :
array
- .helper :
array
- .partial :
array
- .name-format :
string
- .no-gfm :
boolean
- .separators :
boolean
- .module-index-format :
string
- .global-index-format :
string
- .param-list-format :
string
- .property-list-format :
string
- .member-index-format :
string
- .group-by :
array
- .template :
The template the supplied documentation will be rendered into. Use the default or supply your own template for full control over the output.
Kind: instance property of DmdOptions
Default: "{{>main}}"
Example
var fs = require("fs");
var dmd = require("../");
var template = "The description from my class: {{#class name='MyClass'}}{{description}}{{/class}}";
fs.createReadStream(__dirname + "/my-class.json")
.pipe(dmd({ template: template }))
.pipe(process.stdout);
outputs:
The description from my class: MyClass is full of wonder
the equivation operation using the command-line tool:
$ dmd --template template.hbs --src my-class.json
The initial heading depth. For example, with a value of 2
the top-level markdown headings look like "## The heading"
.
Kind: instance property of DmdOptions
Default: 2
The default language to use when syntax highlighting fenced-code blocks in @example
tags.
Kind: instance property of DmdOptions
Default: "js"
Use an installed package containing helper and/or partial overrides
Kind: instance property of DmdOptions
handlebars helper files to override or extend the default set
Kind: instance property of DmdOptions
handlebars partial files to override or extend the default set
Kind: instance property of DmdOptions
Format identifier names in the code style, (i.e. format using backticks or <code></code>
)
Kind: instance property of DmdOptions
By default, dmd generates github-flavoured markdown. Not all markdown parsers render gfm correctly. If your generated docs look incorrect on sites other than Github (e.g. npmjs.org) try enabling this option to disable Github-specific syntax.
Kind: instance property of DmdOptions
Put <hr>
breaks between identifiers. Improves readability on bulky docs.
Kind: instance property of DmdOptions
Default: false
none, grouped, table, dl
Kind: instance property of DmdOptions
none, grouped, table, dl
Kind: instance property of DmdOptions
list, table
Kind: instance property of DmdOptions
list, table
Kind: instance property of DmdOptions
grouped, list
Kind: instance property of DmdOptions
a list of fields to group member indexes by
Kind: instance property of DmdOptions
All options for jsdoc-parse, including defaults
Kind: inner class of jsdocParse
The source files to parse. If this option is not set jsdoc-parse will wait for input to be streamed in.
Kind: instance property of ParseOptions
Example
var parse = require("jsdoc-parse");
var fs = require("fs");
// either supply one or more file names
parse({ src: "example.js" }).pipe(process.stdout);
// or pipe in source code
fs.createReadStream("example.js").parse().pipe(process.stdout);
Include identifier documentation marked as @private
in the output
Kind: instance property of ParseOptions
Default: false
Print a few stats about the doclets parsed
Kind: instance property of ParseOptions
Enable experimental parsing of .html files.
Kind: instance property of ParseOptions
Default: false
Sort by one of more fields, e.g. --sort-by kind category
.
Kind: instance property of ParseOptions
Default: ["scope","category","kind","order"]
© 2015 Lloyd Brookes <[email protected]>. Documented by jsdoc-to-markdown.