-
Notifications
You must be signed in to change notification settings - Fork 172
/
index.ts
44 lines (40 loc) · 1.56 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Application, DeclarationOption, RendererEvent } from 'typedoc';
import { MarkdownPageEvent } from 'typedoc-plugin-markdown';
import * as options from './options/declarations';
import { addTableOfContents } from './options/helpers';
export function load(app: Application) {
Object.entries(options).forEach(([name, option]) => {
app.options.addDeclaration({
name,
...option,
} as DeclarationOption);
});
app.renderer.on(MarkdownPageEvent.END, (event: MarkdownPageEvent) => {
const remarkPlugins = app.options.getValue('remarkPlugins') as [];
const remarkPluginsNames = remarkPlugins.map((plugin) =>
Array.isArray(plugin) ? plugin[0] : plugin,
) as string[];
if (remarkPluginsNames.includes('remark-toc')) {
addTableOfContents(event, remarkPlugins, remarkPluginsNames, app);
}
});
app.renderer.postRenderAsyncJobs.push(async (output: RendererEvent) => {
const remarkPlugins = app.options.getValue('remarkPlugins') as any;
if (output.urls?.length) {
await Promise.all(
output.urls?.map(async (urlMapping) => {
const { parseContents } = await require('./remark.cjs');
const filePath = `${output.outputDirectory}/${urlMapping.url}`;
return await parseContents(filePath, remarkPlugins);
}),
);
if (remarkPlugins.length) {
app.logger.info(
`Output parsed using remark plugin(s) [${remarkPlugins
.map((plugin) => `"${Array.isArray(plugin) ? plugin[0] : plugin}"`)
.join(', ')}]`,
);
}
}
});
}