What is jsdoc-to-markdown?
The jsdoc-to-markdown npm package is a tool that generates markdown documentation from JSDoc comments in your JavaScript code. It is useful for creating comprehensive and readable documentation for your projects.
What are jsdoc-to-markdown's main functionalities?
Generate Markdown Documentation
This feature allows you to generate markdown documentation from JSDoc comments in your JavaScript files. The code sample demonstrates how to use jsdoc-to-markdown to read JSDoc comments from JavaScript files in the 'src' directory and output the generated markdown to 'docs/api.md'.
const jsdoc2md = require('jsdoc-to-markdown');
const fs = require('fs');
const inputFiles = 'src/**/*.js';
const outputFile = 'docs/api.md';
jsdoc2md.render({ files: inputFiles })
.then(output => fs.writeFileSync(outputFile, output));
Customizing the Output
This feature allows you to customize the output of the generated markdown documentation using a template. The code sample shows how to use a custom template to format the documentation for a specific module.
const jsdoc2md = require('jsdoc-to-markdown');
const fs = require('fs');
const inputFiles = 'src/**/*.js';
const outputFile = 'docs/api.md';
const template = `{{#module name="myModule"}}{{>docs}}{{/module}}`;
jsdoc2md.render({ files: inputFiles, template: template })
.then(output => fs.writeFileSync(outputFile, output));
Filtering Output
This feature allows you to filter the output of the generated markdown documentation. The code sample demonstrates how to disable GitHub Flavored Markdown (GFM) in the output by setting the 'no-gfm' option to true.
const jsdoc2md = require('jsdoc-to-markdown');
const fs = require('fs');
const inputFiles = 'src/**/*.js';
const outputFile = 'docs/api.md';
jsdoc2md.render({ files: inputFiles, 'no-gfm': true })
.then(output => fs.writeFileSync(outputFile, output));
Other packages similar to jsdoc-to-markdown
documentation
The 'documentation' package is another tool for generating documentation from JSDoc comments. It offers a command-line interface and supports various output formats, including HTML and JSON. Compared to jsdoc-to-markdown, 'documentation' provides more flexibility in terms of output formats but may require more configuration.
jsdoc
The 'jsdoc' package is a popular tool for generating HTML documentation from JSDoc comments. It is highly configurable and supports a wide range of tags and plugins. While 'jsdoc' focuses on generating HTML documentation, jsdoc-to-markdown is specialized in generating markdown documentation, making it more suitable for projects that prefer markdown.
esdoc
The 'esdoc' package is a documentation generator for JavaScript that supports ES6+ syntax. It generates HTML documentation and includes features like coverage reports and test integration. Compared to jsdoc-to-markdown, 'esdoc' is more focused on modern JavaScript syntax and provides additional features like coverage reports.
work in progress, unstable, draft documentation
#jsdoc-to-markdown
Documented source code in, markdown out.. In development, any feedback welcome.
##Install
Ensure node.js is installed first. Linux/Mac users may need to run the following commands with sudo
.
###Globally
$ npm install -g jsdoc-to-markdown
###Bundled with your project
$ npm install jsdoc-to-markdown --save-dev
Then add an docs
build task to your package.json
scripts, e.g.:
{
"name": "my-web-app",
"version": "1.0.0",
"scripts": {
"docs": "jsdoc2md --index lib/*.js"
}
}
This approach abstracts implementation details away, saving collaborators the hassle of installing / learning jsdoc-to-markdown
. Docs are generated like so:
$ npm run docs
##Usage
Document your source code using correct jsdoc syntax, then run it through jsdoc2md
.
$ jsdoc2md <options> <source_files>
-t, --template <string> A custom handlebars template to insert the rendered documentation into,
overriding the default
-p, --preset <string> Use a preset template ('default', 'global' or 'modules')
-j, --json Output the template data only
-h, --help Print usage information
--src <array> The javascript source files. The default option.
--index Include an index for each module and class, linking to members
--skip-heading Skip the module heading, useful if you already have the heading elsewhere
in your template.
##examples
These projects have readme files rendered by jsdoc2md
:
#API Reference
Example
var jsdoc2md = require("jsdoc-to-markdown");
###jsdoc2md.render(options, done)
Params
- options
object
- The render options - done onRender - a callback invoked on completion
###callback: onRender
Called by jsdoc2md.render()
on completion.
Params
- err
object
- An error instance if applicable, else null
- result
string
- the rendered markdown
Scope: inner typedef of jsdoc-to-markdown
Type: function