might as well turn the URL into a link (#371)

This commit is contained in:
Jeff Williams 2013-03-23 09:39:19 -07:00
parent 306046ce0e
commit 016ee85362
2 changed files with 16 additions and 8 deletions

View File

@ -144,13 +144,16 @@ var linkto = exports.linkto = function(longname, linktext, cssClass) {
// handle cases like:
// @see <http://example.org>
// @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,

View File

@ -289,14 +289,19 @@ describe("jsdoc/util/templateHelper", function() {
'<a href="fakeclass.html">LinktoFakeClass</a>)>');
});
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('<a href="http://example.com">http://example.com</a>');
});
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('<http://example.com>');
expect(link).toBe('http://example.com');
expect(link).toBe('<a href="http://example.com">http://example.com</a>');
});
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('<a href="http://example.com">text</a>');
});
});