diff options
| -rw-r--r-- | docs/collect.js | 16 | ||||
| -rw-r--r-- | docs/spec/collectSpec.js | 18 |
2 files changed, 28 insertions, 6 deletions
diff --git a/docs/collect.js b/docs/collect.js index a4db4ed1..7fe326b4 100644 --- a/docs/collect.js +++ b/docs/collect.js @@ -163,14 +163,24 @@ function markdownTag(doc, name, value) { replace(/\<\/pre\>/gmi, '</pre></div>'); } +R_LINK = /{@link ([^\s}]+)((\s|\n)+(.+?))?\s*}/m + // 1 123 3 4 42 + function markdown(text) { - var parts = text.split(/(<pre>[\s\S]*?<\/pre>)/); + var parts = text.split(/(<pre>[\s\S]*?<\/pre>)/), + match; + parts.forEach(function(text, i){ if (!text.match(/^<pre>/)) { text = text.replace(/<angular\/>/gm, '<tt><angular/></tt>'); text = new Showdown.converter().makeHtml(text); - text = text.replace(/[^#][^!](angular\.[\$\w\._\-:]+)/gm, '<a href="#!$1">$1</a>'); - text = text.replace(/(`(ng:[\w\._\-]+)`)/gm, '<a href="#!angular.directive.$2">$1</a>'); + + while (match = text.match(R_LINK)) { + text = text.replace(match[0], '<a href="#!' + match[1] + '"><code>' + + (match[4] || match[1]) + + '</code></a>'); + } + parts[i] = text; } }); diff --git a/docs/spec/collectSpec.js b/docs/spec/collectSpec.js index 822e97fb..f6b5a319 100644 --- a/docs/spec/collectSpec.js +++ b/docs/spec/collectSpec.js @@ -13,11 +13,11 @@ describe('collect', function(){ }); it('should not replace anything in <pre>', function(){ - expect(collect.markdown('angular.x\n<pre>\nangular.k\n</pre>\nangular.x')). + expect(collect.markdown('bah x\n<pre>\nangular.k\n</pre>\n asdf x')). toEqual( - '<p><a href="#!angular.x">angular.x</a></p>' + + '<p>bah x</p>' + '<pre>\nangular.k\n</pre>' + - '<p><a href="#!angular.x">angular.x</a></p>'); + '<p>asdf x</p>'); }); }); @@ -196,6 +196,18 @@ describe('collect', function(){ '<div ng:non-bindable><pre class="brush: js; html-script: true;">cba</pre></div>'); }); + + it('should support nested @link annotations with or without description', function() { + TAG.description(doc, 'description', + 'foo {@link angular.foo}\n\n da {@link angular.foo bar foo bar } \n\n' + + 'dad{@link angular.foo}\n\n' + + '{@link angular.directive.ng:foo ng:foo}'); + expect(doc.description). + toBe('<p>foo <a href="#!angular.foo"><code>angular.foo</code></a></p>\n\n' + + '<p>da <a href="#!angular.foo"><code>bar foo bar</code></a> </p>\n\n' + + '<p>dad<a href="#!angular.foo"><code>angular.foo</code></a></p>\n\n' + + '<p><a href="#!angular.directive.ng:foo"><code>ng:foo</code></a></p>'); + }); }); describe('@example', function(){ |
