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.
This commit is contained in:
Paul 2014-11-30 02:00:00 -08:00
parent 352d53802f
commit 2f6c109901
2 changed files with 51 additions and 0 deletions

View file

@ -34,6 +34,7 @@
"./tasks/jsdoc-plugins/filterpixi",
"./tasks/jsdoc-plugins/proptomember",
"./tasks/jsdoc-plugins/sourceproxy",
"./tasks/jsdoc-plugins/shortlinks",
"plugins/markdown"
],
"templates": {

View file

@ -0,0 +1,50 @@
/**
* Transform '{@link #x}' to '{@link longname#x x}' which saves lots of cumersome typing.
*
* This looks in @description, @classdesc and @see tags only.
*
* See https://github.com/jsdoc3/jsdoc/issues/483
*/
var path = require('path');
function expandLinks (text, parent) {
return text.replace(/\{\s*@link\s+([#.])([\w$.]+)\s*\}/g, function (m, mod, name) {
var expanded = "{@link " + parent + mod + name + " " + name + "}";
return expanded;
});
}
exports.handlers = {};
exports.handlers.newDoclet = function (e) {
var doclet = e.doclet;
var parent;
if (doclet.kind === 'class' || doclet.kind === 'interface')
{
parent = doclet.longname;
}
else
{
// member, method, property, etc.
parent = doclet.memberof;
}
['description', 'classdesc'].forEach(function (p) {
if (doclet[p])
{
doclet[p] = expandLinks(doclet[p], parent);
}
});
if (doclet.see && doclet.see.length)
{
for (var i = 0; i < doclet.see.length; i++)
{
doclet.see[i] = expandLinks(doclet.see[i], parent);
}
}
};