Skip to content

Commit 2f6c109

Browse files
committed
jsdoc - short/friendly @link plugin
Added support for short `{@link #member}` markup. This makes interlinking much cleaner and shorter; similar short-link support was available in previous versions of jsdoc.
1 parent 352d538 commit 2f6c109

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

tasks/jsdoc-conf.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"./tasks/jsdoc-plugins/filterpixi",
3535
"./tasks/jsdoc-plugins/proptomember",
3636
"./tasks/jsdoc-plugins/sourceproxy",
37+
"./tasks/jsdoc-plugins/shortlinks",
3738
"plugins/markdown"
3839
],
3940
"templates": {

tasks/jsdoc-plugins/shortlinks.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Transform '{@link #x}' to '{@link longname#x x}' which saves lots of cumersome typing.
3+
*
4+
* This looks in @description, @classdesc and @see tags only.
5+
*
6+
* See https://github.com/jsdoc3/jsdoc/issues/483
7+
*/
8+
9+
var path = require('path');
10+
11+
function expandLinks (text, parent) {
12+
13+
return text.replace(/\{\s*@link\s+([#.])([\w$.]+)\s*\}/g, function (m, mod, name) {
14+
var expanded = "{@link " + parent + mod + name + " " + name + "}";
15+
return expanded;
16+
});
17+
18+
}
19+
20+
exports.handlers = {};
21+
exports.handlers.newDoclet = function (e) {
22+
23+
var doclet = e.doclet;
24+
var parent;
25+
if (doclet.kind === 'class' || doclet.kind === 'interface')
26+
{
27+
parent = doclet.longname;
28+
}
29+
else
30+
{
31+
// member, method, property, etc.
32+
parent = doclet.memberof;
33+
}
34+
35+
['description', 'classdesc'].forEach(function (p) {
36+
if (doclet[p])
37+
{
38+
doclet[p] = expandLinks(doclet[p], parent);
39+
}
40+
});
41+
42+
if (doclet.see && doclet.see.length)
43+
{
44+
for (var i = 0; i < doclet.see.length; i++)
45+
{
46+
doclet.see[i] = expandLinks(doclet.see[i], parent);
47+
}
48+
}
49+
50+
};

0 commit comments

Comments
 (0)