diff --git a/lib/jsdoc/util/templateHelper.js b/lib/jsdoc/util/templateHelper.js index adfbd72e..35a47fce 100644 --- a/lib/jsdoc/util/templateHelper.js +++ b/lib/jsdoc/util/templateHelper.js @@ -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 { diff --git a/test/specs/jsdoc/util/templateHelper.js b/test/specs/jsdoc/util/templateHelper.js index d3c87729..ccefe95b 100644 --- a/test/specs/jsdoc/util/templateHelper.js +++ b/test/specs/jsdoc/util/templateHelper.js @@ -1113,6 +1113,20 @@ describe("jsdoc/util/templateHelper", function() { expect(output).toBe('This is a hello there.'); }); + 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 hello there.'); + }); + + 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 hello there.'); + }); + it('should ignore [hello there].', function() { var input = 'This is a [hello there].', output = helper.resolveLinks(input);