Skip to content

Commit 76c2c19

Browse files
committed
#27 - clean up hashParts logic | add comments
1 parent a03650f commit 76c2c19

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

build/make_default_helpers.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,26 +270,31 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
270270
hashParts,
271271
description,
272272
linkText,
273-
docObject;
273+
docObject,
274+
href;
274275

275276
name = parts ? parts[1].replace('::', '.prototype.') : content;
276-
hashParts = name.split("#");
277-
278-
if(hashParts.length > 1){
279-
name = hashParts[0];
280-
}
281277

278+
//the name can be something like 'some-name#someId'
279+
//this allows linking to a specific section with the hash syntax (#27)
280+
hashParts = name.split("#");
281+
name = hashParts.shift();
282+
282283
docObject = docMap[name]
283284
if (docObject) {
284285
linkText = parts && parts[2] ? parts[2] : docObject.title || name;
285286
description = docObject.description || name;
286287

287-
return '<a href="' + urlTo(name) + (hashParts.length > 1 ? ("#" + hashParts.slice(1).join("#")) : "") + '" title="' + stripMarkdown(description) + '">' + linkText + '</a>';
288+
//if there is anything in the hashParts, append it to the end of the url
289+
href = urlTo(name) + (hashParts.length >= 1 ? ("#" + hashParts.join("#")) : "");
290+
291+
return '<a href="' + href + '" title="' + stripMarkdown(description) + '">' + linkText + '</a>';
288292
}
289293

290294
if (httpRegExp.test(name)) {
291295
linkText = parts && parts[2] ? parts[2] : name;
292-
return '<a href="' + name + '" title="' + escape(linkText) + '">' + linkText + '</a>';
296+
href = name;
297+
return '<a href="' + href + '" title="' + escape(linkText) + '">' + linkText + '</a>';
293298
}
294299

295300
return match;

build/make_default_helpers_test.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)