Skip to content

Commit b387386

Browse files
authored
feat(prsr): react-native - parse short descriptions
2 parents 944a92c + 2751645 commit b387386

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/reactNative.parser/parsers/examples.parser.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,22 @@ export class ExamplesParser {
77
if (component[CO.tags] && component[CO.tags].length !== 0) {
88
return component[CO.tags]
99
.filter((tag: any) => tag[CO.tag] === targetTag)
10-
.map((tag: any) => this.parseExample(tag))
10+
.map((tag: any) => this.parseExampleText(tag[CO.text]))
1111
.filter(Boolean);
1212
} else {
1313
return [];
1414
}
1515
}
1616

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'));
2420

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 });
2922
}
3023

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 };
3327
}
34-
3528
}

0 commit comments

Comments
 (0)