Skip to content

Commit

Permalink
fix: Trim whitespace when parsing links
Browse files Browse the repository at this point in the history
Closes #1302
  • Loading branch information
Gerrit0 committed May 15, 2020
1 parent 0708fb8 commit 935e10a
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -15,3 +15,5 @@ yarn-error.log

typedoc*.tgz
tmp

src/test/renderer/specs/assets/*
26 changes: 26 additions & 0 deletions examples/basic/src/classes.ts
@@ -1,11 +1,33 @@
/**
* This is a simple interface.
*
* Links - these should all point to the name property:
* - {@link name}
* - {@link NameInterface.name}
* - {@link "classes".NameInterface.name}
* - {@link name Text} <-- This one goes away eventually
* - {@link name|Text}
* - {@link name | Text}
* - {@link NameInterface.name | Text}
*/
export interface NameInterface {
/**
* This is a interface member of INameInterface.
*
* It should be inherited by all subinterfaces.
*
* Links - these should all point to this property:
* - {@link name}
* - {@link NameInterface.name}
* - {@link "classes".NameInterface.name}
* - {@link name Text} <-- This one goes away eventually
* - {@link name|Text}
* - {@link name | Text}
* - {@link NameInterface.name | Text}
*
* Links - these should point to the containing interface
* - {@link NameInterface}
* - {@link "classes".NameInterface}
*/
name: string;

Expand Down Expand Up @@ -43,6 +65,10 @@ export interface PrintNameInterface extends NameInterface, PrintInterface {
* This is a simple base class.
*
* [[include:class-example.md]]
*
* Links:
* - {@link name | The name property on this class}
* - {@link NameInterface.name | The name property we inherit from the interface}
*/
export abstract class BaseClass implements NameInterface {
/**
Expand Down
1 change: 0 additions & 1 deletion scripts/rebuild_specs.js
Expand Up @@ -84,7 +84,6 @@ async function rebuildRendererTest() {
app.options.setValue('excludeExternals', false);
app.generateDocs(app.expandInputFiles([src]), out)
app.options.setValue('excludeExternals', true);
await fs.remove(path.join(out, 'assets'))

/**
* Avoiding sync methods here is... difficult.
Expand Down
8 changes: 4 additions & 4 deletions src/lib/output/plugins/MarkedLinksPlugin.ts
Expand Up @@ -16,7 +16,7 @@ export class MarkedLinksPlugin extends ContextAwareRendererComponent {
private brackets: RegExp = /\[\[([^\]]+)\]\]/g;

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

Expand Down Expand Up @@ -56,7 +56,7 @@ export class MarkedLinksPlugin extends ContextAwareRendererComponent {
}

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

if (splitIndex !== -1) {
return {
caption: text.substr(splitIndex + 1).replace(/\n+/, ' '),
target: text.substr(0, splitIndex)
caption: text.substr(splitIndex + 1).replace(/\n+/, ' ').trim(),
target: text.substr(0, splitIndex).trim()
};
} else {
return {
Expand Down
5 changes: 5 additions & 0 deletions src/test/renderer/specs/classes/_classes_.baseclass.html
Expand Up @@ -75,6 +75,11 @@ <h1>Class BaseClass</h1>
<p>This is a simple base class.</p>
</div>
<p>[[include:class-example.md]]</p>
<p>Links:</p>
<ul>
<li><a href="_classes_.baseclass.html#name">The name property on this class</a></li>
<li><a href="../interfaces/_classes_.nameinterface.html#name">The name property we inherit from the interface</a></li>
</ul>
</div>
</section>
<section class="tsd-panel tsd-hierarchy">
Expand Down
25 changes: 25 additions & 0 deletions src/test/renderer/specs/interfaces/_classes_.nameinterface.html
Expand Up @@ -74,6 +74,16 @@ <h1>Interface NameInterface</h1>
<div class="lead">
<p>This is a simple interface.</p>
</div>
<p>Links - these should all point to the name property:</p>
<ul>
<li><a href="_classes_.nameinterface.html#name">name</a></li>
<li><a href="_classes_.nameinterface.html#name">NameInterface.name</a></li>
<li><a href="_classes_.nameinterface.html#name">&quot;classes&quot;.NameInterface.name</a></li>
<li><a href="_classes_.nameinterface.html#name">Text</a> &lt;-- This one goes away eventually</li>
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
</ul>
</div>
</section>
<section class="tsd-panel tsd-hierarchy">
Expand Down Expand Up @@ -129,6 +139,21 @@ <h3>name</h3>
<p>This is a interface member of INameInterface.</p>
</div>
<p>It should be inherited by all subinterfaces.</p>
<p>Links - these should all point to this property:</p>
<ul>
<li><a href="_classes_.nameinterface.html#name">name</a></li>
<li><a href="_classes_.nameinterface.html#name">NameInterface.name</a></li>
<li><a href="_classes_.nameinterface.html#name">&quot;classes&quot;.NameInterface.name</a></li>
<li><a href="_classes_.nameinterface.html#name">Text</a> &lt;-- This one goes away eventually</li>
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
</ul>
<p>Links - these should point to the containing interface</p>
<ul>
<li><a href="_classes_.nameinterface.html">NameInterface</a></li>
<li><a href="_classes_.nameinterface.html">&quot;classes&quot;.NameInterface</a></li>
</ul>
</div>
</section>
</section>
Expand Down
Expand Up @@ -133,6 +133,21 @@ <h3>name</h3>
<p>This is a interface member of INameInterface.</p>
</div>
<p>It should be inherited by all subinterfaces.</p>
<p>Links - these should all point to this property:</p>
<ul>
<li><a href="_classes_.printnameinterface.html#name">name</a></li>
<li><a href="_classes_.nameinterface.html#name">NameInterface.name</a></li>
<li><a href="_classes_.nameinterface.html#name">&quot;classes&quot;.NameInterface.name</a></li>
<li><a href="_classes_.printnameinterface.html#name">Text</a> &lt;-- This one goes away eventually</li>
<li><a href="_classes_.printnameinterface.html#name">Text</a></li>
<li><a href="_classes_.printnameinterface.html#name">Text</a></li>
<li><a href="_classes_.nameinterface.html#name">Text</a></li>
</ul>
<p>Links - these should point to the containing interface</p>
<ul>
<li><a href="_classes_.nameinterface.html">NameInterface</a></li>
<li><a href="_classes_.nameinterface.html">&quot;classes&quot;.NameInterface</a></li>
</ul>
</div>
</section>
</section>
Expand Down

0 comments on commit 935e10a

Please sign in to comment.