markdox.js
2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var markdox = require('markdox')
, ghm = require("github-flavored-markdown")
, fs = require('fs')
, _ = require('lodash');
var getTag = function(tags, tagName) {
return _.find(tags, function (tag) {
return tag.type === tagName
});
};
// TODO multiple @see tags
var options = {
output: 'output.md',
formatter: function (docfile) {
docfile = markdox.defaultFormatter(docfile);
docfile.members = [];
docfile.javadoc.forEach(function(javadoc, index){
// Find constructor tags
docfile.javadoc[index].isConstructor = getTag(javadoc.raw.tags, 'constructor') !== undefined;
// Only show params without a dot in them (dots means attributes of object, so no need to clutter the co)
var params = []
javadoc.paramTags.forEach(function (paramTag) {
if (paramTag.name.indexOf('.') === -1) {
params.push(paramTag.name);
}
});
javadoc.paramStr = params.join(', ');
// Handle linking in comments
if (javadoc.see) {
if (javadoc.see.indexOf('{') === 0){
var see = javadoc.see.split('}')
see[0] = see[0].substring(1)
if (javadoc.see.indexOf('www') !== -1) {
javadoc.seeExternal = true
} else {
javadoc.seeExternal = false
}
javadoc.seeURL = see[0]
if (see[1] !== "") {
javadoc.seeText = see[1]
} else {
javadoc.seeText = see[0]
}
} else {
javadoc.seeURL = false
}
}
// Set a name for properties
if (!javadoc.name) {
var property = getTag(javadoc.raw.tags, 'property')
if (property) {
javadoc.name = property.string
}
}
if (!javadoc.isClass) {
docfile.members.push(javadoc.name)
}
});
return docfile;
},
template: 'output.md.ejs'
};
markdox.process('./lib/sequelize.js', options, function(){
md = fs.readFileSync('output.md').toString();
fs.writeFileSync('out.html', ghm.parse(md));
});