generate links correctly when text has extra [bracketed] strings (#470)

This commit is contained in:
Jeff Williams 2013-08-05 21:26:43 -07:00
parent 912f548343
commit 770f5ebb43
2 changed files with 24 additions and 5 deletions

View File

@ -342,13 +342,18 @@ exports.resolveLinks = function(str) {
function extractLeadingText(string, completeTag) {
var tagIndex = string.indexOf(completeTag);
var leadingText = null;
var leadingTextInfo = /\[(.+?)\]/.exec(string);
var leadingTextRegExp = /\[(.+?)\]/g;
var leadingTextInfo = leadingTextRegExp.exec(string);
// did we find leading text, and if so, does it immediately precede the tag?
if ( leadingTextInfo && leadingTextInfo.index &&
(leadingTextInfo.index + leadingTextInfo[0].length === tagIndex) ) {
string = string.replace(leadingTextInfo[0], '');
leadingText = leadingTextInfo[1];
while (leadingTextInfo && leadingTextInfo.length) {
if (leadingTextInfo.index + leadingTextInfo[0].length === tagIndex) {
string = string.replace(leadingTextInfo[0], '');
leadingText = leadingTextInfo[1];
break;
}
leadingTextInfo = leadingTextRegExp.exec(string);
}
return {

View File

@ -1113,6 +1113,20 @@ describe("jsdoc/util/templateHelper", function() {
expect(output).toBe('This is a <a href="path/to/test.html">hello there</a>.');
});
it('should translate [dummy text] and [hello there]{@link test} into an HTML link with the custom content.', function() {
var input = 'This is [dummy text] and [hello there]{@link test}.',
output = helper.resolveLinks(input);
expect(output).toBe('This is [dummy text] and <a href="path/to/test.html">hello there</a>.');
});
it('should translate [dummy text] and [more] and [hello there]{@link test} into an HTML link with the custom content.', function() {
var input = 'This is [dummy text] and [more] and [hello there]{@link test}.',
output = helper.resolveLinks(input);
expect(output).toBe('This is [dummy text] and [more] and <a href="path/to/test.html">hello there</a>.');
});
it('should ignore [hello there].', function() {
var input = 'This is a [hello there].',
output = helper.resolveLinks(input);