Skip to content

Commit f095485

Browse files
committed
mdast-powered Markdown output
1 parent a88ad7f commit f095485

File tree

106 files changed

+2127
-897
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+2127
-897
lines changed

docs/THEME_MARKDOWN.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var sort = require('./lib/sort'),
1010
parse = require('./lib/parsers/javascript'),
1111
polyglot = require('./lib/parsers/polyglot'),
1212
github = require('./lib/github'),
13+
hierarchy = require('./lib/hierarchy'),
1314
inferName = require('./lib/infer/name'),
1415
inferKind = require('./lib/infer/kind'),
1516
inferMembership = require('./lib/infer/membership'),
@@ -20,7 +21,7 @@ var sort = require('./lib/sort'),
2021
* comments, given a root file as a path.
2122
*
2223
* @name documentation
23-
* @param {Array<String>|String} indexes files to process
24+
* @param {Array<string>|string} indexes files to process
2425
* @param {Object} options options
2526
* @param {Array<string>} options.external a string regex / glob match pattern
2627
* that defines what external modules will be whitelisted and included in the
@@ -51,7 +52,7 @@ module.exports = function (indexes, options, callback) {
5152

5253
return inputStream.pipe(concat(function (inputs) {
5354
try {
54-
callback(null, inputs
55+
var flat = inputs
5556
.filter(filterJS)
5657
.reduce(function (memo, file) {
5758
return memo.concat(parse(file));
@@ -65,7 +66,8 @@ module.exports = function (indexes, options, callback) {
6566
return comment;
6667
})
6768
.sort(sort.bind(undefined, options.order))
68-
.filter(filterAccess.bind(undefined, options.private ? [] : undefined)));
69+
.filter(filterAccess.bind(undefined, options.private ? [] : undefined))
70+
callback(null, options.hierarchy !== false ? hierarchy(flat) : flat);
6971
} catch (e) {
7072
callback(e);
7173
}

lib/args.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ var args = require('yargs')
1919
.describe('name', 'project name. by default, inferred from package.json')
2020
.describe('version', 'project version. by default, inferred from package.json')
2121

22-
.boolean('shallow')
23-
.describe('shallow', 'shallow mode turns off dependency resolution, ' +
24-
'only processing the specified files (or the main script specified in package.json)')
25-
.default('shallow', false)
22+
.option('shallow', {
23+
describe: 'shallow mode turns off dependency resolution, ' +
24+
'only processing the specified files (or the main script specified in package.json)',
25+
default: false,
26+
type: 'boolean'
27+
})
2628

2729
.boolean('polyglot')
2830
.describe('polyglot', 'polyglot mode turns off dependency resolution and ' +
@@ -32,10 +34,12 @@ var args = require('yargs')
3234
.describe('g', 'infer links to github in documentation')
3335
.alias('g', 'github')
3436

35-
.describe('o', 'output location. omit for stdout, otherwise is a filename ' +
36-
'for single-file outputs and a directory name for multi-file outputs like html')
37-
.alias('o', 'output')
38-
.default('o', 'stdout')
37+
.option('o', {
38+
describe: 'output location. omit for stdout, otherwise is a filename ' +
39+
'for single-file outputs and a directory name for multi-file outputs like html',
40+
alias: 'output',
41+
default: 'stdout'
42+
})
3943

4044
.describe('c', 'configuration file. an array defining explicit sort order')
4145
.alias('c', 'config')

lib/filter_access.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @name access
99
* @public
10-
* @param {Array<String>} [levels=[private]] excluded access levels.
10+
* @param {Array<string>} [levels=[private]] excluded access levels.
1111
* @param {Object} comment a parsed comment
1212
* @return {boolean} whether the comment should be output
1313
*/

lib/hierarchy.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ function inferHierarchy(comments) {
6262
continue;
6363
}
6464

65+
6566
switch (comment.kind) {
6667
case 'event':
6768
parent.events.push(comment);
6869
break;
6970

7071
default:
7172
if (!comment.scope) {
72-
comment.errors.push('found memberof but no @scope, @static, or @instance tag');
73+
parent.errors.push('found memberof but no @scope, @static, or @instance tag');
7374
continue;
7475
}
7576
parent.members[comment.scope].push(comment);

lib/html_helpers.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
var slugg = require('slugg'),
44
getGlobalExternalLink = require('globals-docs').getDoc,
5-
Remarkable = require('remarkable'),
5+
mdast = require('mdast'),
6+
html = require('mdast-html'),
67
inlineLex = require('jsdoc-inline-lex');
78

8-
var md = new Remarkable();
9-
109
/**
1110
* Make slugg a unary so we can use it in functions
1211
*
@@ -81,7 +80,7 @@ function autolink(paths, text) {
8180
* @name formatType
8281
* @param {Object} type type object in doctrine style
8382
* @param {Array<string>} paths valid namespace paths that can be linked
84-
* @returns {String} string
83+
* @returns {string} string
8584
* @example
8685
* var x = { type: 'NameExpression', name: 'String' };
8786
* // in template
@@ -104,6 +103,8 @@ function formatType(type, paths) {
104103
case 'TypeApplication':
105104
return formatType(type.expression, paths) + '<' +
106105
type.applications.map(recurse).join(', ') + '>';
106+
case 'UndefinedLiteral':
107+
return 'undefined';
107108
}
108109
}
109110

@@ -113,7 +114,7 @@ function formatType(type, paths) {
113114
* parameters
114115
*
115116
* @param {Object} param a param as a type spec
116-
* @returns {String} formatted parameter representation.
117+
* @returns {string} formatted parameter representation.
117118
*/
118119
function formatParameter(param) {
119120
return (param.type && param.type.type === 'OptionalType') ?
@@ -157,16 +158,16 @@ module.exports = function (Handlebars, paths) {
157158
* Markdown-formatted text as proper HTML.
158159
*
159160
* @name formatMarkdown
160-
* @param {String} string
161-
* @returns {String} string
161+
* @param {string} string
162+
* @returns {string} string
162163
* @example
163164
* var x = '## foo';
164165
* // in template
165166
* // {{ md x }}
166167
* // generates <h2>foo</h2>
167168
*/
168169
Handlebars.registerHelper('md', function formatMarkdown(string) {
169-
return new Handlebars.SafeString(md.render(formatInlineTags(string)));
170+
return new Handlebars.SafeString(mdast().use(html).process(formatInlineTags(string)));
170171
});
171172

172173
Handlebars.registerHelper('format_type', function (type) {

lib/lint.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ module.exports = function (comment) {
2828
}
2929

3030
function checkCanonical(type) {
31-
if (!type) {
32-
return;
33-
}
3431
if (type.type === 'NameExpression') {
3532
nameInvariant(type.name);
3633
} else if (type.type === 'UnionType') {

lib/markdown_format_type.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
'use strict';
2-
3-
/**
4-
* Given a type object parsed from JSDoc by Doctrine, generate
5-
* a string representation appropriate for usage in Markdown.
6-
*
7-
* @param {Object} type object with 'type' and optionally 'name'
8-
* members that defines a parameter, property, return type, or other
9-
* type expression
10-
* @return {string} formatted markdown expression of that type.
11-
*/
121
function formatType(type) {
132
if (!type) {
143
return '';
@@ -29,6 +18,8 @@ function formatType(type) {
2918
type.applications.map(function (application) {
3019
return formatType(application);
3120
}).join(', ') + '>';
21+
case 'UndefinedLiteral':
22+
return 'undefined';
3223
}
3324
}
3425

lib/markdown_helpers.js

Lines changed: 0 additions & 87 deletions
This file was deleted.

lib/module_filters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
* Create a filter function for use with module-deps, allowing the specified
1616
* external modules through.
1717
*
18-
* @param {Array<String>} indexes - the list of entry points that will be
18+
* @param {Array<string>} indexes - the list of entry points that will be
1919
* used by module-deps
2020
* @param {Object} options - An options object with `external` being a
2121
* micromatch-compaitible glob. *NOTE:* the glob will be matched relative to

0 commit comments

Comments
 (0)