@@ -7,29 +7,22 @@ export class ExamplesParser {
7
7
if ( component [ CO . tags ] && component [ CO . tags ] . length !== 0 ) {
8
8
return component [ CO . tags ]
9
9
. filter ( ( tag : any ) => tag [ CO . tag ] === targetTag )
10
- . map ( ( tag : any ) => this . parseExample ( tag ) )
10
+ . map ( ( tag : any ) => this . parseExampleText ( tag [ CO . text ] ) )
11
11
. filter ( Boolean ) ;
12
12
} else {
13
13
return [ ] ;
14
14
}
15
15
}
16
16
17
- private parseExample ( example : any ) : Sample {
18
- return new Sample ( {
19
- code : this . getCode ( example [ CO . text ] ) ,
20
- description : this . getDescription ( example [ CO . text ] ) ,
21
- shortDescription : ''
22
- } ) ;
23
- }
17
+ private parseExampleText ( text : string ) : Sample {
18
+ const [ name , ...descriptionOrCode ] = text . split ( '\n' ) ;
19
+ const description = this . parseDescription ( descriptionOrCode . join ( '\n' ) ) ;
24
20
25
- private getCode ( example : string ) : string {
26
- const cutExample : string = example
27
- . slice ( example . indexOf ( '`' ) + 1 , example . lastIndexOf ( '`' ) ) ;
28
- return '`' + cutExample + '`' ;
21
+ return new Sample ( { description : name , ...description } ) ;
29
22
}
30
23
31
- protected getDescription ( example : string ) : string {
32
- return example . split ( '\n' ) [ 0 ] ;
24
+ private parseDescription ( example : string ) : any {
25
+ const [ shortDescription , code ] = example . split ( '```' ) ;
26
+ return { shortDescription, code } ;
33
27
}
34
-
35
28
}
0 commit comments