forked from xAlien95/typedoc-plugin-shortcuts-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.ts
50 lines (42 loc) · 2.03 KB
/
plugin.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
45
46
47
48
49
50
import { Declaration, ParameterDeclaration } from 'typescript';
import { Component, ConverterComponent } from 'typedoc/dist/lib/converter/components';
import { Context } from 'typedoc/dist/lib/converter/context';
import { Converter } from 'typedoc/dist/lib/converter/converter';
import { Reflection } from 'typedoc/dist/lib/models/reflections/abstract';
import { ParameterReflection } from 'typedoc/dist/lib/models/reflections/parameter';
@Component({ name: 'shortcuts-js' })
export class ShortcutsJSPlugin extends ConverterComponent {
initialize() {
this.listenTo(this.owner, {
[Converter.EVENT_CREATE_PARAMETER]: this.onParameter,
[Converter.EVENT_CREATE_DECLARATION]: this.onDeclaration,
});
}
/**
* Triggered when the converter has created a parameter reflection.
*
* @param context The context object describing the current state the converter is in.
* @param parameter The parameter that is currently processed.
* @param node The node that is currently processed if available.
*/
private onParameter(context: Context, parameter: ParameterReflection, node?: ParameterDeclaration) {
// fixes https://github.com/TypeStrong/typedoc/issues/957
parameter.type = context.converter.convertType(context, node.type, context.getTypeAtLocation(node));
}
/**
* Triggered when the converter has created a declaration reflection.
*
* @param context The context object describing the current state the converter is in.
* @param reflection The reflection that is currently processed.
* @param node The node that is currently processed if available.
*/
private onDeclaration(_context: Context, reflection: Reflection, _node?: Declaration) {
if (!reflection.comment || !reflection.comment.hasTag('action')) return;
const last = reflection.comment.tags.pop();
const [content, shortText, ...text] = last.text.split('\n\n');
last.text = content;
reflection.comment.tags.push(last);
reflection.comment.shortText = shortText;
reflection.comment.text = text.join('\n\n');
}
};