@@ -5,22 +5,19 @@ var remark = require('remark'),
5
5
_rerouteLinks = require ( './reroute_links' ) ,
6
6
formatType = require ( './format_type' ) ;
7
7
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
+ */
8
15
module . exports = function ( getHref ) {
9
16
var rerouteLinks = _rerouteLinks . bind ( undefined , getHref ) ;
10
17
11
18
/**
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.
24
21
*/
25
22
var formatters = { } ;
26
23
@@ -41,15 +38,25 @@ module.exports = function (getHref) {
41
38
return param . name + ': ' + formatters . type ( param . type ) . replace ( / \n / g, '' ) ;
42
39
}
43
40
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
+ */
44
46
formatters . markdown = function ( ast ) {
45
47
if ( ast ) {
46
48
return remark ( ) . use ( html ) . stringify ( rerouteLinks ( ast ) ) ;
47
49
}
48
50
} ;
49
51
52
+ /**
53
+ * Format a type and convert it to HTML
54
+ *
55
+ * @param {Object } type doctrine-format type
56
+ * @returns {string } HTML
57
+ */
50
58
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, '' ) ;
53
60
} ;
54
61
55
62
/**
0 commit comments