mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
generate valid filenames for incorrectly tagged modules (#458)
This commit is contained in:
parent
1a8fac17f0
commit
463dd0a05b
@ -51,8 +51,16 @@ function makeFilenameUnique(filename, str) {
|
||||
return filename;
|
||||
}
|
||||
|
||||
// compute it here just once
|
||||
var nsprefix = /^(event|module|external):/;
|
||||
function cleanseFilename(str) {
|
||||
// allow for namespace prefix
|
||||
return str.replace(/^(event|module|external|package):/, '$1-')
|
||||
// use - instead of ~ to denote 'inner'
|
||||
.replace(/~/g, '-')
|
||||
// use _ instead of # to denote 'instance'
|
||||
.replace(/\#/g, '_')
|
||||
// remove the variation, if any
|
||||
.replace(/\([\s\S]*\)$/, '');
|
||||
}
|
||||
|
||||
var htmlsafe = exports.htmlsafe = function(str) {
|
||||
return str.replace(/</g, '<');
|
||||
@ -71,11 +79,7 @@ var htmlsafe = exports.htmlsafe = function(str) {
|
||||
*/
|
||||
var getUniqueFilename = exports.getUniqueFilename = function(str) {
|
||||
// allow for namespace prefix
|
||||
var basename = str.replace(nsprefix, '$1-')
|
||||
// use - instead of ~ to denote 'inner'
|
||||
.replace(/~/g, '-')
|
||||
// remove the variation, if any
|
||||
.replace(/\([\s\S]*\)$/, '');
|
||||
var basename = cleanseFilename(str);
|
||||
|
||||
// if the basename includes characters that we can't use in a filepath, remove everything up to
|
||||
// and including the last bad character
|
||||
@ -701,10 +705,21 @@ exports.createLink = function(doclet) {
|
||||
var url = '';
|
||||
var longname = doclet.longname;
|
||||
var filename;
|
||||
|
||||
var fakeContainerMatch = /(\S+):/.exec(longname);
|
||||
|
||||
// the doclet gets its own HTML file
|
||||
if ( containers.indexOf(doclet.kind) !== -1 || isModuleFunction(doclet) ) {
|
||||
url = getFilename(longname);
|
||||
}
|
||||
// the doclet's longname suggests that it should get its own HTML file, but doclet.kind says
|
||||
// otherwise. this happens due to mistagged JSDoc (for example, a module that somehow has
|
||||
// doclet.kind set to `member`). use the container's filename plus a fragment.
|
||||
else if ( containers.indexOf(doclet.kind) === -1 && fakeContainerMatch &&
|
||||
containers.indexOf(fakeContainerMatch[1]) !== -1 ) {
|
||||
url = getFilename(longname) + '#' + doclet.name;
|
||||
}
|
||||
// the doclet is within another HTML file
|
||||
else {
|
||||
filename = getFilename(doclet.memberof || exports.globalName);
|
||||
url = filename + '#' + getNamespace(doclet.kind) + doclet.name;
|
||||
|
||||
@ -1375,6 +1375,25 @@ describe("jsdoc/util/templateHelper", function() {
|
||||
|
||||
expect(url).toEqual('module-bar.html');
|
||||
});
|
||||
|
||||
it('should create a url for a doclet with the wrong kind (caused by incorrect JSDoc tags', function() {
|
||||
var moduleDoclet = {
|
||||
kind: 'module',
|
||||
longname: 'module:bar',
|
||||
name: 'module:bar'
|
||||
};
|
||||
var badDoclet = {
|
||||
kind: 'member',
|
||||
longname: 'module:bar',
|
||||
name: 'module:bar'
|
||||
};
|
||||
|
||||
var moduleDocletUrl = helper.createLink(moduleDoclet);
|
||||
var badDocletUrl = helper.createLink(badDoclet);
|
||||
|
||||
expect(moduleDocletUrl).toBe('module-bar.html');
|
||||
expect(badDocletUrl).toBe('module-bar.html#module:bar');
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveAuthorLinks", function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user