UNPKG

19.8 kBMarkdownView Raw
1[![view on npm](http://img.shields.io/npm/v/jsdoc-to-markdown.svg)](https://www.npmjs.org/package/jsdoc-to-markdown)
2[![npm module downloads](http://img.shields.io/npm/dt/jsdoc-to-markdown.svg)](https://www.npmjs.org/package/jsdoc-to-markdown)
3[![Build Status](https://travis-ci.org/jsdoc2md/jsdoc-to-markdown.svg?branch=master)](https://travis-ci.org/jsdoc2md/jsdoc-to-markdown)
4[![Dependency Status](https://david-dm.org/jsdoc2md/jsdoc-to-markdown.svg)](https://david-dm.org/jsdoc2md/jsdoc-to-markdown)
5[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)
6
7***This documentation is a work-in-progress***
8
9# jsdoc-to-markdown
10[jsdoc](http://usejsdoc.org) documented source code in, markdown format API documentation out.
11
12## Synopsis
13write documented code:
14```js
15/**
16a quite wonderful function
17@param {object} - privacy gown
18@param {object} - security
19@returns {survival}
20*/
21function protection(cloak, dagger){}
22```
23
24run a command:
25```
26$ jsdoc2md example/src/protection.js
27```
28
29get markdown docs! (in [github-flavored-markdown](https://help.github.com/articles/github-flavored-markdown/) format by default)
30```handlebars
31<a name="protection"></a>
32## protection(cloak, dagger) ⇒ <code>survival</code>
33a quite wonderful function
34
35| Param | Type | Description |
36| ------ | ------------------- | ------------ |
37| cloak | <code>object</code> | privacy gown |
38| dagger | <code>object</code> | security |
39```
40
41this command achieves the same result:
42```sh
43$ jsdoc-parse example/function.js | dmd
44```
45## Features
46
47- Insert API documention into a README, or any arbitrary document.
48- Customisable to a granular level. If the output doesn't suit you, change it.
49- Package your modifications, publish to npm and share with others (e.g. [dmd-bitbucket](https://github.com/jsdoc2md/dmd-bitbucket))
50- Accepts `.js` or `.html` input files (parsing html is experimental - [more](https://github.com/jsdoc2md/jsdoc-parse/))
51- Extends jsdoc with some new tags ([more](https://github.com/jsdoc2md/jsdoc-parse/))
52- Use any arbitrary tag, e.g. `@fulfil`, `@reject`, `@hatredlevel` etc.
53
54## Example output
55Some example output creating using `jsdoc2md`.
56
57### Generated README files
58These projects insert jsdoc2md output into a readme template.
59
60<table>
61 <thead>
62 <tr><th>Project</th><th>Notes</th></tr>
63 </thead>
64 <tbody>
65 <tr>
66 <td><a href="https://github.com/75lb/handbrake-js">handbrake-js</a></td>
67 <td>
68 <p>A module exposing two methods and an inner class. The API docs are inserted into <a href="https://github.com/75lb/handbrake-js/tree/master/jsdoc2md">this README template</a> by this command: <br>
69 <code>$ jsdoc2md --template jsdoc2md/README.hbs lib/*.js</code></p>
70 </td>
71 </tr>
72 <tr>
73 <td><a href="https://github.com/75lb/array-tools">array-tools</a></td>
74 <td>Very simple module exporting a collection of static methods. Demonstrates use of <code>@typicalname</code> (set to <code>a</code>) and the <code>@category</code> tag to group identifiers in the member-list.</td>
75 </tr>
76 <tr>
77 <td><a href="https://github.com/75lb/ansi-escape-sequences">ansi-escape-sequences</a></td>
78 <td>Demonstrates usage of <code>@enum {type}</code> (rendered in table format).</td>
79 </tr>
80 <tr>
81 <td><a href="https://github.com/75lb/file-set">file-set</a></td>
82 <td>Simple module exporting a class.</td>
83 </tr>
84 </tbody>
85</table>
86
87### Tags
88You can see an example of how each [jsdoc tag](http://usejsdoc.org) looks when rendered [here](https://github.com/jsdoc2md/jsdoc-to-markdown/tree/master/example/tags).
89
90### Examples demonstrating various options
91
92To get an idea of the affects the various options have:
93
94- [formatting options](https://github.com/jsdoc2md/jsdoc-to-markdown/tree/master/example/options/dmd%20options)
95 - [example-lang](https://github.com/jsdoc2md/jsdoc-to-markdown/tree/master/example/options/dmd%20options/example-lang)
96 - [module-index-format](https://github.com/jsdoc2md/jsdoc-to-markdown/blob/master/example/options/dmd%20options/module-index-format)
97 - [global-index-format](https://github.com/jsdoc2md/jsdoc-to-markdown/tree/master/example/options/dmd%20options/global-index-format)
98 - [member-index-format](https://github.com/jsdoc2md/jsdoc-to-markdown/blob/master/example/options/dmd%20options/member-index-format)
99 - [param-list-format](https://github.com/jsdoc2md/jsdoc-to-markdown/blob/master/example/options/dmd%20options/param-list-format)
100 - [property-list-format](https://github.com/jsdoc2md/jsdoc-to-markdown/blob/master/example/options/dmd%20options/property-list-format)
101 - [no-gfm](https://github.com/jsdoc2md/jsdoc-to-markdown/tree/master/example/options/dmd%20options/no-gfm)
102 - [separators](https://github.com/jsdoc2md/jsdoc-to-markdown/blob/master/example/options/dmd%20options/separators)
103 - [name format](https://github.com/jsdoc2md/jsdoc-to-markdown/blob/master/example/options/dmd%20options/name-format)
104- [parse options](https://github.com/jsdoc2md/jsdoc-to-markdown/tree/master/example/options/jsdoc-parse%20options)
105 - [html](https://github.com/jsdoc2md/jsdoc-to-markdown/tree/master/example/options/jsdoc-parse%20options/html)
106 - [sort-by](https://github.com/jsdoc2md/jsdoc-to-markdown/tree/master/example/options/jsdoc-parse%20options/sort-by)
107
108### Scripting examples
109If you can't achieve what you need using the command-line tool you can write a custom script.
110
111- [generate one markdown file per class](https://github.com/jsdoc2md/jsdoc-to-markdown/tree/master/example/scripting/output-file-per-class)
112
113### Templating examples
114The default jsdoc2md output might not always suit you. You can supply your using own template using the `template` option. You can see the template used to generate this README [here](https://github.com/jsdoc2md/jsdoc-to-markdown/blob/master/jsdoc2md/README.hbs).
115
116#### Selectors
117- Cherry-pick which documentation appears in the output using [selector helpers](https://github.com/jsdoc2md/jsdoc-to-markdown/tree/master/example/templating/selector%20helpers).
118 - [{{#module}}](https://github.com/jsdoc2md/jsdoc-to-markdown/tree/master/example/templating/selector%20helpers/module)
119 - [{{#class}}](https://github.com/jsdoc2md/jsdoc-to-markdown/tree/master/example/templating/selector%20helpers/class)
120
121### Exemplary APIs
122See [the wiki](https://github.com/jsdoc2md/jsdoc-to-markdown/wiki/Exemplary-APIs) for more great API examples. Feel free to add your own!
123
124
125## Install and use
126First, document your source code using [correct jsdoc syntax](http://usejsdoc.org) then run it through jsdoc-to-markdown using one of the following methods (all tested on Mac OSX, Linux, Windows 8.1 and Windows XP):
127
128### Command-line tool
129To install the `jsdoc2md` command-line tool globally, run:
130```
131$ npm install -g jsdoc-to-markdown
132```
133
134Some typical use cases:
135
136```sh
137$ # dump everything you have into a single file
138$ jsdoc2md "src/**/*.js" > api.md
139```
140
141```sh
142$ # split into separate files
143$ jsdoc2md src/main-module.js > main-module.md
144$ jsdoc2md src/important-class.js > important-class.md
145```
146
147```sh
148$ # embed documentation into a template you made
149$ jsdoc2md "src/**/*.js" --template readme.hbs > README.md
150```
151
152#### Note on globbing
153General rule: if your file expression contains `**` yet recursion is failing, wrap the expression in quotes (e.g. `"lib/**/*.js"`).
154
155If 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.
156
157### Add a "generate docs" task to your project workflow
158#### As an `npm run` task
159This is the most lightweight way to add the task - no additional task-running software required. First:
160```sh
161$ npm install jsdoc-to-markdown --save-dev
162```
163
164Then, in the `"scripts"` section of `package.json`, add a `docs` task. For example:
165```json
166{
167 "scripts": {
168 "docs": "jsdoc2md lib/*.js > api.md"
169 }
170}
171```
172Now, project documentation is generated like so:
173
174```sh
175$ npm run docs
176```
177
178#### As a grunt task
179See [grunt-jsdoc-to-markdown](https://github.com/jsdoc2md/grunt-jsdoc-to-markdown).
180
181#### As a gulp task
182See [gulp-jsdoc-to-markdown](https://github.com/jsdoc2md/gulp-jsdoc-to-markdown).
183
184## Contributing
185Issue reports and patches are encouraged. And the project would benefit from an additional maintainer..
186
187### Composition
188Essentially, jsdoc2d connects the output of [jsdoc-parse](https://github.com/jsdoc2md/jsdoc-parse) to the input of [dmd](https://github.com/jsdoc2md/dmd). dmd uses the [ddata](https://github.com/jsdoc2md/ddata) helper library (also shared by [dhtml](https://github.com/jsdoc2md/dhtml)) and [stream-handlebars](https://github.com/75lb/stream-handlebars) to generate the output.
189
190## API Reference
191**Example**
192```js
193var jsdoc2md = require("jsdoc-to-markdown")
194```
195<a name="exp_module_jsdoc-to-markdown--jsdoc2md"></a>
196### jsdoc2md([options]) ⇒ <code>[TransformStream](https://nodejs.org/api/stream.html#stream_class_stream_transform)</code> ⏏
197Transforms jsdoc into markdown documentation.
198
199**Kind**: Exported function
200**Params**
201- [options] <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code> | <code>[ParseOptions](#module_jsdoc-parse--jsdocParse..ParseOptions)</code> - the options
202
203**Example**
204Two ways to use `jsdoc2md`. Either pass in filepaths (`**` glob matching supported) of javascript source files:
205```js
206> jsdoc2md({ src: "lib/*.js" }).pipe(process.stdout)
207```
208or pipe in source code from another source:
209```js
210> fs.createReadStream("lib/main.js").pipe(jsdoc2md()).pipe(process.stdout)
211```
212
213
214<a name="module_dmd--dmd..DmdOptions"></a>
215### dmd~DmdOptions
216All dmd options and their defaults
217
218**Kind**: inner class of <code>[dmd](#exp_module_dmd--dmd)</code>
219
220* [~DmdOptions](#module_dmd--dmd..DmdOptions)
221 * [.template](#module_dmd--dmd..DmdOptions+template) : <code>string</code>
222 * [.heading-depth](#module_dmd--dmd..DmdOptions+heading-depth) : <code>number</code>
223 * [.example-lang](#module_dmd--dmd..DmdOptions+example-lang) : <code>string</code>
224 * [.plugin](#module_dmd--dmd..DmdOptions+plugin) : <code>array</code>
225 * [.helper](#module_dmd--dmd..DmdOptions+helper) : <code>array</code>
226 * [.partial](#module_dmd--dmd..DmdOptions+partial) : <code>array</code>
227 * [.name-format](#module_dmd--dmd..DmdOptions+name-format) : <code>string</code>
228 * [.no-gfm](#module_dmd--dmd..DmdOptions+no-gfm) : <code>boolean</code>
229 * [.separators](#module_dmd--dmd..DmdOptions+separators) : <code>boolean</code>
230 * [.module-index-format](#module_dmd--dmd..DmdOptions+module-index-format) : <code>string</code>
231 * [.global-index-format](#module_dmd--dmd..DmdOptions+global-index-format) : <code>string</code>
232 * [.param-list-format](#module_dmd--dmd..DmdOptions+param-list-format) : <code>string</code>
233 * [.property-list-format](#module_dmd--dmd..DmdOptions+property-list-format) : <code>string</code>
234 * [.member-index-format](#module_dmd--dmd..DmdOptions+member-index-format) : <code>string</code>
235 * [.group-by](#module_dmd--dmd..DmdOptions+group-by) : <code>array</code>
236
237<a name="module_dmd--dmd..DmdOptions+template"></a>
238#### dmdOptions.template : <code>string</code>
239The template the supplied documentation will be rendered into. Use the default or supply your own template for full control over the output.
240
241**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
242**Default**: <code>&quot;{{&gt;main}}&quot;</code>
243**Example**
244```js
245var fs = require("fs");
246var dmd = require("../");
247
248var template = "The description from my class: {{#class name='MyClass'}}{{description}}{{/class}}";
249
250fs.createReadStream(__dirname + "/my-class.json")
251 .pipe(dmd({ template: template }))
252 .pipe(process.stdout);
253```
254outputs:
255```
256The description from my class: MyClass is full of wonder
257```
258the equivation operation using the command-line tool:
259```
260$ dmd --template template.hbs --src my-class.json
261```
262<a name="module_dmd--dmd..DmdOptions+heading-depth"></a>
263#### dmdOptions.heading-depth : <code>number</code>
264The initial heading depth. For example, with a value of `2` the top-level markdown headings look like `"## The heading"`.
265
266**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
267**Default**: <code>2</code>
268<a name="module_dmd--dmd..DmdOptions+example-lang"></a>
269#### dmdOptions.example-lang : <code>string</code>
270Specifies the default language used in @example blocks (for [syntax-highlighting](https://help.github.com/articles/github-flavored-markdown/#syntax-highlighting) purposes). In gfm mode, each @example is wrapped in a fenced-code block. Example usage: `--example-lang js`. Use the special value `none` for no specific language. While using this option, you can override the supplied language for any @example by specifying the `@lang` subtag, e.g `@example @lang hbs`. Specifying `@example @lang off` will disable code blocks for that example.
271
272**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
273**Default**: <code>&quot;js&quot;</code>
274<a name="module_dmd--dmd..DmdOptions+plugin"></a>
275#### dmdOptions.plugin : <code>array</code>
276Use an installed package containing helper and/or partial overrides
277
278**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
279<a name="module_dmd--dmd..DmdOptions+helper"></a>
280#### dmdOptions.helper : <code>array</code>
281handlebars helper files to override or extend the default set
282
283**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
284<a name="module_dmd--dmd..DmdOptions+partial"></a>
285#### dmdOptions.partial : <code>array</code>
286handlebars partial files to override or extend the default set
287
288**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
289<a name="module_dmd--dmd..DmdOptions+name-format"></a>
290#### dmdOptions.name-format : <code>string</code>
291Format identifier names in the [code](http://daringfireball.net/projects/markdown/syntax#code) style, (i.e. format using backticks or `<code></code>`)
292
293**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
294<a name="module_dmd--dmd..DmdOptions+no-gfm"></a>
295#### dmdOptions.no-gfm : <code>boolean</code>
296By 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.
297
298**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
299<a name="module_dmd--dmd..DmdOptions+separators"></a>
300#### dmdOptions.separators : <code>boolean</code>
301Put `<hr>` breaks between identifiers. Improves readability on bulky docs.
302
303**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
304**Default**: <code>false</code>
305<a name="module_dmd--dmd..DmdOptions+module-index-format"></a>
306#### dmdOptions.module-index-format : <code>string</code>
307none, grouped, table, dl
308
309**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
310**Default**: <code>&quot;dl&quot;</code>
311<a name="module_dmd--dmd..DmdOptions+global-index-format"></a>
312#### dmdOptions.global-index-format : <code>string</code>
313none, grouped, table, dl
314
315**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
316**Default**: <code>&quot;dl&quot;</code>
317<a name="module_dmd--dmd..DmdOptions+param-list-format"></a>
318#### dmdOptions.param-list-format : <code>string</code>
319Two options to render parameter lists: 'list' or 'table' (default). Table format works well in most cases but switch to list if things begin to look crowded / squashed.
320
321**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
322**Default**: <code>&quot;table&quot;</code>
323<a name="module_dmd--dmd..DmdOptions+property-list-format"></a>
324#### dmdOptions.property-list-format : <code>string</code>
325list, table
326
327**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
328**Default**: <code>&quot;table&quot;</code>
329<a name="module_dmd--dmd..DmdOptions+member-index-format"></a>
330#### dmdOptions.member-index-format : <code>string</code>
331grouped, list
332
333**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
334**Default**: <code>&quot;grouped&quot;</code>
335<a name="module_dmd--dmd..DmdOptions+group-by"></a>
336#### dmdOptions.group-by : <code>array</code>
337a list of fields to group member indexes by
338
339**Kind**: instance property of <code>[DmdOptions](#module_dmd--dmd..DmdOptions)</code>
340**Default**: <code>[&quot;scope&quot;,&quot;category&quot;]</code>
341
342<a name="module_jsdoc-parse--jsdocParse..ParseOptions"></a>
343### jsdocParse~ParseOptions
344All options for jsdoc-parse, including defaults
345
346**Kind**: inner class of <code>[jsdocParse](#exp_module_jsdoc-parse--jsdocParse)</code>
347
348* [~ParseOptions](#module_jsdoc-parse--jsdocParse..ParseOptions)
349 * [.src](#module_jsdoc-parse--jsdocParse..ParseOptions+src) : <code>string</code> &#124; <code>Array.&lt;string&gt;</code>
350 * [.private](#module_jsdoc-parse--jsdocParse..ParseOptions+private) : <code>boolean</code>
351 * [.stats](#module_jsdoc-parse--jsdocParse..ParseOptions+stats) : <code>boolean</code>
352 * [.html](#module_jsdoc-parse--jsdocParse..ParseOptions+html) : <code>boolean</code>
353 * [.sort-by](#module_jsdoc-parse--jsdocParse..ParseOptions+sort-by) : <code>array</code>
354
355<a name="module_jsdoc-parse--jsdocParse..ParseOptions+src"></a>
356#### parseOptions.src : <code>string</code> &#124; <code>Array.&lt;string&gt;</code>
357A list of javascript source files (or glob expressions) to parse for documentation. If this option is not set jsdoc-parse will wait for source code on stdin (i.e. `cat *.js | jsdoc-parse <options>`).
358
359**Kind**: instance property of <code>[ParseOptions](#module_jsdoc-parse--jsdocParse..ParseOptions)</code>
360**Example**
361```js
362var parse = require("jsdoc-parse");
363var fs = require("fs");
364
365// either supply one or more file names
366parse({ src: "example.js" }).pipe(process.stdout);
367
368// or pipe in source code
369fs.createReadStream("example.js").parse().pipe(process.stdout);
370```
371<a name="module_jsdoc-parse--jsdocParse..ParseOptions+private"></a>
372#### parseOptions.private : <code>boolean</code>
373Include identifier documentation marked as `@private` in the output
374
375**Kind**: instance property of <code>[ParseOptions](#module_jsdoc-parse--jsdocParse..ParseOptions)</code>
376**Default**: <code>false</code>
377<a name="module_jsdoc-parse--jsdocParse..ParseOptions+stats"></a>
378#### parseOptions.stats : <code>boolean</code>
379Print a few stats about the doclets parsed
380
381**Kind**: instance property of <code>[ParseOptions](#module_jsdoc-parse--jsdocParse..ParseOptions)</code>
382<a name="module_jsdoc-parse--jsdocParse..ParseOptions+html"></a>
383#### parseOptions.html : <code>boolean</code>
384Enable experimental parsing of .html files.
385
386**Kind**: instance property of <code>[ParseOptions](#module_jsdoc-parse--jsdocParse..ParseOptions)</code>
387**Default**: <code>false</code>
388<a name="module_jsdoc-parse--jsdocParse..ParseOptions+sort-by"></a>
389#### parseOptions.sort-by : <code>array</code>
390Sort by one of more fields, e.g. `--sort-by kind category`. Pass the special value `none` to remove the default sort order.
391
392**Kind**: instance property of <code>[ParseOptions](#module_jsdoc-parse--jsdocParse..ParseOptions)</code>
393**Default**: <code>[&quot;scope&quot;,&quot;category&quot;,&quot;kind&quot;,&quot;order&quot;]</code>
394
395* * *
396
397&copy; 2015 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).