Skip to content

Commit a03650f

Browse files
committed
#27 - allow linking to a section with hash syntax
1 parent 5209c66 commit a03650f

File tree

3 files changed

+85
-2
lines changed

3 files changed

+85
-2
lines changed

build/build_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
require("./make_default_helpers_test");
22

33
var getRenderer = require('./get_renderer'),
44
getPartials = require('./get_partials'),

build/make_default_helpers.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,24 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
267267
var replacer = function (match, content) {
268268
var parts = content.match(linkRegExp),
269269
name,
270+
hashParts,
270271
description,
271272
linkText,
272273
docObject;
273274

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

276282
docObject = docMap[name]
277283
if (docObject) {
278284
linkText = parts && parts[2] ? parts[2] : docObject.title || name;
279285
description = docObject.description || name;
280286

281-
return '<a href="' + urlTo(name) + '" title="' + stripMarkdown(description) + '">' + linkText + '</a>';
287+
return '<a href="' + urlTo(name) + (hashParts.length > 1 ? ("#" + hashParts.slice(1).join("#")) : "") + '" title="' + stripMarkdown(description) + '">' + linkText + '</a>';
282288
}
283289

284290
if (httpRegExp.test(name)) {

build/make_default_helpers_test.js

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)