Skip to content

Commit

Permalink
feat(prsr): react-native - parse short descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
artyorsh authored Apr 8, 2020
2 parents 944a92c + 2751645 commit b387386
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/reactNative.parser/parsers/examples.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,22 @@ export class ExamplesParser {
if (component[CO.tags] && component[CO.tags].length !== 0) {
return component[CO.tags]
.filter((tag: any) => tag[CO.tag] === targetTag)
.map((tag: any) => this.parseExample(tag))
.map((tag: any) => this.parseExampleText(tag[CO.text]))
.filter(Boolean);
} else {
return [];
}
}

private parseExample(example: any): Sample {
return new Sample({
code: this.getCode(example[CO.text]),
description: this.getDescription(example[CO.text]),
shortDescription: ''
});
}
private parseExampleText(text: string): Sample {
const [name, ...descriptionOrCode] = text.split('\n');
const description = this.parseDescription(descriptionOrCode.join('\n'));

private getCode(example: string): string {
const cutExample: string = example
.slice(example.indexOf('`') + 1, example.lastIndexOf('`'));
return '`' + cutExample + '`';
return new Sample({ description: name, ...description });
}

protected getDescription(example: string): string {
return example.split('\n')[0];
private parseDescription(example: string): any {
const [shortDescription, code] = example.split('```');
return { shortDescription, code };
}

}

0 comments on commit b387386

Please sign in to comment.