Docma (Dust) Filters

Docma uses Dust.js as the template engine; which is also globally accessible within the template (web app).

As well as the Dust.js built-in filters, Docma includes pre-defined filters for ease of use.

Built-in Filters by Dust.js

Input Filter Description
String h HTML encode.
String s Turn off automatic HTML encoding
String j Javascript string encode
String u encodeURI
String uc encodeURIComponent
Object js JSON.stringify
String jp JSON.parse

Built-in Filters by Docma

Input Filter Description
String $pt Converts ticks to HTML code tags.
Also available as docma.utils.parseTicks(string)
String $pnl Converts new lines to HTML paragraphs.
Also available as docma.utils.parseNewLines(string)
String $pl Converts JSDoc @link directives to HTML anchor tags.
Also available as docma.utils.parseLinks(string)
String $tl Removes leading spaces and dashes.
Also available as docma.utils.trimLeft(string)
String $p Applies $tl|$pnl|$pt|$pl filters combined.
Also available as docma.utils.parse(string)
String $nt Normalizes the number of spaces/tabs to multiples of 2 spaces, in the beginning of each line.
Also available as docma.utils.normalizeTabs(string)
$desc Parses and returns the (class description or) description of the documentation symbol.
$def Returns the default value of the parameter or symbol.
$val Returns the value of the symbol (if any).
$id Returns a readable id for the symbol. Useful for anchor bookmarks.
e.g. <a href="#{.|$id}">{longname}</a>

Creating Custom Filters

You can also create your own custom filters using either the dust object or shorthand methods defined by Docma Web.

// filter that adds parenthesis if the symbol is a method.
docma.addFilter('$parenths', function (symbol) {
    return docma.utils.isMethod(symbol)
        ? symbol.longname + '()'
        : symbol.longname;

Example Usage in Partials