Skip to content

Commit ea11d50

Browse files
kamranayubblakeembrey
authored andcommitted
Add --listInvalidSymbolLinks option to list broken symbol links after generation (#370)
1 parent 8a9234f commit ea11d50

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/lib/output/plugins/MarkedLinksPlugin.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import * as Util from "util";
22

33
import {Reflection} from "../../models/reflections/abstract";
44
import {Component, ContextAwareRendererComponent} from "../components";
5-
import {MarkdownEvent} from "../events";
6-
5+
import {MarkdownEvent, RendererEvent} from "../events";
6+
import {Option} from "../../utils/component";
7+
import {ParameterType} from "../../utils/options/declaration";
78

89
/**
910
* A plugin that builds links in markdown texts.
@@ -26,14 +27,24 @@ export class MarkedLinksPlugin extends ContextAwareRendererComponent
2627
*/
2728
private urlPrefix:RegExp = /^(http|ftp)s?:\/\//;
2829

30+
@Option({
31+
name: 'listInvalidSymbolLinks',
32+
help: 'Emits a list of broken symbol [[navigation]] links after documentation generation',
33+
type: ParameterType.Boolean
34+
})
35+
listInvalidSymbolLinks:boolean;
2936

37+
private warnings: string[] = [];
3038

3139
/**
3240
* Create a new MarkedLinksPlugin instance.
3341
*/
3442
initialize() {
3543
super.initialize();
36-
this.listenTo(this.owner, MarkdownEvent.PARSE, this.onParseMarkdown, 100);
44+
this.listenTo(this.owner, {
45+
[MarkdownEvent.PARSE]: this.onParseMarkdown,
46+
[RendererEvent.END]: this.onEndRenderer
47+
}, null, 100);
3748
}
3849

3950

@@ -101,6 +112,8 @@ export class MarkedLinksPlugin extends ContextAwareRendererComponent
101112
if (reflection && reflection.url) {
102113
target = this.getRelativeUrl(reflection.url);
103114
} else {
115+
reflection = this.reflection || this.project;
116+
this.warnings.push(`In ${reflection.getFullName()}: ${original}`);
104117
return original;
105118
}
106119
}
@@ -122,6 +135,20 @@ export class MarkedLinksPlugin extends ContextAwareRendererComponent
122135
event.parsedText = this.replaceInlineTags(this.replaceBrackets(event.parsedText));
123136
}
124137

138+
/**
139+
* Triggered when [[Renderer]] is finished
140+
*/
141+
onEndRenderer(event:RendererEvent) {
142+
if (this.listInvalidSymbolLinks && this.warnings.length > 0) {
143+
this.application.logger.write('');
144+
this.application.logger.warn('[MarkedLinksPlugin]: Found invalid symbol reference(s) in JSDocs, ' +
145+
'they will not render as links in the generated documentation.');
146+
147+
for (var warning of this.warnings) {
148+
this.application.logger.write(' ' + warning);
149+
}
150+
}
151+
}
125152

126153
/**
127154
* Split the given link into text and target at first pipe or space.

src/lib/output/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class Renderer extends ChildableComponent<Application, RendererComponent>
103103
help: 'Specifies the fully qualified name of the root symbol. Defaults to global namespace.',
104104
type: ParameterType.String
105105
})
106-
entryPoint:string;
106+
entryPoint:string;
107107

108108
/**
109109
* Create a new Renderer instance.

0 commit comments

Comments
 (0)