Skip to content

Commit f38f825

Browse files
committed
Define MarkdownDocumenterFeature.onBeforeWritePage() event
1 parent 7b560a2 commit f38f825

File tree

6 files changed

+98
-4
lines changed

6 files changed

+98
-4
lines changed

apps/api-documenter/src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
export { MarkdownDocumenterFeature } from './plugin/MarkdownDocumenterFeature';
5-
export { PluginFeature, PluginFeatureInitialization } from './plugin/PluginFeature';
64
export {
75
IFeatureDefinition,
86
IApiDocumenterPluginManifest
97
} from './plugin/IApiDocumenterPluginManifest';
8+
export {
9+
MarkdownDocumenterFeatureContext,
10+
IMarkdownDocumenterFeatureOnBeforeWritePage,
11+
MarkdownDocumenterFeature
12+
} from './plugin/MarkdownDocumenterFeature';
13+
export {
14+
PluginFeature,
15+
PluginFeatureContext,
16+
PluginFeatureInitialization
17+
} from './plugin/PluginFeature';

apps/api-documenter/src/plugin/MarkdownDocumenterFeature.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,37 @@
22
// See LICENSE in the project root for license information.
33

44
import { PluginFeature } from './PluginFeature';
5+
import { ApiItem } from '@microsoft/api-extractor-model';
6+
7+
/**
8+
* Context object for {@link MarkdownDocumenterFeature}.
9+
*
10+
* @public
11+
*/
12+
export class MarkdownDocumenterFeatureContext {
13+
14+
}
15+
16+
/**
17+
* Event arguments for MarkdownDocumenterFeature.onBeforeWritePage()
18+
* @public
19+
*/
20+
export interface IMarkdownDocumenterFeatureOnBeforeWritePage {
21+
/**
22+
* The API item corresponding to this page.
23+
*/
24+
apiItem: ApiItem;
25+
26+
/**
27+
* The page content. The onBeforeWritePage() handler can reassign this string to customize the page appearance.
28+
*/
29+
pageContent: string;
30+
31+
/**
32+
* The filename where the output will be written.
33+
*/
34+
outputFilename: string;
35+
}
536

637
/**
738
* Inherit from this base class to implement an API Documenter plugin feature that customizes
@@ -10,4 +41,13 @@ import { PluginFeature } from './PluginFeature';
1041
* @public
1142
*/
1243
export class MarkdownDocumenterFeature extends PluginFeature {
44+
public context: MarkdownDocumenterFeatureContext;
45+
46+
/**
47+
* This event function is called before writing a page.
48+
* @virtual
49+
*/
50+
public onBeforeWritePage(eventArgs: IMarkdownDocumenterFeatureOnBeforeWritePage): void {
51+
// (implemented by child class)
52+
}
1353
}

apps/api-documenter/src/plugin/PluginFeature.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,26 @@ export class PluginFeatureInitialization {
1414
public constructor() {
1515
// reserved for future use
1616
}
17+
18+
/** @internal */
19+
public _context: PluginFeatureContext;
20+
}
21+
22+
/**
23+
* Context object for {@link PluginFeature}.
24+
*
25+
* @public
26+
*/
27+
export class PluginFeatureContext {
1728
}
1829

1930
/**
2031
* The abstract base class for all API Documenter plugin features.
2132
* @public
2233
*/
2334
export abstract class PluginFeature {
35+
public context: PluginFeatureContext;
36+
2437
/**
2538
* The subclass should pass the `initialization` through to the base class.
2639
* Do not put custom initialization code in the constructor. Insteadm perform your initialization in the
@@ -29,6 +42,7 @@ export abstract class PluginFeature {
2942
*/
3043
public constructor(initialization: PluginFeatureInitialization) {
3144
// reserved for future expansion
45+
this.context = initialization._context;
3246
}
3347

3448
/**

apps/api-documenter/src/plugin/PluginLoader.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as resolve from 'resolve';
66

77
import { IConfigPlugin } from '../documenters/IConfigFile';
88
import { IApiDocumenterPluginManifest, IFeatureDefinition } from './IApiDocumenterPluginManifest';
9-
import { MarkdownDocumenterFeature } from './MarkdownDocumenterFeature';
9+
import { MarkdownDocumenterFeature, MarkdownDocumenterFeatureContext } from './MarkdownDocumenterFeature';
1010
import { PluginFeatureInitialization } from './PluginFeature';
1111

1212
interface ILoadedPlugin {
@@ -69,7 +69,11 @@ export class PluginLoader {
6969
throw new Error('A MarkdownDocumenterFeature is already loaded');
7070
}
7171

72+
const context: MarkdownDocumenterFeatureContext = new MarkdownDocumenterFeatureContext();
73+
7274
const initialization: PluginFeatureInitialization = new PluginFeatureInitialization();
75+
initialization._context = context;
76+
7377
let markdownDocumenterFeature: MarkdownDocumenterFeature | undefined = undefined;
7478
try {
7579
markdownDocumenterFeature = new featureDefinition.subclass(initialization);

apps/api-documenter/tslint.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"extends": "@microsoft/rush-stack-compiler-3.4/includes/tslint.json"
2+
"extends": "@microsoft/rush-stack-compiler-3.4/includes/tslint.json",
3+
"rules": {
4+
"member-ordering": false
5+
}
36
}

common/reviews/api/api-documenter.api.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
```ts
66

7+
import { ApiItem } from '@microsoft/api-extractor-model';
8+
79
// @public
810
export interface IApiDocumenterPluginManifest {
911
features: IFeatureDefinition[];
@@ -19,22 +21,45 @@ export interface IFeatureDefinition {
1921
};
2022
}
2123

24+
// @public
25+
export interface IMarkdownDocumenterFeatureOnBeforeWritePage {
26+
apiItem: ApiItem;
27+
outputFilename: string;
28+
pageContent: string;
29+
}
30+
2231
// @public
2332
export class MarkdownDocumenterFeature extends PluginFeature {
33+
// (undocumented)
34+
context: MarkdownDocumenterFeatureContext;
35+
// @virtual
36+
onBeforeWritePage(eventArgs: IMarkdownDocumenterFeatureOnBeforeWritePage): void;
37+
}
38+
39+
// @public
40+
export class MarkdownDocumenterFeatureContext {
2441
}
2542

2643
// @public
2744
export abstract class PluginFeature {
2845
// @internal
2946
constructor(initialization: PluginFeatureInitialization);
47+
// (undocumented)
48+
context: PluginFeatureContext;
3049
// @virtual
3150
onInitialized(): void;
3251
}
3352

53+
// @public
54+
export class PluginFeatureContext {
55+
}
56+
3457
// @public
3558
export class PluginFeatureInitialization {
3659
// @internal
3760
constructor();
61+
// @internal (undocumented)
62+
_context: PluginFeatureContext;
3863
}
3964

4065

0 commit comments

Comments
 (0)