Skip to content

Commit cc3a1a0

Browse files
author
Alexander Gräfenstein
committed
render remarks at page start for class, interface, package and namespace
1 parent c998284 commit cc3a1a0

2 files changed

Lines changed: 48 additions & 31 deletions

File tree

apps/api-documenter/src/documenters/MarkdownDocumenter.ts

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,17 @@ export class MarkdownDocumenter {
207207
}
208208
}
209209

210+
let appendRemarks: boolean = true;
211+
switch (apiItem.kind) {
212+
case ApiItemKind.Class:
213+
case ApiItemKind.Interface:
214+
case ApiItemKind.Namespace:
215+
case ApiItemKind.Package:
216+
this._writeRemarksSection(output, apiItem);
217+
appendRemarks = false;
218+
break;
219+
}
220+
210221
switch (apiItem.kind) {
211222
case ApiItemKind.Class:
212223
this._writeClassTables(output, apiItem as ApiClass);
@@ -244,31 +255,8 @@ export class MarkdownDocumenter {
244255
throw new Error('Unsupported API item kind: ' + apiItem.kind);
245256
}
246257

247-
if (apiItem instanceof ApiDocumentedItem) {
248-
const tsdocComment: DocComment | undefined = apiItem.tsdocComment;
249-
250-
if (tsdocComment) {
251-
// Write the @remarks block
252-
if (tsdocComment.remarksBlock) {
253-
output.appendNode(new DocHeading({ configuration: this._tsdocConfiguration, title: 'Remarks' }));
254-
this._appendSection(output, tsdocComment.remarksBlock.content);
255-
}
256-
257-
// Write the @example blocks
258-
const exampleBlocks: DocBlock[] = tsdocComment.customBlocks.filter(x => x.blockTag.tagNameWithUpperCase
259-
=== StandardTags.example.tagNameWithUpperCase);
260-
261-
let exampleNumber: number = 1;
262-
for (const exampleBlock of exampleBlocks) {
263-
const heading: string = exampleBlocks.length > 1 ? `Example ${exampleNumber}` : 'Example';
264-
265-
output.appendNode(new DocHeading({ configuration: this._tsdocConfiguration, title: heading }));
266-
267-
this._appendSection(output, exampleBlock.content);
268-
269-
++exampleNumber;
270-
}
271-
}
258+
if (appendRemarks) {
259+
this._writeRemarksSection(output, apiItem);
272260
}
273261

274262
const filename: string = path.join(this._outputFolder, this._getFilenameForApiItem(apiItem));
@@ -301,6 +289,35 @@ export class MarkdownDocumenter {
301289
});
302290
}
303291

292+
private _writeRemarksSection(output: DocSection, apiItem: ApiItem): void {
293+
if (apiItem instanceof ApiDocumentedItem) {
294+
const tsdocComment: DocComment | undefined = apiItem.tsdocComment;
295+
296+
if (tsdocComment) {
297+
// Write the @remarks block
298+
if (tsdocComment.remarksBlock) {
299+
output.appendNode(new DocHeading({ configuration: this._tsdocConfiguration, title: 'Remarks' }));
300+
this._appendSection(output, tsdocComment.remarksBlock.content);
301+
}
302+
303+
// Write the @example blocks
304+
const exampleBlocks: DocBlock[] = tsdocComment.customBlocks.filter(x => x.blockTag.tagNameWithUpperCase
305+
=== StandardTags.example.tagNameWithUpperCase);
306+
307+
let exampleNumber: number = 1;
308+
for (const exampleBlock of exampleBlocks) {
309+
const heading: string = exampleBlocks.length > 1 ? `Example ${exampleNumber}` : 'Example';
310+
311+
output.appendNode(new DocHeading({ configuration: this._tsdocConfiguration, title: heading }));
312+
313+
this._appendSection(output, exampleBlock.content);
314+
315+
++exampleNumber;
316+
}
317+
}
318+
}
319+
}
320+
304321
/**
305322
* GENERATE PAGE: MODEL
306323
*/

build-tests/api-documenter-test/etc/markdown/api-documenter-test.docclass1.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ This is an example class.
1212
export declare class DocClass1 extends DocBaseClass implements IDocInterface1, IDocInterface2
1313
```
1414
15+
## Remarks
16+
17+
These are some remarks.
18+
19+
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `DocClass1` class.
20+
1521
## Events
1622
1723
| Property | Modifiers | Type | Description |
@@ -36,9 +42,3 @@ export declare class DocClass1 extends DocBaseClass implements IDocInterface1, I
3642
| [sumWithExample(x, y)](./api-documenter-test.docclass1.sumwithexample.md) | <code>static</code> | Returns the sum of two numbers. |
3743
| [tableExample()](./api-documenter-test.docclass1.tableexample.md) | | An example with tables: |
3844
39-
## Remarks
40-
41-
These are some remarks.
42-
43-
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `DocClass1` class.
44-

0 commit comments

Comments
 (0)