Skip to content
This repository has been archived by the owner on Oct 22, 2022. It is now read-only.

Commit

Permalink
feat: add description HTML field, remove anchor tag of description
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Mar 6, 2019
1 parent 2ac0ab0 commit 922ecb1
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/src/github_trending_base.dart
Expand Up @@ -11,6 +11,7 @@ class TrendingRepository {
String owner;
String name;
String description;
String descriptionHTML;
int starCount;
int forkCount;
TrendingRepositoryPrimaryLanguage primaryLanguage;
Expand All @@ -19,6 +20,7 @@ class TrendingRepository {
this.owner,
this.name,
this.description,
this.descriptionHTML,
this.starCount,
this.forkCount,
this.primaryLanguage,
Expand Down Expand Up @@ -78,6 +80,19 @@ Future<List<TrendingRepository>> getTrendingRepositories({
?.trim();
var forkCount = forkCountStr == null ? null : int.tryParse(forkCountStr);

String description;
String descriptionHTML;
var descriptionRawHtml =
item.children[2].querySelector('p')?.innerHtml?.trim();
if (descriptionRawHtml != null) {
description = descriptionRawHtml
?.replaceAll(RegExp(r'<g-emoji.*?>'), '')
?.replaceAll(RegExp(r'</g-emoji>'), '')
?.replaceAll(RegExp(r'<a.*?>'), '')
?.replaceAll(RegExp(r'</a>'), '');
descriptionHTML = '<div>$descriptionRawHtml</div>';
}

return TrendingRepository(
owner: item
.querySelector('h3>a>span')
Expand All @@ -89,12 +104,8 @@ Future<List<TrendingRepository>> getTrendingRepositories({
?.innerHtml
?.replaceFirst(RegExp(r'^[\s\S]*span>'), '')
?.trim(),
description: item.children[2]
.querySelector('p')
?.innerHtml
?.trim()
?.replaceAll(RegExp(r'<g-emoji.*?>'), '') // TODO: emoji
?.replaceAll(RegExp(r'</g-emoji>'), ''),
description: description,
descriptionHTML: descriptionHTML,
starCount: starCount,
forkCount: forkCount,
primaryLanguage: primaryLanguage,
Expand Down

0 comments on commit 922ecb1

Please sign in to comment.