Skip to content

Commit cb60799

Browse files
author
Sebastian Schürmann
committed
refactor(vanillin): added simple parse String mthod
1 parent ffeca55 commit cb60799

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

packages/vanillin/src/doc-gen.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { Formatter } from './formatter';
1010
*/
1111
export class DocGen {
1212

13+
public customConfiguration = new TSDocConfiguration();
14+
15+
public tsdocParser: TSDocParser;
16+
1317
/**
1418
* TSDoc tag definition for demo blocks.
1519
* This custom block tag allows marking code sections as demos in the documentation.
@@ -19,6 +23,13 @@ export class DocGen {
1923
syntaxKind: TSDocTagSyntaxKind.BlockTag
2024
});
2125

26+
constructor() {
27+
this.customConfiguration.addTagDefinitions([
28+
DocGen.CUSTOM_BLOCK_DEFINITION_DEMO
29+
]);
30+
this.tsdocParser = new TSDocParser(this.customConfiguration);
31+
}
32+
2233
/**
2334
* Parses a TypeScript source file to extract its documentation.
2435
*
@@ -28,15 +39,17 @@ export class DocGen {
2839
async parseDoc(doc: string): Promise<ParserContext> {
2940
const inputFilename: string = path.resolve(doc);
3041
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);
4053
return parserContext;
4154
}
4255

0 commit comments

Comments
 (0)