ts-japi 1.5.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/.prettierrc +10 -0
  2. package/CHANGELOG.md +56 -16
  3. package/Makefile +19 -0
  4. package/README.md +235 -159
  5. package/api-extractor.json +14 -0
  6. package/benchmarks/playground.benchmark.ts +32 -32
  7. package/benchmarks/serializer.benchmark.ts +29 -29
  8. package/lib/classes/cache.d.ts +6 -6
  9. package/lib/classes/cache.d.ts.map +1 -1
  10. package/lib/classes/cache.js +26 -48
  11. package/lib/classes/cache.js.map +1 -1
  12. package/lib/classes/error-serializer.d.ts +9 -9
  13. package/lib/classes/error-serializer.d.ts.map +1 -1
  14. package/lib/classes/error-serializer.js +58 -125
  15. package/lib/classes/error-serializer.js.map +1 -1
  16. package/lib/classes/linker.d.ts +8 -8
  17. package/lib/classes/linker.d.ts.map +1 -1
  18. package/lib/classes/linker.js +15 -40
  19. package/lib/classes/linker.js.map +1 -1
  20. package/lib/classes/metaizer.d.ts +6 -6
  21. package/lib/classes/metaizer.d.ts.map +1 -1
  22. package/lib/classes/metaizer.js +12 -37
  23. package/lib/classes/metaizer.js.map +1 -1
  24. package/lib/classes/paginator.d.ts +6 -6
  25. package/lib/classes/paginator.d.ts.map +1 -1
  26. package/lib/classes/paginator.js +17 -16
  27. package/lib/classes/paginator.js.map +1 -1
  28. package/lib/classes/relator.d.ts +19 -18
  29. package/lib/classes/relator.d.ts.map +1 -1
  30. package/lib/classes/relator.js +70 -110
  31. package/lib/classes/relator.js.map +1 -1
  32. package/lib/classes/serializer.d.ts +20 -19
  33. package/lib/classes/serializer.d.ts.map +1 -1
  34. package/lib/classes/serializer.js +213 -311
  35. package/lib/classes/serializer.js.map +1 -1
  36. package/lib/index.d.ts +20 -20
  37. package/lib/index.js +17 -10
  38. package/lib/index.js.map +1 -1
  39. package/lib/interfaces/cache.interface.d.ts +3 -3
  40. package/lib/interfaces/cache.interface.d.ts.map +1 -1
  41. package/lib/interfaces/cache.interface.js +1 -1
  42. package/lib/interfaces/error-serializer.interface.d.ts +15 -15
  43. package/lib/interfaces/error-serializer.interface.d.ts.map +1 -1
  44. package/lib/interfaces/error-serializer.interface.js +1 -1
  45. package/lib/interfaces/error.interface.d.ts.map +1 -1
  46. package/lib/interfaces/error.interface.js +1 -1
  47. package/lib/interfaces/json-api.interface.d.ts +7 -7
  48. package/lib/interfaces/json-api.interface.d.ts.map +1 -1
  49. package/lib/interfaces/json-api.interface.js +1 -1
  50. package/lib/interfaces/linker.interface.d.ts +2 -2
  51. package/lib/interfaces/linker.interface.d.ts.map +1 -1
  52. package/lib/interfaces/linker.interface.js +1 -1
  53. package/lib/interfaces/paginator.interface.d.ts +1 -1
  54. package/lib/interfaces/paginator.interface.d.ts.map +1 -1
  55. package/lib/interfaces/paginator.interface.js +1 -1
  56. package/lib/interfaces/relator.interface.d.ts +7 -7
  57. package/lib/interfaces/relator.interface.d.ts.map +1 -1
  58. package/lib/interfaces/relator.interface.js +1 -1
  59. package/lib/interfaces/serializer.interface.d.ts +30 -30
  60. package/lib/interfaces/serializer.interface.d.ts.map +1 -1
  61. package/lib/interfaces/serializer.interface.js +1 -1
  62. package/lib/models/error.model.d.ts +5 -5
  63. package/lib/models/error.model.d.ts.map +1 -1
  64. package/lib/models/error.model.js +59 -22
  65. package/lib/models/error.model.js.map +1 -1
  66. package/lib/models/link.model.d.ts +2 -2
  67. package/lib/models/link.model.d.ts.map +1 -1
  68. package/lib/models/link.model.js +11 -10
  69. package/lib/models/link.model.js.map +1 -1
  70. package/lib/models/meta.model.d.ts.map +1 -1
  71. package/lib/models/meta.model.js +5 -6
  72. package/lib/models/meta.model.js.map +1 -1
  73. package/lib/models/relationship.model.d.ts +4 -4
  74. package/lib/models/relationship.model.d.ts.map +1 -1
  75. package/lib/models/relationship.model.js +11 -9
  76. package/lib/models/relationship.model.js.map +1 -1
  77. package/lib/models/resource-identifier.model.d.ts +1 -1
  78. package/lib/models/resource-identifier.model.d.ts.map +1 -1
  79. package/lib/models/resource-identifier.model.js +11 -9
  80. package/lib/models/resource-identifier.model.js.map +1 -1
  81. package/lib/models/resource.model.d.ts +4 -4
  82. package/lib/models/resource.model.d.ts.map +1 -1
  83. package/lib/models/resource.model.js +13 -26
  84. package/lib/models/resource.model.js.map +1 -1
  85. package/lib/tsdoc-metadata.json +11 -0
  86. package/lib/types/global.types.d.ts.map +1 -1
  87. package/lib/types/global.types.js +1 -1
  88. package/lib/utils/is-error-document.d.ts +2 -2
  89. package/lib/utils/is-error-document.js +7 -9
  90. package/lib/utils/is-error-document.js.map +1 -1
  91. package/lib/utils/is-object.js +2 -2
  92. package/lib/utils/is-object.js.map +1 -1
  93. package/lib/utils/is-plain-object.js +6 -6
  94. package/lib/utils/is-plain-object.js.map +1 -1
  95. package/lib/utils/merge.d.ts +3 -3
  96. package/lib/utils/merge.d.ts.map +1 -1
  97. package/lib/utils/merge.js +16 -62
  98. package/lib/utils/merge.js.map +1 -1
  99. package/lib/utils/serializer.utils.d.ts +5 -4
  100. package/lib/utils/serializer.utils.d.ts.map +1 -1
  101. package/lib/utils/serializer.utils.js +57 -168
  102. package/lib/utils/serializer.utils.js.map +1 -1
  103. package/package.json +94 -107
  104. package/tools/generate_docs.ts +33 -0
  105. package/tools/internal/custom_markdown_action.ts +32 -0
  106. package/tools/internal/custom_markdown_documenter.ts +1337 -0
  107. package/tsconfig.json +60 -83
  108. package/CONTRIBUTING.md +0 -127
@@ -0,0 +1,1337 @@
1
+ /**
2
+ * Copyright 2022 Google Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the
18
+ // MIT license. See LICENSE in the project root for license information.
19
+
20
+ // Taken from
21
+ // https://github.com/microsoft/rushstack/blob/main/apps/api-documenter/src/documenters/MarkdownDocumenter.ts
22
+ // This file has been edited to morph into Docusaurus's expected inputs.
23
+
24
+ import {
25
+ ApiClass,
26
+ ApiDeclaredItem,
27
+ ApiDocumentedItem,
28
+ ApiEnum,
29
+ ApiInitializerMixin,
30
+ ApiInterface,
31
+ ApiItem,
32
+ ApiItemKind,
33
+ ApiModel,
34
+ ApiNamespace,
35
+ ApiOptionalMixin,
36
+ ApiPackage,
37
+ ApiParameterListMixin,
38
+ ApiPropertyItem,
39
+ ApiProtectedMixin,
40
+ ApiReadonlyMixin,
41
+ ApiReleaseTagMixin,
42
+ ApiReturnTypeMixin,
43
+ ApiStaticMixin,
44
+ ApiTypeAlias,
45
+ Excerpt,
46
+ ExcerptToken,
47
+ ExcerptTokenKind,
48
+ IResolveDeclarationReferenceResult,
49
+ ReleaseTag,
50
+ } from '@microsoft/api-extractor-model';
51
+ import {
52
+ DocBlock,
53
+ DocCodeSpan,
54
+ DocComment,
55
+ DocFencedCode,
56
+ DocLinkTag,
57
+ DocNodeContainer,
58
+ DocNodeKind,
59
+ DocParagraph,
60
+ DocPlainText,
61
+ DocSection,
62
+ StandardTags,
63
+ StringBuilder,
64
+ TSDocConfiguration,
65
+ } from '@microsoft/tsdoc';
66
+ import { FileSystem, NewlineKind, PackageName } from '@rushstack/node-core-library';
67
+ import * as path from 'path';
68
+
69
+ import { DocumenterConfig } from '@microsoft/api-documenter/lib/documenters/DocumenterConfig';
70
+ import { CustomMarkdownEmitter } from '@microsoft/api-documenter/lib/markdown/CustomMarkdownEmitter';
71
+ import { CustomDocNodes } from '@microsoft/api-documenter/lib/nodes/CustomDocNodeKind';
72
+ import { DocEmphasisSpan } from '@microsoft/api-documenter/lib/nodes/DocEmphasisSpan';
73
+ import { DocHeading } from '@microsoft/api-documenter/lib/nodes/DocHeading';
74
+ import { DocNoteBox } from '@microsoft/api-documenter/lib/nodes/DocNoteBox';
75
+ import { DocTable } from '@microsoft/api-documenter/lib/nodes/DocTable';
76
+ import { DocTableCell } from '@microsoft/api-documenter/lib/nodes/DocTableCell';
77
+ import { DocTableRow } from '@microsoft/api-documenter/lib/nodes/DocTableRow';
78
+ import { MarkdownDocumenterAccessor } from '@microsoft/api-documenter/lib/plugin/MarkdownDocumenterAccessor';
79
+ import {
80
+ IMarkdownDocumenterFeatureOnBeforeWritePageArgs,
81
+ MarkdownDocumenterFeatureContext,
82
+ } from '@microsoft/api-documenter/lib/plugin/MarkdownDocumenterFeature';
83
+ import { PluginLoader } from '@microsoft/api-documenter/lib/plugin/PluginLoader';
84
+ import { Utilities } from '@microsoft/api-documenter/lib/utils/Utilities';
85
+
86
+ export interface IMarkdownDocumenterOptions {
87
+ apiModel: ApiModel;
88
+ documenterConfig: DocumenterConfig | undefined;
89
+ outputFolder: string;
90
+ }
91
+
92
+ /**
93
+ * Renders API documentation in the Markdown file format.
94
+ * For more info: https://en.wikipedia.org/wiki/Markdown
95
+ */
96
+ export class MarkdownDocumenter {
97
+ private readonly _apiModel: ApiModel;
98
+ private readonly _documenterConfig: DocumenterConfig | undefined;
99
+ private readonly _tsdocConfiguration: TSDocConfiguration;
100
+ private readonly _markdownEmitter: CustomMarkdownEmitter;
101
+ private readonly _outputFolder: string;
102
+ private readonly _pluginLoader: PluginLoader;
103
+
104
+ public constructor(options: IMarkdownDocumenterOptions) {
105
+ this._apiModel = options.apiModel;
106
+ this._documenterConfig = options.documenterConfig;
107
+ this._outputFolder = options.outputFolder;
108
+ this._tsdocConfiguration = CustomDocNodes.configuration;
109
+ this._markdownEmitter = new CustomMarkdownEmitter(this._apiModel);
110
+
111
+ this._pluginLoader = new PluginLoader();
112
+ }
113
+
114
+ public generateFiles(): void {
115
+ if (this._documenterConfig) {
116
+ this._pluginLoader.load(this._documenterConfig, () => {
117
+ return new MarkdownDocumenterFeatureContext({
118
+ apiModel: this._apiModel,
119
+ outputFolder: this._outputFolder,
120
+ documenter: new MarkdownDocumenterAccessor({
121
+ getLinkForApiItem: (apiItem: ApiItem) => {
122
+ return this._getLinkFilenameForApiItem(apiItem);
123
+ },
124
+ }),
125
+ });
126
+ });
127
+ }
128
+
129
+ console.log();
130
+ this._deleteOldOutputFiles();
131
+
132
+ this._writeApiItemPage(this._apiModel.members[0]!);
133
+
134
+ if (this._pluginLoader.markdownDocumenterFeature) {
135
+ this._pluginLoader.markdownDocumenterFeature.onFinished({});
136
+ }
137
+ }
138
+
139
+ private _writeApiItemPage(apiItem: ApiItem): void {
140
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
141
+ const output: DocSection = new DocSection({
142
+ configuration: this._tsdocConfiguration,
143
+ });
144
+
145
+ const scopedName: string = apiItem.getScopedNameWithinPackage();
146
+
147
+ switch (apiItem.kind) {
148
+ case ApiItemKind.Class:
149
+ output.appendNode(new DocHeading({ configuration, title: `${scopedName} class` }));
150
+ break;
151
+ case ApiItemKind.Enum:
152
+ output.appendNode(new DocHeading({ configuration, title: `${scopedName} enum` }));
153
+ break;
154
+ case ApiItemKind.Interface:
155
+ output.appendNode(new DocHeading({ configuration, title: `${scopedName} interface` }));
156
+ break;
157
+ case ApiItemKind.Constructor:
158
+ case ApiItemKind.ConstructSignature:
159
+ output.appendNode(new DocHeading({ configuration, title: scopedName }));
160
+ break;
161
+ case ApiItemKind.Method:
162
+ case ApiItemKind.MethodSignature:
163
+ output.appendNode(new DocHeading({ configuration, title: `${scopedName} method` }));
164
+ break;
165
+ case ApiItemKind.Function:
166
+ output.appendNode(new DocHeading({ configuration, title: `${scopedName} function` }));
167
+ break;
168
+ case ApiItemKind.Model:
169
+ output.appendNode(new DocHeading({ configuration, title: `API Reference` }));
170
+ break;
171
+ case ApiItemKind.Namespace:
172
+ output.appendNode(new DocHeading({ configuration, title: `${scopedName} namespace` }));
173
+ break;
174
+ case ApiItemKind.Package:
175
+ console.log(`Writing ${apiItem.displayName} package`);
176
+ output.appendNode(
177
+ new DocHeading({
178
+ configuration,
179
+ title: `API Reference`,
180
+ })
181
+ );
182
+ break;
183
+ case ApiItemKind.Property:
184
+ case ApiItemKind.PropertySignature:
185
+ output.appendNode(new DocHeading({ configuration, title: `${scopedName} property` }));
186
+ break;
187
+ case ApiItemKind.TypeAlias:
188
+ output.appendNode(new DocHeading({ configuration, title: `${scopedName} type` }));
189
+ break;
190
+ case ApiItemKind.Variable:
191
+ output.appendNode(new DocHeading({ configuration, title: `${scopedName} variable` }));
192
+ break;
193
+ default:
194
+ throw new Error('Unsupported API item kind: ' + apiItem.kind);
195
+ }
196
+
197
+ if (ApiReleaseTagMixin.isBaseClassOf(apiItem)) {
198
+ if (apiItem.releaseTag === ReleaseTag.Beta) {
199
+ this._writeBetaWarning(output);
200
+ }
201
+ }
202
+
203
+ const decoratorBlocks: DocBlock[] = [];
204
+
205
+ if (apiItem instanceof ApiDocumentedItem) {
206
+ const tsdocComment: DocComment | undefined = apiItem.tsdocComment;
207
+
208
+ if (tsdocComment) {
209
+ decoratorBlocks.push(
210
+ ...tsdocComment.customBlocks.filter((block) => {
211
+ return (
212
+ block.blockTag.tagNameWithUpperCase === StandardTags.decorator.tagNameWithUpperCase
213
+ );
214
+ })
215
+ );
216
+
217
+ if (tsdocComment.deprecatedBlock) {
218
+ output.appendNode(
219
+ new DocNoteBox({ configuration: this._tsdocConfiguration }, [
220
+ new DocParagraph({ configuration: this._tsdocConfiguration }, [
221
+ new DocPlainText({
222
+ configuration: this._tsdocConfiguration,
223
+ text: 'Warning: This API is now obsolete. ',
224
+ }),
225
+ ]),
226
+ ...tsdocComment.deprecatedBlock.content.nodes,
227
+ ])
228
+ );
229
+ }
230
+
231
+ this._appendSection(output, tsdocComment.summarySection);
232
+ }
233
+ }
234
+
235
+ if (apiItem instanceof ApiDeclaredItem) {
236
+ if (apiItem.excerpt.text.length > 0) {
237
+ output.appendNode(
238
+ new DocParagraph({ configuration }, [
239
+ new DocEmphasisSpan({ configuration, bold: true }, [
240
+ new DocPlainText({ configuration, text: 'Signature:' }),
241
+ ]),
242
+ ])
243
+ );
244
+
245
+ let code: string;
246
+ switch (apiItem.parent?.kind) {
247
+ case ApiItemKind.Class:
248
+ code = `class ${apiItem.parent.displayName} {${apiItem.getExcerptWithModifiers()}}`;
249
+ break;
250
+ case ApiItemKind.Interface:
251
+ code = `interface ${apiItem.parent.displayName} {${apiItem.getExcerptWithModifiers()}}`;
252
+ break;
253
+ default:
254
+ code = apiItem.getExcerptWithModifiers();
255
+ }
256
+ output.appendNode(
257
+ new DocFencedCode({
258
+ configuration,
259
+ code: code,
260
+ language: 'typescript',
261
+ })
262
+ );
263
+ }
264
+
265
+ this._writeHeritageTypes(output, apiItem);
266
+ }
267
+
268
+ if (decoratorBlocks.length > 0) {
269
+ output.appendNode(
270
+ new DocParagraph({ configuration }, [
271
+ new DocEmphasisSpan({ configuration, bold: true }, [
272
+ new DocPlainText({ configuration, text: 'Decorators:' }),
273
+ ]),
274
+ ])
275
+ );
276
+ for (const decoratorBlock of decoratorBlocks) {
277
+ output.appendNodes(decoratorBlock.content.nodes);
278
+ }
279
+ }
280
+
281
+ let appendRemarks = true;
282
+ switch (apiItem.kind) {
283
+ case ApiItemKind.Class:
284
+ case ApiItemKind.Interface:
285
+ case ApiItemKind.Namespace:
286
+ case ApiItemKind.Package:
287
+ this._writeRemarksSection(output, apiItem);
288
+ appendRemarks = false;
289
+ break;
290
+ }
291
+
292
+ switch (apiItem.kind) {
293
+ case ApiItemKind.Class:
294
+ this._writeClassTables(output, apiItem as ApiClass);
295
+ break;
296
+ case ApiItemKind.Enum:
297
+ this._writeEnumTables(output, apiItem as ApiEnum);
298
+ break;
299
+ case ApiItemKind.Interface:
300
+ this._writeInterfaceTables(output, apiItem as ApiInterface);
301
+ break;
302
+ case ApiItemKind.Constructor:
303
+ case ApiItemKind.ConstructSignature:
304
+ case ApiItemKind.Method:
305
+ case ApiItemKind.MethodSignature:
306
+ case ApiItemKind.Function:
307
+ this._writeParameterTables(output, apiItem as ApiParameterListMixin);
308
+ this._writeThrowsSection(output, apiItem);
309
+ break;
310
+ case ApiItemKind.Namespace:
311
+ this._writePackageOrNamespaceTables(output, apiItem as ApiNamespace);
312
+ break;
313
+ case ApiItemKind.Model:
314
+ this._writeModelTable(output, apiItem as ApiModel);
315
+ break;
316
+ case ApiItemKind.Package:
317
+ this._writePackageOrNamespaceTables(output, apiItem as ApiPackage);
318
+ break;
319
+ case ApiItemKind.Property:
320
+ case ApiItemKind.PropertySignature:
321
+ break;
322
+ case ApiItemKind.TypeAlias:
323
+ break;
324
+ case ApiItemKind.Variable:
325
+ break;
326
+ default:
327
+ throw new Error('Unsupported API item kind: ' + apiItem.kind);
328
+ }
329
+
330
+ if (appendRemarks) {
331
+ this._writeRemarksSection(output, apiItem);
332
+ }
333
+
334
+ const filename: string = path.join(this._outputFolder, this._getFilenameForApiItem(apiItem));
335
+ const stringBuilder: StringBuilder = new StringBuilder();
336
+
337
+ this._markdownEmitter.emit(stringBuilder, output, {
338
+ contextApiItem: apiItem,
339
+ onGetFilenameForApiItem: (apiItemForFilename: ApiItem) => {
340
+ return this._getLinkFilenameForApiItem(apiItemForFilename);
341
+ },
342
+ });
343
+
344
+ let pageContent: string = stringBuilder.toString();
345
+
346
+ if (this._pluginLoader.markdownDocumenterFeature) {
347
+ // Allow the plugin to customize the pageContent
348
+ const eventArgs: IMarkdownDocumenterFeatureOnBeforeWritePageArgs = {
349
+ apiItem: apiItem,
350
+ outputFilename: filename,
351
+ pageContent: pageContent,
352
+ };
353
+ this._pluginLoader.markdownDocumenterFeature.onBeforeWritePage(eventArgs);
354
+ pageContent = eventArgs.pageContent;
355
+ }
356
+
357
+ pageContent =
358
+ `---\nsidebar_label: ${this._getSidebarLabelForApiItem(apiItem)}\n---` + pageContent;
359
+ pageContent = pageContent.replace('##', '#');
360
+ pageContent = pageContent.replace(/<!-- -->/g, '');
361
+ pageContent = pageContent.replace(/<b>|<\/b>/g, '**');
362
+ FileSystem.writeFile(filename, pageContent, {
363
+ convertLineEndings: this._documenterConfig
364
+ ? this._documenterConfig.newlineKind
365
+ : NewlineKind.CrLf,
366
+ });
367
+ }
368
+
369
+ private _writeHeritageTypes(output: DocSection, apiItem: ApiDeclaredItem): void {
370
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
371
+
372
+ if (apiItem instanceof ApiClass) {
373
+ if (apiItem.extendsType) {
374
+ const extendsParagraph: DocParagraph = new DocParagraph({ configuration }, [
375
+ new DocEmphasisSpan({ configuration, bold: true }, [
376
+ new DocPlainText({ configuration, text: 'Extends: ' }),
377
+ ]),
378
+ ]);
379
+ this._appendExcerptWithHyperlinks(extendsParagraph, apiItem.extendsType.excerpt);
380
+ output.appendNode(extendsParagraph);
381
+ }
382
+ if (apiItem.implementsTypes.length > 0) {
383
+ const extendsParagraph: DocParagraph = new DocParagraph({ configuration }, [
384
+ new DocEmphasisSpan({ configuration, bold: true }, [
385
+ new DocPlainText({ configuration, text: 'Implements: ' }),
386
+ ]),
387
+ ]);
388
+ let needsComma = false;
389
+ for (const implementsType of apiItem.implementsTypes) {
390
+ if (needsComma) {
391
+ extendsParagraph.appendNode(new DocPlainText({ configuration, text: ', ' }));
392
+ }
393
+ this._appendExcerptWithHyperlinks(extendsParagraph, implementsType.excerpt);
394
+ needsComma = true;
395
+ }
396
+ output.appendNode(extendsParagraph);
397
+ }
398
+ }
399
+
400
+ if (apiItem instanceof ApiInterface) {
401
+ if (apiItem.extendsTypes.length > 0) {
402
+ const extendsParagraph: DocParagraph = new DocParagraph({ configuration }, [
403
+ new DocEmphasisSpan({ configuration, bold: true }, [
404
+ new DocPlainText({ configuration, text: 'Extends: ' }),
405
+ ]),
406
+ ]);
407
+ let needsComma = false;
408
+ for (const extendsType of apiItem.extendsTypes) {
409
+ if (needsComma) {
410
+ extendsParagraph.appendNode(new DocPlainText({ configuration, text: ', ' }));
411
+ }
412
+ this._appendExcerptWithHyperlinks(extendsParagraph, extendsType.excerpt);
413
+ needsComma = true;
414
+ }
415
+ output.appendNode(extendsParagraph);
416
+ }
417
+ }
418
+
419
+ if (apiItem instanceof ApiTypeAlias) {
420
+ const refs: ExcerptToken[] = apiItem.excerptTokens.filter((token) => {
421
+ return (
422
+ token.kind === ExcerptTokenKind.Reference &&
423
+ token.canonicalReference &&
424
+ this._apiModel.resolveDeclarationReference(token.canonicalReference, undefined)
425
+ .resolvedApiItem
426
+ );
427
+ });
428
+ if (refs.length > 0) {
429
+ const referencesParagraph: DocParagraph = new DocParagraph({ configuration }, [
430
+ new DocEmphasisSpan({ configuration, bold: true }, [
431
+ new DocPlainText({ configuration, text: 'References: ' }),
432
+ ]),
433
+ ]);
434
+ let needsComma = false;
435
+ const visited: Set<string> = new Set();
436
+ for (const ref of refs) {
437
+ if (visited.has(ref.text)) {
438
+ continue;
439
+ }
440
+ visited.add(ref.text);
441
+
442
+ if (needsComma) {
443
+ referencesParagraph.appendNode(new DocPlainText({ configuration, text: ', ' }));
444
+ }
445
+
446
+ this._appendExcerptTokenWithHyperlinks(referencesParagraph, ref);
447
+ needsComma = true;
448
+ }
449
+ output.appendNode(referencesParagraph);
450
+ }
451
+ }
452
+ }
453
+
454
+ private _writeRemarksSection(output: DocSection, apiItem: ApiItem): void {
455
+ if (apiItem instanceof ApiDocumentedItem) {
456
+ const tsdocComment: DocComment | undefined = apiItem.tsdocComment;
457
+
458
+ if (tsdocComment) {
459
+ // Write the @remarks block
460
+ if (tsdocComment.remarksBlock) {
461
+ output.appendNode(
462
+ new DocHeading({
463
+ configuration: this._tsdocConfiguration,
464
+ title: 'Remarks',
465
+ })
466
+ );
467
+ this._appendSection(output, tsdocComment.remarksBlock.content);
468
+ }
469
+
470
+ // Write the @example blocks
471
+ const exampleBlocks: DocBlock[] = tsdocComment.customBlocks.filter((x) => {
472
+ return x.blockTag.tagNameWithUpperCase === StandardTags.example.tagNameWithUpperCase;
473
+ });
474
+
475
+ let exampleNumber = 1;
476
+ for (const exampleBlock of exampleBlocks) {
477
+ const heading: string = exampleBlocks.length > 1 ? `Example ${exampleNumber}` : 'Example';
478
+
479
+ output.appendNode(
480
+ new DocHeading({
481
+ configuration: this._tsdocConfiguration,
482
+ title: heading,
483
+ })
484
+ );
485
+
486
+ this._appendSection(output, exampleBlock.content);
487
+
488
+ ++exampleNumber;
489
+ }
490
+ }
491
+ }
492
+ }
493
+
494
+ private _writeThrowsSection(output: DocSection, apiItem: ApiItem): void {
495
+ if (apiItem instanceof ApiDocumentedItem) {
496
+ const tsdocComment: DocComment | undefined = apiItem.tsdocComment;
497
+
498
+ if (tsdocComment) {
499
+ // Write the @throws blocks
500
+ const throwsBlocks: DocBlock[] = tsdocComment.customBlocks.filter((x) => {
501
+ return x.blockTag.tagNameWithUpperCase === StandardTags.throws.tagNameWithUpperCase;
502
+ });
503
+
504
+ if (throwsBlocks.length > 0) {
505
+ const heading = 'Exceptions';
506
+ output.appendNode(
507
+ new DocHeading({
508
+ configuration: this._tsdocConfiguration,
509
+ title: heading,
510
+ })
511
+ );
512
+
513
+ for (const throwsBlock of throwsBlocks) {
514
+ this._appendSection(output, throwsBlock.content);
515
+ }
516
+ }
517
+ }
518
+ }
519
+ }
520
+
521
+ /**
522
+ * GENERATE PAGE: MODEL
523
+ */
524
+ private _writeModelTable(output: DocSection, apiModel: ApiModel): void {
525
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
526
+
527
+ const packagesTable: DocTable = new DocTable({
528
+ configuration,
529
+ headerTitles: ['Package', 'Description'],
530
+ });
531
+
532
+ for (const apiMember of apiModel.members) {
533
+ const row: DocTableRow = new DocTableRow({ configuration }, [
534
+ this._createTitleCell(apiMember),
535
+ this._createDescriptionCell(apiMember),
536
+ ]);
537
+
538
+ switch (apiMember.kind) {
539
+ case ApiItemKind.Package:
540
+ packagesTable.addRow(row);
541
+ this._writeApiItemPage(apiMember);
542
+ break;
543
+ }
544
+ }
545
+
546
+ if (packagesTable.rows.length > 0) {
547
+ output.appendNode(
548
+ new DocHeading({
549
+ configuration: this._tsdocConfiguration,
550
+ title: 'Packages',
551
+ })
552
+ );
553
+ output.appendNode(packagesTable);
554
+ }
555
+ }
556
+
557
+ /**
558
+ * GENERATE PAGE: PACKAGE or NAMESPACE
559
+ */
560
+ private _writePackageOrNamespaceTables(
561
+ output: DocSection,
562
+ apiContainer: ApiPackage | ApiNamespace
563
+ ): void {
564
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
565
+
566
+ const classesTable: DocTable = new DocTable({
567
+ configuration,
568
+ headerTitles: ['Class', 'Description'],
569
+ });
570
+
571
+ const enumerationsTable: DocTable = new DocTable({
572
+ configuration,
573
+ headerTitles: ['Enumeration', 'Description'],
574
+ });
575
+
576
+ const functionsTable: DocTable = new DocTable({
577
+ configuration,
578
+ headerTitles: ['Function', 'Description'],
579
+ });
580
+
581
+ const interfacesTable: DocTable = new DocTable({
582
+ configuration,
583
+ headerTitles: ['Interface', 'Description'],
584
+ });
585
+
586
+ const namespacesTable: DocTable = new DocTable({
587
+ configuration,
588
+ headerTitles: ['Namespace', 'Description'],
589
+ });
590
+
591
+ const variablesTable: DocTable = new DocTable({
592
+ configuration,
593
+ headerTitles: ['Variable', 'Description'],
594
+ });
595
+
596
+ const typeAliasesTable: DocTable = new DocTable({
597
+ configuration,
598
+ headerTitles: ['Type Alias', 'Description'],
599
+ });
600
+
601
+ const apiMembers: ReadonlyArray<ApiItem> =
602
+ apiContainer.kind === ApiItemKind.Package
603
+ ? (apiContainer as ApiPackage).entryPoints[0]!.members
604
+ : (apiContainer as ApiNamespace).members;
605
+
606
+ for (const apiMember of apiMembers) {
607
+ const row: DocTableRow = new DocTableRow({ configuration }, [
608
+ this._createTitleCell(apiMember),
609
+ this._createDescriptionCell(apiMember),
610
+ ]);
611
+
612
+ switch (apiMember.kind) {
613
+ case ApiItemKind.Class:
614
+ classesTable.addRow(row);
615
+ this._writeApiItemPage(apiMember);
616
+ break;
617
+
618
+ case ApiItemKind.Enum:
619
+ enumerationsTable.addRow(row);
620
+ this._writeApiItemPage(apiMember);
621
+ break;
622
+
623
+ case ApiItemKind.Interface:
624
+ interfacesTable.addRow(row);
625
+ this._writeApiItemPage(apiMember);
626
+ break;
627
+
628
+ case ApiItemKind.Namespace:
629
+ namespacesTable.addRow(row);
630
+ this._writeApiItemPage(apiMember);
631
+ break;
632
+
633
+ case ApiItemKind.Function:
634
+ functionsTable.addRow(row);
635
+ this._writeApiItemPage(apiMember);
636
+ break;
637
+
638
+ case ApiItemKind.TypeAlias:
639
+ typeAliasesTable.addRow(row);
640
+ this._writeApiItemPage(apiMember);
641
+ break;
642
+
643
+ case ApiItemKind.Variable:
644
+ variablesTable.addRow(row);
645
+ this._writeApiItemPage(apiMember);
646
+ break;
647
+ }
648
+ }
649
+
650
+ if (classesTable.rows.length > 0) {
651
+ output.appendNode(
652
+ new DocHeading({
653
+ configuration: this._tsdocConfiguration,
654
+ title: 'Classes',
655
+ })
656
+ );
657
+ output.appendNode(classesTable);
658
+ }
659
+
660
+ if (enumerationsTable.rows.length > 0) {
661
+ output.appendNode(
662
+ new DocHeading({
663
+ configuration: this._tsdocConfiguration,
664
+ title: 'Enumerations',
665
+ })
666
+ );
667
+ output.appendNode(enumerationsTable);
668
+ }
669
+ if (functionsTable.rows.length > 0) {
670
+ output.appendNode(
671
+ new DocHeading({
672
+ configuration: this._tsdocConfiguration,
673
+ title: 'Functions',
674
+ })
675
+ );
676
+ output.appendNode(functionsTable);
677
+ }
678
+
679
+ if (interfacesTable.rows.length > 0) {
680
+ output.appendNode(
681
+ new DocHeading({
682
+ configuration: this._tsdocConfiguration,
683
+ title: 'Interfaces',
684
+ })
685
+ );
686
+ output.appendNode(interfacesTable);
687
+ }
688
+
689
+ if (namespacesTable.rows.length > 0) {
690
+ output.appendNode(
691
+ new DocHeading({
692
+ configuration: this._tsdocConfiguration,
693
+ title: 'Namespaces',
694
+ })
695
+ );
696
+ output.appendNode(namespacesTable);
697
+ }
698
+
699
+ if (variablesTable.rows.length > 0) {
700
+ output.appendNode(
701
+ new DocHeading({
702
+ configuration: this._tsdocConfiguration,
703
+ title: 'Variables',
704
+ })
705
+ );
706
+ output.appendNode(variablesTable);
707
+ }
708
+
709
+ if (typeAliasesTable.rows.length > 0) {
710
+ output.appendNode(
711
+ new DocHeading({
712
+ configuration: this._tsdocConfiguration,
713
+ title: 'Type Aliases',
714
+ })
715
+ );
716
+ output.appendNode(typeAliasesTable);
717
+ }
718
+ }
719
+
720
+ /**
721
+ * GENERATE PAGE: CLASS
722
+ */
723
+ private _writeClassTables(output: DocSection, apiClass: ApiClass): void {
724
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
725
+
726
+ const eventsTable: DocTable = new DocTable({
727
+ configuration,
728
+ headerTitles: ['Property', 'Modifiers', 'Type', 'Description'],
729
+ });
730
+
731
+ const constructorsTable: DocTable = new DocTable({
732
+ configuration,
733
+ headerTitles: ['Constructor', 'Modifiers', 'Description'],
734
+ });
735
+
736
+ const propertiesTable: DocTable = new DocTable({
737
+ configuration,
738
+ headerTitles: ['Property', 'Modifiers', 'Type', 'Description'],
739
+ });
740
+
741
+ const methodsTable: DocTable = new DocTable({
742
+ configuration,
743
+ headerTitles: ['Method', 'Modifiers', 'Description'],
744
+ });
745
+
746
+ for (const apiMember of apiClass.members) {
747
+ switch (apiMember.kind) {
748
+ case ApiItemKind.Constructor: {
749
+ constructorsTable.addRow(
750
+ new DocTableRow({ configuration }, [
751
+ this._createTitleCell(apiMember),
752
+ this._createModifiersCell(apiMember),
753
+ this._createDescriptionCell(apiMember),
754
+ ])
755
+ );
756
+
757
+ this._writeApiItemPage(apiMember);
758
+ break;
759
+ }
760
+ case ApiItemKind.Method: {
761
+ methodsTable.addRow(
762
+ new DocTableRow({ configuration }, [
763
+ this._createTitleCell(apiMember),
764
+ this._createModifiersCell(apiMember),
765
+ this._createDescriptionCell(apiMember),
766
+ ])
767
+ );
768
+
769
+ this._writeApiItemPage(apiMember);
770
+ break;
771
+ }
772
+ case ApiItemKind.Property: {
773
+ if ((apiMember as ApiPropertyItem).isEventProperty) {
774
+ eventsTable.addRow(
775
+ new DocTableRow({ configuration }, [
776
+ this._createTitleCell(apiMember),
777
+ this._createModifiersCell(apiMember),
778
+ this._createPropertyTypeCell(apiMember),
779
+ this._createDescriptionCell(apiMember),
780
+ ])
781
+ );
782
+ } else {
783
+ propertiesTable.addRow(
784
+ new DocTableRow({ configuration }, [
785
+ this._createTitleCell(apiMember),
786
+ this._createModifiersCell(apiMember),
787
+ this._createPropertyTypeCell(apiMember),
788
+ this._createDescriptionCell(apiMember),
789
+ ])
790
+ );
791
+ }
792
+
793
+ this._writeApiItemPage(apiMember);
794
+ break;
795
+ }
796
+ }
797
+ }
798
+
799
+ if (eventsTable.rows.length > 0) {
800
+ output.appendNode(
801
+ new DocHeading({
802
+ configuration: this._tsdocConfiguration,
803
+ title: 'Events',
804
+ })
805
+ );
806
+ output.appendNode(eventsTable);
807
+ }
808
+
809
+ if (constructorsTable.rows.length > 0) {
810
+ output.appendNode(
811
+ new DocHeading({
812
+ configuration: this._tsdocConfiguration,
813
+ title: 'Constructors',
814
+ })
815
+ );
816
+ output.appendNode(constructorsTable);
817
+ }
818
+
819
+ if (propertiesTable.rows.length > 0) {
820
+ output.appendNode(
821
+ new DocHeading({
822
+ configuration: this._tsdocConfiguration,
823
+ title: 'Properties',
824
+ })
825
+ );
826
+ output.appendNode(propertiesTable);
827
+ }
828
+
829
+ if (methodsTable.rows.length > 0) {
830
+ output.appendNode(
831
+ new DocHeading({
832
+ configuration: this._tsdocConfiguration,
833
+ title: 'Methods',
834
+ })
835
+ );
836
+ output.appendNode(methodsTable);
837
+ }
838
+ }
839
+
840
+ /**
841
+ * GENERATE PAGE: ENUM
842
+ */
843
+ private _writeEnumTables(output: DocSection, apiEnum: ApiEnum): void {
844
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
845
+
846
+ const enumMembersTable: DocTable = new DocTable({
847
+ configuration,
848
+ headerTitles: ['Member', 'Value', 'Description'],
849
+ });
850
+
851
+ for (const apiEnumMember of apiEnum.members) {
852
+ enumMembersTable.addRow(
853
+ new DocTableRow({ configuration }, [
854
+ new DocTableCell({ configuration }, [
855
+ new DocParagraph({ configuration }, [
856
+ new DocPlainText({
857
+ configuration,
858
+ text: Utilities.getConciseSignature(apiEnumMember),
859
+ }),
860
+ ]),
861
+ ]),
862
+ this._createInitializerCell(apiEnumMember),
863
+ this._createDescriptionCell(apiEnumMember),
864
+ ])
865
+ );
866
+ }
867
+
868
+ if (enumMembersTable.rows.length > 0) {
869
+ output.appendNode(
870
+ new DocHeading({
871
+ configuration: this._tsdocConfiguration,
872
+ title: 'Enumeration Members',
873
+ })
874
+ );
875
+ output.appendNode(enumMembersTable);
876
+ }
877
+ }
878
+
879
+ /**
880
+ * GENERATE PAGE: INTERFACE
881
+ */
882
+ private _writeInterfaceTables(output: DocSection, apiClass: ApiInterface): void {
883
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
884
+
885
+ const eventsTable: DocTable = new DocTable({
886
+ configuration,
887
+ headerTitles: ['Property', 'Modifiers', 'Type', 'Description'],
888
+ });
889
+
890
+ const propertiesTable: DocTable = new DocTable({
891
+ configuration,
892
+ headerTitles: ['Property', 'Modifiers', 'Type', 'Description'],
893
+ });
894
+
895
+ const methodsTable: DocTable = new DocTable({
896
+ configuration,
897
+ headerTitles: ['Method', 'Description'],
898
+ });
899
+
900
+ for (const apiMember of apiClass.members) {
901
+ switch (apiMember.kind) {
902
+ case ApiItemKind.ConstructSignature:
903
+ case ApiItemKind.MethodSignature: {
904
+ methodsTable.addRow(
905
+ new DocTableRow({ configuration }, [
906
+ this._createTitleCell(apiMember),
907
+ this._createDescriptionCell(apiMember),
908
+ ])
909
+ );
910
+
911
+ this._writeApiItemPage(apiMember);
912
+ break;
913
+ }
914
+ case ApiItemKind.PropertySignature: {
915
+ if ((apiMember as ApiPropertyItem).isEventProperty) {
916
+ eventsTable.addRow(
917
+ new DocTableRow({ configuration }, [
918
+ this._createTitleCell(apiMember),
919
+ this._createModifiersCell(apiMember),
920
+ this._createPropertyTypeCell(apiMember),
921
+ this._createDescriptionCell(apiMember),
922
+ ])
923
+ );
924
+ } else {
925
+ propertiesTable.addRow(
926
+ new DocTableRow({ configuration }, [
927
+ this._createTitleCell(apiMember),
928
+ this._createModifiersCell(apiMember),
929
+ this._createPropertyTypeCell(apiMember),
930
+ this._createDescriptionCell(apiMember),
931
+ ])
932
+ );
933
+ }
934
+
935
+ this._writeApiItemPage(apiMember);
936
+ break;
937
+ }
938
+ }
939
+ }
940
+
941
+ if (eventsTable.rows.length > 0) {
942
+ output.appendNode(
943
+ new DocHeading({
944
+ configuration: this._tsdocConfiguration,
945
+ title: 'Events',
946
+ })
947
+ );
948
+ output.appendNode(eventsTable);
949
+ }
950
+
951
+ if (propertiesTable.rows.length > 0) {
952
+ output.appendNode(
953
+ new DocHeading({
954
+ configuration: this._tsdocConfiguration,
955
+ title: 'Properties',
956
+ })
957
+ );
958
+ output.appendNode(propertiesTable);
959
+ }
960
+
961
+ if (methodsTable.rows.length > 0) {
962
+ output.appendNode(
963
+ new DocHeading({
964
+ configuration: this._tsdocConfiguration,
965
+ title: 'Methods',
966
+ })
967
+ );
968
+ output.appendNode(methodsTable);
969
+ }
970
+ }
971
+
972
+ /**
973
+ * GENERATE PAGE: FUNCTION-LIKE
974
+ */
975
+ private _writeParameterTables(
976
+ output: DocSection,
977
+ apiParameterListMixin: ApiParameterListMixin
978
+ ): void {
979
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
980
+
981
+ const parametersTable: DocTable = new DocTable({
982
+ configuration,
983
+ headerTitles: ['Parameter', 'Type', 'Description'],
984
+ });
985
+ for (const apiParameter of apiParameterListMixin.parameters) {
986
+ const parameterDescription: DocSection = new DocSection({ configuration });
987
+
988
+ if (apiParameter.isOptional) {
989
+ parameterDescription.appendNodesInParagraph([
990
+ new DocEmphasisSpan({ configuration, italic: true }, [
991
+ new DocPlainText({ configuration, text: '(Optional)' }),
992
+ ]),
993
+ new DocPlainText({ configuration, text: ' ' }),
994
+ ]);
995
+ }
996
+
997
+ if (apiParameter.tsdocParamBlock) {
998
+ this._appendAndMergeSection(parameterDescription, apiParameter.tsdocParamBlock.content);
999
+ }
1000
+
1001
+ parametersTable.addRow(
1002
+ new DocTableRow({ configuration }, [
1003
+ new DocTableCell({ configuration }, [
1004
+ new DocParagraph({ configuration }, [
1005
+ new DocPlainText({ configuration, text: apiParameter.name }),
1006
+ ]),
1007
+ ]),
1008
+ new DocTableCell({ configuration }, [
1009
+ this._createParagraphForTypeExcerpt(apiParameter.parameterTypeExcerpt),
1010
+ ]),
1011
+ new DocTableCell({ configuration }, parameterDescription.nodes),
1012
+ ])
1013
+ );
1014
+ }
1015
+
1016
+ if (parametersTable.rows.length > 0) {
1017
+ output.appendNode(
1018
+ new DocHeading({
1019
+ configuration: this._tsdocConfiguration,
1020
+ title: 'Parameters',
1021
+ })
1022
+ );
1023
+ output.appendNode(parametersTable);
1024
+ }
1025
+
1026
+ if (ApiReturnTypeMixin.isBaseClassOf(apiParameterListMixin)) {
1027
+ const returnTypeExcerpt: Excerpt = apiParameterListMixin.returnTypeExcerpt;
1028
+ output.appendNode(
1029
+ new DocParagraph({ configuration }, [
1030
+ new DocEmphasisSpan({ configuration, bold: true }, [
1031
+ new DocPlainText({ configuration, text: 'Returns:' }),
1032
+ ]),
1033
+ ])
1034
+ );
1035
+
1036
+ output.appendNode(this._createParagraphForTypeExcerpt(returnTypeExcerpt));
1037
+
1038
+ if (apiParameterListMixin instanceof ApiDocumentedItem) {
1039
+ if (apiParameterListMixin.tsdocComment && apiParameterListMixin.tsdocComment.returnsBlock) {
1040
+ this._appendSection(output, apiParameterListMixin.tsdocComment.returnsBlock.content);
1041
+ }
1042
+ }
1043
+ }
1044
+ }
1045
+
1046
+ private _createParagraphForTypeExcerpt(excerpt: Excerpt): DocParagraph {
1047
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
1048
+
1049
+ const paragraph: DocParagraph = new DocParagraph({ configuration });
1050
+ if (!excerpt.text.trim()) {
1051
+ paragraph.appendNode(new DocPlainText({ configuration, text: '(not declared)' }));
1052
+ } else {
1053
+ this._appendExcerptWithHyperlinks(paragraph, excerpt);
1054
+ }
1055
+
1056
+ return paragraph;
1057
+ }
1058
+
1059
+ private _appendExcerptWithHyperlinks(docNodeContainer: DocNodeContainer, excerpt: Excerpt): void {
1060
+ for (const token of excerpt.spannedTokens) {
1061
+ this._appendExcerptTokenWithHyperlinks(docNodeContainer, token);
1062
+ }
1063
+ }
1064
+
1065
+ private _appendExcerptTokenWithHyperlinks(
1066
+ docNodeContainer: DocNodeContainer,
1067
+ token: ExcerptToken
1068
+ ): void {
1069
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
1070
+
1071
+ // Markdown doesn't provide a standardized syntax for hyperlinks inside code
1072
+ // spans, so we will render the type expression as DocPlainText. Instead of
1073
+ // creating multiple DocParagraphs, we can simply discard any newlines and
1074
+ // let the renderer do normal word-wrapping.
1075
+ const unwrappedTokenText: string = token.text.replace(/[\r\n]+/g, ' ');
1076
+
1077
+ // If it's hyperlinkable, then append a DocLinkTag
1078
+ if (token.kind === ExcerptTokenKind.Reference && token.canonicalReference) {
1079
+ const apiItemResult: IResolveDeclarationReferenceResult =
1080
+ this._apiModel.resolveDeclarationReference(token.canonicalReference, undefined);
1081
+
1082
+ if (apiItemResult.resolvedApiItem) {
1083
+ docNodeContainer.appendNode(
1084
+ new DocLinkTag({
1085
+ configuration,
1086
+ tagName: '@link',
1087
+ linkText: unwrappedTokenText,
1088
+ urlDestination: this._getLinkFilenameForApiItem(apiItemResult.resolvedApiItem),
1089
+ })
1090
+ );
1091
+ return;
1092
+ }
1093
+ }
1094
+
1095
+ // Otherwise append non-hyperlinked text
1096
+ docNodeContainer.appendNode(new DocPlainText({ configuration, text: unwrappedTokenText }));
1097
+ }
1098
+
1099
+ private _createTitleCell(apiItem: ApiItem): DocTableCell {
1100
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
1101
+
1102
+ let linkText: string = Utilities.getConciseSignature(apiItem);
1103
+ if (ApiOptionalMixin.isBaseClassOf(apiItem) && apiItem.isOptional) {
1104
+ linkText += '?';
1105
+ }
1106
+
1107
+ return new DocTableCell({ configuration }, [
1108
+ new DocParagraph({ configuration }, [
1109
+ new DocLinkTag({
1110
+ configuration,
1111
+ tagName: '@link',
1112
+ linkText: linkText,
1113
+ urlDestination: this._getLinkFilenameForApiItem(apiItem),
1114
+ }),
1115
+ ]),
1116
+ ]);
1117
+ }
1118
+
1119
+ /**
1120
+ * This generates a DocTableCell for an ApiItem including the summary section
1121
+ * and "(BETA)" annotation.
1122
+ *
1123
+ * @remarks
1124
+ * We mostly assume that the input is an ApiDocumentedItem, but it's easier to
1125
+ * perform this as a runtime check than to have each caller perform a type
1126
+ * cast.
1127
+ */
1128
+ private _createDescriptionCell(apiItem: ApiItem): DocTableCell {
1129
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
1130
+
1131
+ const section: DocSection = new DocSection({ configuration });
1132
+
1133
+ if (ApiReleaseTagMixin.isBaseClassOf(apiItem)) {
1134
+ if (apiItem.releaseTag === ReleaseTag.Beta) {
1135
+ section.appendNodesInParagraph([
1136
+ new DocEmphasisSpan({ configuration, bold: true, italic: true }, [
1137
+ new DocPlainText({ configuration, text: '(BETA)' }),
1138
+ ]),
1139
+ new DocPlainText({ configuration, text: ' ' }),
1140
+ ]);
1141
+ }
1142
+ }
1143
+
1144
+ if (ApiOptionalMixin.isBaseClassOf(apiItem) && apiItem.isOptional) {
1145
+ section.appendNodesInParagraph([
1146
+ new DocEmphasisSpan({ configuration, italic: true }, [
1147
+ new DocPlainText({ configuration, text: '(Optional)' }),
1148
+ ]),
1149
+ new DocPlainText({ configuration, text: ' ' }),
1150
+ ]);
1151
+ }
1152
+
1153
+ if (apiItem instanceof ApiDocumentedItem) {
1154
+ if (apiItem.tsdocComment !== undefined) {
1155
+ this._appendAndMergeSection(section, apiItem.tsdocComment.summarySection);
1156
+ }
1157
+ }
1158
+
1159
+ return new DocTableCell({ configuration }, section.nodes);
1160
+ }
1161
+
1162
+ private _createModifiersCell(apiItem: ApiItem): DocTableCell {
1163
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
1164
+
1165
+ const section: DocSection = new DocSection({ configuration });
1166
+
1167
+ if (ApiProtectedMixin.isBaseClassOf(apiItem)) {
1168
+ if (apiItem.isProtected) {
1169
+ section.appendNode(
1170
+ new DocParagraph({ configuration }, [
1171
+ new DocCodeSpan({ configuration, code: 'protected' }),
1172
+ ])
1173
+ );
1174
+ }
1175
+ }
1176
+
1177
+ if (ApiReadonlyMixin.isBaseClassOf(apiItem)) {
1178
+ if (apiItem.isReadonly) {
1179
+ section.appendNode(
1180
+ new DocParagraph({ configuration }, [
1181
+ new DocCodeSpan({ configuration, code: 'readonly' }),
1182
+ ])
1183
+ );
1184
+ }
1185
+ }
1186
+
1187
+ if (ApiStaticMixin.isBaseClassOf(apiItem)) {
1188
+ if (apiItem.isStatic) {
1189
+ section.appendNode(
1190
+ new DocParagraph({ configuration }, [new DocCodeSpan({ configuration, code: 'static' })])
1191
+ );
1192
+ }
1193
+ }
1194
+
1195
+ return new DocTableCell({ configuration }, section.nodes);
1196
+ }
1197
+
1198
+ private _createPropertyTypeCell(apiItem: ApiItem): DocTableCell {
1199
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
1200
+
1201
+ const section: DocSection = new DocSection({ configuration });
1202
+
1203
+ if (apiItem instanceof ApiPropertyItem) {
1204
+ section.appendNode(this._createParagraphForTypeExcerpt(apiItem.propertyTypeExcerpt));
1205
+ }
1206
+
1207
+ return new DocTableCell({ configuration }, section.nodes);
1208
+ }
1209
+
1210
+ private _createInitializerCell(apiItem: ApiItem): DocTableCell {
1211
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
1212
+
1213
+ const section: DocSection = new DocSection({ configuration });
1214
+
1215
+ if (ApiInitializerMixin.isBaseClassOf(apiItem)) {
1216
+ if (apiItem.initializerExcerpt) {
1217
+ section.appendNodeInParagraph(
1218
+ new DocCodeSpan({
1219
+ configuration,
1220
+ code: apiItem.initializerExcerpt.text,
1221
+ })
1222
+ );
1223
+ }
1224
+ }
1225
+
1226
+ return new DocTableCell({ configuration }, section.nodes);
1227
+ }
1228
+
1229
+ private _writeBetaWarning(output: DocSection): void {
1230
+ const configuration: TSDocConfiguration = this._tsdocConfiguration;
1231
+ const betaWarning: string =
1232
+ 'This API is provided as a preview for developers and may change' +
1233
+ ' based on feedback that we receive. Do not use this API in a production environment.';
1234
+ output.appendNode(
1235
+ new DocNoteBox({ configuration }, [
1236
+ new DocParagraph({ configuration }, [
1237
+ new DocPlainText({ configuration, text: betaWarning }),
1238
+ ]),
1239
+ ])
1240
+ );
1241
+ }
1242
+
1243
+ private _appendSection(output: DocSection, docSection: DocSection): void {
1244
+ for (const node of docSection.nodes) {
1245
+ output.appendNode(node);
1246
+ }
1247
+ }
1248
+
1249
+ private _appendAndMergeSection(output: DocSection, docSection: DocSection): void {
1250
+ let firstNode = true;
1251
+ for (const node of docSection.nodes) {
1252
+ if (firstNode) {
1253
+ if (node.kind === DocNodeKind.Paragraph) {
1254
+ output.appendNodesInParagraph(node.getChildNodes());
1255
+ firstNode = false;
1256
+ continue;
1257
+ }
1258
+ }
1259
+ firstNode = false;
1260
+
1261
+ output.appendNode(node);
1262
+ }
1263
+ }
1264
+
1265
+ private _getSidebarLabelForApiItem(apiItem: ApiItem): string {
1266
+ if (apiItem.kind === ApiItemKind.Package) {
1267
+ return 'API';
1268
+ }
1269
+
1270
+ let baseName = '';
1271
+ for (const hierarchyItem of apiItem.getHierarchy()) {
1272
+ // For overloaded methods, add a suffix such as "MyClass.myMethod_2".
1273
+ let qualifiedName: string = hierarchyItem.displayName;
1274
+ if (ApiParameterListMixin.isBaseClassOf(hierarchyItem)) {
1275
+ if (hierarchyItem.overloadIndex > 1) {
1276
+ // Subtract one for compatibility with earlier releases of API Documenter.
1277
+ // (This will get revamped when we fix GitHub issue #1308)
1278
+ qualifiedName += `_${hierarchyItem.overloadIndex - 1}`;
1279
+ }
1280
+ }
1281
+
1282
+ switch (hierarchyItem.kind) {
1283
+ case ApiItemKind.Model:
1284
+ case ApiItemKind.EntryPoint:
1285
+ case ApiItemKind.EnumMember:
1286
+ case ApiItemKind.Package:
1287
+ break;
1288
+ default:
1289
+ baseName += qualifiedName + '.';
1290
+ }
1291
+ }
1292
+ return baseName.slice(0, baseName.length - 1);
1293
+ }
1294
+
1295
+ private _getFilenameForApiItem(apiItem: ApiItem): string {
1296
+ if (apiItem.kind === ApiItemKind.Package) {
1297
+ return 'index.md';
1298
+ }
1299
+
1300
+ let baseName = '';
1301
+ for (const hierarchyItem of apiItem.getHierarchy()) {
1302
+ // For overloaded methods, add a suffix such as "MyClass.myMethod_2".
1303
+ let qualifiedName: string = Utilities.getSafeFilenameForName(hierarchyItem.displayName);
1304
+ if (ApiParameterListMixin.isBaseClassOf(hierarchyItem)) {
1305
+ if (hierarchyItem.overloadIndex > 1) {
1306
+ // Subtract one for compatibility with earlier releases of API Documenter.
1307
+ // (This will get revamped when we fix GitHub issue #1308)
1308
+ qualifiedName += `_${hierarchyItem.overloadIndex - 1}`;
1309
+ }
1310
+ }
1311
+
1312
+ switch (hierarchyItem.kind) {
1313
+ case ApiItemKind.Model:
1314
+ case ApiItemKind.EntryPoint:
1315
+ case ApiItemKind.EnumMember:
1316
+ break;
1317
+ case ApiItemKind.Package:
1318
+ baseName = Utilities.getSafeFilenameForName(
1319
+ PackageName.getUnscopedName(hierarchyItem.displayName)
1320
+ );
1321
+ break;
1322
+ default:
1323
+ baseName += '.' + qualifiedName;
1324
+ }
1325
+ }
1326
+ return baseName + '.md';
1327
+ }
1328
+
1329
+ private _getLinkFilenameForApiItem(apiItem: ApiItem): string {
1330
+ return './' + this._getFilenameForApiItem(apiItem);
1331
+ }
1332
+
1333
+ private _deleteOldOutputFiles(): void {
1334
+ console.log('Deleting old output from ' + this._outputFolder);
1335
+ FileSystem.ensureEmptyFolder(this._outputFolder);
1336
+ }
1337
+ }