Skip to content

Commit 935e10a

Browse files
committed
fix: Trim whitespace when parsing links
Closes #1302
1 parent 0708fb8 commit 935e10a

File tree

7 files changed

+77
-5
lines changed

7 files changed

+77
-5
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ yarn-error.log
1515

1616
typedoc*.tgz
1717
tmp
18+
19+
src/test/renderer/specs/assets/*

examples/basic/src/classes.ts

+26
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
/**
22
* This is a simple interface.
3+
*
4+
* Links - these should all point to the name property:
5+
* - {@link name}
6+
* - {@link NameInterface.name}
7+
* - {@link "classes".NameInterface.name}
8+
* - {@link name Text} <-- This one goes away eventually
9+
* - {@link name|Text}
10+
* - {@link name | Text}
11+
* - {@link NameInterface.name | Text}
312
*/
413
export interface NameInterface {
514
/**
615
* This is a interface member of INameInterface.
716
*
817
* It should be inherited by all subinterfaces.
18+
*
19+
* Links - these should all point to this property:
20+
* - {@link name}
21+
* - {@link NameInterface.name}
22+
* - {@link "classes".NameInterface.name}
23+
* - {@link name Text} <-- This one goes away eventually
24+
* - {@link name|Text}
25+
* - {@link name | Text}
26+
* - {@link NameInterface.name | Text}
27+
*
28+
* Links - these should point to the containing interface
29+
* - {@link NameInterface}
30+
* - {@link "classes".NameInterface}
931
*/
1032
name: string;
1133

@@ -43,6 +65,10 @@ export interface PrintNameInterface extends NameInterface, PrintInterface {
4365
* This is a simple base class.
4466
*
4567
* [[include:class-example.md]]
68+
*
69+
* Links:
70+
* - {@link name | The name property on this class}
71+
* - {@link NameInterface.name | The name property we inherit from the interface}
4672
*/
4773
export abstract class BaseClass implements NameInterface {
4874
/**

scripts/rebuild_specs.js

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ async function rebuildRendererTest() {
8484
app.options.setValue('excludeExternals', false);
8585
app.generateDocs(app.expandInputFiles([src]), out)
8686
app.options.setValue('excludeExternals', true);
87-
await fs.remove(path.join(out, 'assets'))
8887

8988
/**
9089
* Avoiding sync methods here is... difficult.

src/lib/output/plugins/MarkedLinksPlugin.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class MarkedLinksPlugin extends ContextAwareRendererComponent {
1616
private brackets: RegExp = /\[\[([^\]]+)\]\]/g;
1717

1818
/**
19-
* Regular expression for detecting inline tags like {@link ...}.
19+
* Regular expression for detecting inline tags like {&link ...}.
2020
*/
2121
private inlineTag: RegExp = /(?:\[(.+?)\])?\{@(link|linkcode|linkplain)\s+((?:.|\n)+?)\}/gi;
2222

@@ -56,7 +56,7 @@ export class MarkedLinksPlugin extends ContextAwareRendererComponent {
5656
}
5757

5858
/**
59-
* Find symbol {@link ...} strings in text and turn into html links
59+
* Find symbol {&link ...} strings in text and turn into html links
6060
*
6161
* @param text The string in which to replace the inline tags.
6262
* @return The updated string.
@@ -152,8 +152,8 @@ export class MarkedLinksPlugin extends ContextAwareRendererComponent {
152152

153153
if (splitIndex !== -1) {
154154
return {
155-
caption: text.substr(splitIndex + 1).replace(/\n+/, ' '),
156-
target: text.substr(0, splitIndex)
155+
caption: text.substr(splitIndex + 1).replace(/\n+/, ' ').trim(),
156+
target: text.substr(0, splitIndex).trim()
157157
};
158158
} else {
159159
return {

src/test/renderer/specs/classes/_classes_.baseclass.html

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ <h1>Class BaseClass</h1>
7575
<p>This is a simple base class.</p>
7676
</div>
7777
<p>[[include:class-example.md]]</p>
78+
<p>Links:</p>
79+
<ul>
80+
<li><a href="_classes_.baseclass.html#name">The name property on this class</a></li>
81+
<li><a href="../interfaces/_classes_.nameinterface.html#name">The name property we inherit from the interface</a></li>
82+
</ul>
7883
</div>
7984
</section>
8085
<section class="tsd-panel tsd-hierarchy">

src/test/renderer/specs/interfaces/_classes_.nameinterface.html

+25
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ <h1>Interface NameInterface</h1>
7474
<div class="lead">
7575
<p>This is a simple interface.</p>
7676
</div>
77+
<p>Links - these should all point to the name property:</p>
78+
<ul>
79+
<li><a href="_classes_.nameinterface.html#name">name</a></li>
80+
<li><a href="_classes_.nameinterface.html#name">NameInterface.name</a></li>
81+
<li><a href="_classes_.nameinterface.html#name">&quot;classes&quot;.NameInterface.name</a></li>
82+
<li><a href="_classes_.nameinterface.html#name">Text</a> &lt;-- This one goes away eventually</li>
83+
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
84+
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
85+
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
86+
</ul>
7787
</div>
7888
</section>
7989
<section class="tsd-panel tsd-hierarchy">
@@ -129,6 +139,21 @@ <h3>name</h3>
129139
<p>This is a interface member of INameInterface.</p>
130140
</div>
131141
<p>It should be inherited by all subinterfaces.</p>
142+
<p>Links - these should all point to this property:</p>
143+
<ul>
144+
<li><a href="_classes_.nameinterface.html#name">name</a></li>
145+
<li><a href="_classes_.nameinterface.html#name">NameInterface.name</a></li>
146+
<li><a href="_classes_.nameinterface.html#name">&quot;classes&quot;.NameInterface.name</a></li>
147+
<li><a href="_classes_.nameinterface.html#name">Text</a> &lt;-- This one goes away eventually</li>
148+
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
149+
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
150+
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
151+
</ul>
152+
<p>Links - these should point to the containing interface</p>
153+
<ul>
154+
<li><a href="_classes_.nameinterface.html">NameInterface</a></li>
155+
<li><a href="_classes_.nameinterface.html">&quot;classes&quot;.NameInterface</a></li>
156+
</ul>
132157
</div>
133158
</section>
134159
</section>

src/test/renderer/specs/interfaces/_classes_.printnameinterface.html

+15
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ <h3>name</h3>
133133
<p>This is a interface member of INameInterface.</p>
134134
</div>
135135
<p>It should be inherited by all subinterfaces.</p>
136+
<p>Links - these should all point to this property:</p>
137+
<ul>
138+
<li><a href="_classes_.printnameinterface.html#name">name</a></li>
139+
<li><a href="_classes_.nameinterface.html#name">NameInterface.name</a></li>
140+
<li><a href="_classes_.nameinterface.html#name">&quot;classes&quot;.NameInterface.name</a></li>
141+
<li><a href="_classes_.printnameinterface.html#name">Text</a> &lt;-- This one goes away eventually</li>
142+
<li><a href="_classes_.printnameinterface.html#name">Text</a></li>
143+
<li><a href="_classes_.printnameinterface.html#name">Text</a></li>
144+
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
145+
</ul>
146+
<p>Links - these should point to the containing interface</p>
147+
<ul>
148+
<li><a href="_classes_.nameinterface.html">NameInterface</a></li>
149+
<li><a href="_classes_.nameinterface.html">&quot;classes&quot;.NameInterface</a></li>
150+
</ul>
136151
</div>
137152
</section>
138153
</section>

0 commit comments

Comments
 (0)