Skip to content

Commit 77a53be

Browse files
committed
Document formatters
1 parent ccd96f9 commit 77a53be

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

lib/output/util/formatters.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@ var remark = require('remark'),
55
_rerouteLinks = require('./reroute_links'),
66
formatType = require('./format_type');
77

8+
/**
9+
* Create a formatter group, given a linker method that resolves
10+
* namespaces to URLs
11+
*
12+
* @param {Function} getHref linker method
13+
* @returns {formatters} formatter object
14+
*/
815
module.exports = function (getHref) {
916
var rerouteLinks = _rerouteLinks.bind(undefined, getHref);
1017

1118
/**
12-
* This helper is exposed in templates as `md` and is useful for showing
13-
* Markdown-formatted text as proper HTML.
14-
*
15-
* @param {Function} getHref a method that transforms namepaths to urls
16-
* @param {Object} ast - mdast tree
17-
* @returns {string} HTML
18-
* @private
19-
* @example
20-
* var x = remark.parse('## foo');
21-
* // in template
22-
* // {{ md x }}
23-
* // generates <h2>foo</h2>
19+
* Formatters are helpers for templates: they handle tricky logic
20+
* parts like outputting types and parameters.
2421
*/
2522
var formatters = {};
2623

@@ -41,15 +38,25 @@ module.exports = function (getHref) {
4138
return param.name + ': ' + formatters.type(param.type).replace(/\n/g, '');
4239
}
4340

41+
/**
42+
* Convert a remark AST to a string of HTML, rerouting links as necessary
43+
* @param {Object} ast remark-compatible AST
44+
* @returns {string} HTML
45+
*/
4446
formatters.markdown = function (ast) {
4547
if (ast) {
4648
return remark().use(html).stringify(rerouteLinks(ast));
4749
}
4850
};
4951

52+
/**
53+
* Format a type and convert it to HTML
54+
*
55+
* @param {Object} type doctrine-format type
56+
* @returns {string} HTML
57+
*/
5058
formatters.type = function (type) {
51-
return formatters.markdown(u('root', formatType(getHref, type)))
52-
.replace(/\n/g, '');
59+
return formatters.markdown(u('root', formatType(getHref, type))).replace(/\n/g, '');
5360
};
5461

5562
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy