Import jsdoc-to-markdown
masterTo use the library, import the default export from jsdoc-to-markdown.
import jsdoc2md from 'jsdoc-to-markdown'repository·master·Indexed 22 days ago
https://github.com/jsdoc2md/jsdoc-to-markdownA tool and library (version 9.1.3) that generates Markdown API documentation from JSDoc annotated source code. It provides a CLI (`jsdoc2md`) and a JavaScript API featuring methods like `.render()` for generating documentation, `.getTemplateData()` for processed JSON data, and `.getJsdocData()` for raw JSDoc engine output. It supports custom Handlebars templates, GFM configuration, and various output formats for parameters and indexes.
To use the library, import the default export from jsdoc-to-markdown.
import jsdoc2md from 'jsdoc-to-markdown'To generate markdown API documentation, follow these three steps:
jsdoc2md command followed by the path to your source file.Source Code (example.js):
/**
* A quite wonderful function.
* @param {object} - Privacy gown
* @param {object} - Security
* @returns {survival}
*/
function protection (cloak, dagger) {}Command:
$ jsdoc2md example.jsMarkdown Output:
## protection(cloak, dagger) ⇒ <code>survival</code>
A quite wonderful function.
**Kind**: global function
| Param | Type | Description |
| ------ | ------------------- | ------------ |
| cloak | <code>object</code> | Privacy gown |
| dagger | <code>object</code> | Security |Install jsdoc-to-markdown as a development dependency using npm to enable generating markdown documentation from your JSDoc annotated source code.
$ npm install --save-dev jsdoc-to-markdown.getNamepaths(options) method returns all JSDoc namepaths found in the supplied source code. It returns an object.render, getTemplateData, etc.) is stored in the system's temporary directory to speed up repeat invocations. If the input options or source code changes, fresh output is generated. Use .clear() to manually clear the cache if it is failing for some reason.The .getJsdocData([options]) method returns raw data directly from the underlying jsdoc3 engine. It returns a Promise<Array.<object>>.
| Option | Type | Description |
|---|---|---|
no-cache | boolean | If true, disables caching. By default, results are cached to speed up repeat invocations with the same input. |
files | string or Array<string> | One or more filenames to process. Accepts globs (e.g. *.js). |
source | string | A string containing source code to process. |
configure | string | The path to the JSDoc configuration file. |
Note: One of files, source, or configure must be supplied.
.getTemplateData([options]) method returns the template data (the jsdoc-parse output) that is fed into the output template. It returns a Promise<Array.<object>>.The .render([options]) method returns markdown documentation from JSDoc-annotated source code. It returns a Promise<string> which resolves to the rendered documentation.
| Option | Type | Description |
|---|---|---|
data | Array.<object> | Raw template data to use. Useful when you already have template data, obtained from .getTemplateData(). In the options, one of files, source, or configure must be supplied alongside data. |
template | string | The Handlebars template the supplied documentation will be rendered into. Enables full control over the output. |
heading-depth | number | The initial heading depth. For example, with a value of 2 the top-level markdown headings look like ## The heading. |
example-lang | string | Specifies the default language used in @example blocks (for syntax highlighting). In GFM mode, each @example is wrapped in a fenced-code block. Example usage: js. Use none for no specific language. You can override this per-example using the @lang subtag (e.g., @example @lang hbs). Specifying @example @lang off disables code blocks for that example. |
plugin | string or Array<string> | Use an installed package containing helper and/or partial overrides. |
helper | string or Array<string> | Handlebars helper files to override or extend the default set. |
partial | string or Array<string> | Handlebars partial files to override or extend the default set. |
name-format | string | Format identifier names as code (i.e. wrap function/property/class etc names in backticks). |
no-gfm | boolean | If true, disables GitHub-Flavoured Markdown syntax. Useful if your markdown parser does not support GFM correctly. |
separators | boolean | Put <hr> breaks between identifiers to improve readability. |
module-index-format | string | Options: none, grouped, table, dl. |
global-index-format | string | Options: none, grouped, table, dl. |
param-list-format | string | Options: list or table (default). Use list if tables look crowded. |
property-list-format | string | Options: list, table. |
member-index-format | string | Options: grouped, list. |
clever-links | boolean | If true, URL {@link} tags are rendered in plain text. |
monospace-links | boolean | If true, all {@link} tags are rendered in monospace format. This is ignored if clever-links is set. |
EOL | string | Specify posix or win32 to force all line endings in the output. |
const apiDocs = await jsdoc2md.render({ files: 'lib/*.js' })When passing options to jsdoc-to-markdown, you can provide a configuration object that is processed by the JsdocOptions class. This class manages how options are passed to the underlying jsdoc-api.
Key behaviors include:
no-cache option in your configuration object. The class will internally convert this to a cache boolean set to false.template option is explicitly removed from the options object before being passed to jsdoc-api to prevent errors, as jsdoc-api expects the template option to be a specific filename rather than a general template configuration.jsdoc-to-markdown engine, you can provide an options object to control its behavior. One specific option is noCache, which can be passed using the kebab-case key 'no-cache' in the input object. The engine internally maps 'no-cache' to noCache.jsdoc2md caches results in the system's temporary directory to speed up subsequent runs with the same input. If you need to force a fresh generation or if the cache is behaving unexpectedly, use the clear() method to wipe both the jsdoc-api and dmd caches.The getNamepaths() method returns an object containing arrays of JSDoc namepaths, categorized by their kind. This is useful for building navigation or indexes.
Supported kinds include:
module, class, constructor, mixin, member, namespace, constant, function, event, typedef, external.