@@ -10,6 +10,10 @@ import { Formatter } from './formatter';
10
10
*/
11
11
export class DocGen {
12
12
13
+ public customConfiguration = new TSDocConfiguration ( ) ;
14
+
15
+ public tsdocParser : TSDocParser ;
16
+
13
17
/**
14
18
* TSDoc tag definition for demo blocks.
15
19
* This custom block tag allows marking code sections as demos in the documentation.
@@ -19,6 +23,13 @@ export class DocGen {
19
23
syntaxKind : TSDocTagSyntaxKind . BlockTag
20
24
} ) ;
21
25
26
+ constructor ( ) {
27
+ this . customConfiguration . addTagDefinitions ( [
28
+ DocGen . CUSTOM_BLOCK_DEFINITION_DEMO
29
+ ] ) ;
30
+ this . tsdocParser = new TSDocParser ( this . customConfiguration ) ;
31
+ }
32
+
22
33
/**
23
34
* Parses a TypeScript source file to extract its documentation.
24
35
*
@@ -28,15 +39,17 @@ export class DocGen {
28
39
async parseDoc ( doc : string ) : Promise < ParserContext > {
29
40
const inputFilename : string = path . resolve ( doc ) ;
30
41
const inputBuffer : string = await readFile ( inputFilename , 'utf-8' ) ;
31
-
32
- const customConfiguration : TSDocConfiguration = new TSDocConfiguration ( ) ;
33
-
34
- customConfiguration . addTagDefinitions ( [
35
- DocGen . CUSTOM_BLOCK_DEFINITION_DEMO
36
- ] ) ;
37
-
38
- const tsdocParser : TSDocParser = new TSDocParser ( customConfiguration ) ;
39
- const parserContext : ParserContext = tsdocParser . parseString ( inputBuffer ) ;
42
+ return this . parseString ( inputBuffer ) ;
43
+ }
44
+
45
+ /**
46
+ * Parses a TypeScript source file to extract its documentation.
47
+ *
48
+ * @param sourceCode - The path to the TypeScript source file to parse
49
+ * @returns A Promise that resolves to a ParserContext containing the parsed documentation
50
+ */
51
+ private parseString ( sourceCode : string ) : ParserContext {
52
+ const parserContext : ParserContext = this . tsdocParser . parseString ( sourceCode ) ;
40
53
return parserContext ;
41
54
}
42
55
0 commit comments