yamdog

Yamdog API Docs

Welcome to Yamdog v2.1.0 API documentation. This document is generated with Yamdog itself, of course. See docs/generate.js for the recipe.

Two bones

yamdog

The module provides following tools for parsing, decorating, and rendering YAML and Markdown flavoured API documentation from source code comments.

Contents:

Source: lib/index.js

yamdog.decorate(blocks, decorators)

Decorate parsed blocks. The list of decorator functions are applied to each block in the given order. See yamdog.decorators for available built-in decorator functions.

Parameters:

Returns:

Source: decorate/index.js

yamdog.decorators

The default docs output is a bit dull.

With decorators you can style the document in various ways. Below you can find many prebuilt decorators, for example to emphasize matching keywords, insert tables of contents, and order the documentation blocks in alphabetical order. See custom decorators for more info on how decorator functions work and how to create your own decorators.

Contents:

Source: decorators/index.js

yamdog.decorators About Custom Decorators

Each decorator is a function that maps an array of parsed doc blocks to a new array of doc blocks. For example, yamdog.decorators.alphabetical is a function that takes in an array of doc blocks, sorts them by their title, and outputs the blocks in the new order.

The decorator function must be idempotent so that output of running it twice does not differ from running it once. The idempotency also does protect although not prevent decorators interfering with each other. For example a bolding operation should not be done twice - the code must recognize if the text is already bold.

The decorator function must also be immutable so that the input stays unaltered. This prevents a class of problems that would be very hard to debug.

The decorator function is allowed to create, modify, sort, and remove blocks. However, the output must still be a valid array of blocks that can be subjected for further processing.

Source: decorators/index.js

yamdog.decorators.aliases(opts)

Creates a decorator function that appends paragraphs for aliases.

Parameters:

Returns:

Source: aliases.js

yamdog.decorators.alphabetical(opts)

Sort blocks in alphabetical order.

Parameters:

Returns:

Source: alphabetical.js

yamdog.decorators.backTopLinks(opts)

Extends the last block with a link back to the top of the page. In future versions this decorator might be upgraded to add back links also at every 10th block or so.

Parameters:

Returns:

Source: backTopLinks.js

yamdog.decorators.boldKeywords(keywords)

Bolds the given keywords with Markdown **bold** syntax.

Parameters:

Returns:

Source: boldKeywords.js

yamdog.decorators.boldListTitles()

Bolds the first line of all lists with Markdown **bold** syntax.

Returns:

Source: boldListTitles.js

yamdog.decorators.italicSingles()

Emphasizes list item values that contain only a single word. This can be used to make parameter names and property names stand out.

For example the list values “foobar”, “fooBar”, and “foo_bar” would be emphasized but the values “foo bar”, “foo.bar”, and “foo:” would not. See yamdog.decorators.replaceListValues for customization.

Returns:

Source: italicSingles.js

yamdog.decorators.linkKeywords(keywordToUrl)

Create links for keyword occurrences in text. Searches block contents for the given keywords names and replaces each keyword match with a link to the matching URL. Skips preformatted text sections.

Parameters:

Example:

linkKeywords({
  'point2d': 'geometry/point2d.html',
  'point3d': '#geometrypoint3d'
})

Returns:

Source: linkKeywords.js

yamdog.decorators.linkNames()

Easy way to create internal links for block name occurrences in text. Searches block contents for block names and replaces each match with a link to the block heading anchor. Skips preformatted text.

Returns:

Source: linkNames.js

yamdog.decorators.replace(rules)

Replaces the given patterns in text and lists by using String.prototype.replace. Skips preformatted text sections, block names, and block signatures.

Parameters:

Returns:

Source: replace.js

yamdog.decorators.replaceListValues(config)

Replaces all list values according to given rules. Uses applies String.prototype.replace() for each list value.

Parameters:

Returns:

Source: replaceListValues.js

yamdog.decorators.sourceLinks(config)

Creates a decorator function that extends each block with a paragraph that contains a link to the source code.

Parameters:

Returns:

Example:

yamdog.decorators.sourceLinks({
  basePath: path.resolve(__dirname, '..'),
  baseUrl: 'https://github.com/axelpale/yamdog/blob/main/'
}),

Source: sourceLinks.js

yamdog.decorators.toc(config)

Create and insert table of contents for each module that has child blocks. The parent-child relationships are determined by the block names. For example the block “yamdog.decorators” is a child of block “yamdog”, and the block “yamdog.decorators.toc” is a child of “yamdog.decorators”. However, “yamdogbone” would not be a child of “yamdog” because of the missing separator. Allowed separator characters are - .:#/.

Parameters:

Returns:

Source: toc.js

yamdog.generate(config)

Generate the API documentation and save as Markdown document. Internally uses yamdog.parse, yamdog.decorate, and yamdog.render, in this order.

Parameters:

Source: generate.js

yamdog.parse(mod)

Parse doc block objects from code.

Parameters:

Returns:

A parsed doc block object has properties:

If a module file is not found, it will be skipped without error.

Ball Skipping

Aliases: yamdog.stringify

Source: parse/index.js

yamdog.render(blocks, options)

Render API docs in Markdown.

Parameters:

Returns:

Source: render/index.js

yamdog.stringify(mod)

Alias of yamdog.parse

↑ Back To Top