mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
generate links correctly when text has extra [bracketed] strings (#470)
This commit is contained in:
parent
912f548343
commit
770f5ebb43
@ -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 {
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user