Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ migrate_working_dir/
.dart_tool/
.packages
build/
.flutter-plugins
.flutter-plugins-dependencies
38 changes: 23 additions & 15 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,23 @@ packages:
dependency: transitive
description:
name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.2"
version: "1.18.0"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
url: "https://pub.dev"
source: hosted
version: "2.0.3"
flutter_web_plugins:
dependency: transitive
description: flutter
Expand All @@ -34,22 +42,30 @@ packages:
relative: true
source: path
version: "3.0.2"
lints:
dependency: transitive
description:
name: lints
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.11.0"
plugin_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -135,14 +151,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
sdks:
dart: ">=3.1.3 <4.0.0"
dart: ">=3.2.0-0 <4.0.0"
flutter: ">=3.13.0"
4 changes: 4 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ dependencies:
linkable:
path: ..


dev_dependencies:
flutter_lints: ^2.0.0

flutter:
uses-material-design: true
27 changes: 19 additions & 8 deletions lib/http_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,27 @@ class HttpParser implements Parser {
HttpParser(this.text);

@override
parse() {
String pattern =
r"(http(s)?:\/\/)?(www.)?[a-zA-Z0-9]{2,256}\.[a-zA-Z0-9]{2,256}(\.[a-zA-Z0-9]{2,256})?([-a-zA-Z0-9@:%_\+~#?&//=.]*)([-a-zA-Z0-9@:%_\+~#?&//=]+)";
List<Link> parse() {
const pattern =
r'\b((www\.|https?://)[^\s]+)|([a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)+(:\d+)?(/[^\s]*)?)\b';

RegExp regExp = RegExp(pattern, caseSensitive: false);
final regExp = RegExp(pattern, caseSensitive: false);
final allMatches = regExp.allMatches(text);
final links = <Link>[];

Iterable<RegExpMatch> allMatches = regExp.allMatches(text);
List<Link> links = <Link>[];
for (RegExpMatch match in allMatches) {
links.add(Link(regExpMatch: match, type: http));
for (final match in allMatches) {
String urlString = match.group(0)!;

if (!urlString.startsWith('http://') &&
!urlString.startsWith('https://')) {
urlString = 'https://$urlString';
}

final uri = Uri.parse(urlString);

if ((uri.scheme == 'http' || uri.scheme == 'https') && uri.hasAuthority) {
links.add(Link(regExpMatch: match, type: http));
}
}
return links;
}
Expand Down
Loading