Changes to allow target and text in {@link target text} to be separated by newlines and for text to contain newlines.

This commit is contained in:
Louis-Dominique Dubeau 2013-06-21 10:03:26 -04:00
parent 2090b8d2fe
commit 32d00c20ca
3 changed files with 20 additions and 2 deletions

View File

@ -61,7 +61,7 @@ exports.replaceInlineTags = function(string, replacers) {
string = string || '';
Object.keys(replacers).forEach(function(replacer) {
var tagRegExp = new RegExp('\\{@' + replacer + '\\s+(.+?)\\}', 'gi');
var tagRegExp = new RegExp('\\{@' + replacer + '\\s+((?:.|\n)+?)\\}', 'gi');
var matches;
// call the replacer once for each match
while ( (matches = tagRegExp.exec(string)) !== null ) {

View File

@ -256,11 +256,13 @@ function splitLinkText(text) {
// if a pipe is not present, we split on the first space
splitIndex = text.indexOf('|');
if (splitIndex === -1) {
splitIndex = text.indexOf(' ');
splitIndex = text.search(/\s/);
}
if (splitIndex !== -1) {
linkText = text.substr(splitIndex + 1);
// Normalize subsequent newlines to a single space.
linkText = linkText.replace(/\n+/, ' ');
target = text.substr(0, splitIndex);
}

View File

@ -1170,6 +1170,22 @@ describe("jsdoc/util/templateHelper", function() {
expect(output).toBe('This is a <a href="path/to/test.html">test</a>.');
});
it('should allow linebreaks to separate url from link text', function() {
var input = 'This is a {@link\ntest\ntest}.',
output = helper.resolveLinks(input);
expect(output).toBe('This is a <a href="path/to/test.html">test</a>.');
});
it('should normalize additional newlines to spaces', function() {
var input = 'This is a {@link\ntest\ntest\n\ntest}.',
output = helper.resolveLinks(input);
expect(output).toBe('This is a <a href="path/to/test.html">test test</a>.');
});
it('should allow tabs between link tag and content', function() {
var input = 'This is a {@link\ttest}.',
output = helper.resolveLinks(input);