From 016ee85362f59ae790877860ca85263d0f600562 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Sat, 23 Mar 2013 09:39:19 -0700 Subject: [PATCH] might as well turn the URL into a link (#371) --- lib/jsdoc/util/templateHelper.js | 11 +++++++---- test/specs/jsdoc/util/templateHelper.js | 13 +++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/jsdoc/util/templateHelper.js b/lib/jsdoc/util/templateHelper.js index 4b914356..19097109 100644 --- a/lib/jsdoc/util/templateHelper.js +++ b/lib/jsdoc/util/templateHelper.js @@ -144,13 +144,16 @@ var linkto = exports.linkto = function(longname, linktext, cssClass) { // handle cases like: // @see // @see http://example.org - var stripped = text.replace(/^<|>$/g, ''); + var stripped = longname && longname.replace(/^<|>$/g, ''); if ( hasUrlPrefix(stripped) ) { - return stripped; + url = stripped; + // remove the angle brackets from the link text if necessary + if (longname === text) { + text = stripped; + } } - // handle complex type expressions that may require multiple links - if (longname && longname.search(/[<{(]/) !== -1) { + else if (longname && longname.search(/[<{(]/) !== -1) { parsedType = parseType(longname); return catharsis.stringify(parsedType, { cssClass: cssClass, diff --git a/test/specs/jsdoc/util/templateHelper.js b/test/specs/jsdoc/util/templateHelper.js index 7b313ee1..ed074b68 100644 --- a/test/specs/jsdoc/util/templateHelper.js +++ b/test/specs/jsdoc/util/templateHelper.js @@ -289,14 +289,19 @@ describe("jsdoc/util/templateHelper", function() { 'LinktoFakeClass)>'); }); - it('returns the URL when a URL is specified', function() { + it('returns a link when a URL is specified', function() { var link = helper.linkto('http://example.com'); - expect(link).toBe('http://example.com'); + expect(link).toBe('http://example.com'); }); - it('returns the URL if a URL wrapped in angle brackets is specified', function() { + it('returns a link if a URL wrapped in angle brackets is specified', function() { var link = helper.linkto(''); - expect(link).toBe('http://example.com'); + expect(link).toBe('http://example.com'); + }); + + it('returns a link with link text if a URL and link text are specified', function() { + var link = helper.linkto('http://example.com', 'text'); + expect(link).toBe('text'); }); });