From db30ffcd17ba82779b905c00286d93d3c4721ff0 Mon Sep 17 00:00:00 2001 From: Desson Chan <16623125+dessonchan@users.noreply.github.com> Date: Thu, 1 Jun 2023 15:53:37 +0800 Subject: [PATCH] - always provide origin text to LinkableElement --- lib/src/email.dart | 3 ++- lib/src/phone_number.dart | 6 ++++-- lib/src/user_tag.dart | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/src/email.dart b/lib/src/email.dart index 9471320..e74e7b5 100644 --- a/lib/src/email.dart +++ b/lib/src/email.dart @@ -30,6 +30,7 @@ class EmailLinkifier extends Linkifier { // Always humanize emails list.add(EmailElement( match.group(2)!.replaceFirst(RegExp(r'mailto:'), ''), + match.group(2) )); } @@ -50,7 +51,7 @@ class EmailLinkifier extends Linkifier { class EmailElement extends LinkableElement { final String emailAddress; - EmailElement(this.emailAddress) : super(emailAddress, 'mailto:$emailAddress'); + EmailElement(this.emailAddress, String? originText) : super(emailAddress, 'mailto:$emailAddress', originText); @override String toString() { diff --git a/lib/src/phone_number.dart b/lib/src/phone_number.dart index 37c2243..9aff254 100644 --- a/lib/src/phone_number.dart +++ b/lib/src/phone_number.dart @@ -28,7 +28,8 @@ class PhoneNumberLinkifier extends Linkifier { if (match.group(2)?.isNotEmpty == true) { list.add(PhoneNumberElement( - match.group(2)!.replaceFirst(RegExp(r'tel:'), ''), + match.group(2)!.replaceFirst(RegExp(r'tel:'), ''), + match.group(2) )); } @@ -49,10 +50,11 @@ class PhoneNumberLinkifier extends Linkifier { class PhoneNumberElement extends LinkableElement { final String phoneNumber; - PhoneNumberElement(this.phoneNumber) + PhoneNumberElement(this.phoneNumber, String? originText) : super( phoneNumber, 'tel:$phoneNumber', + originText, ); @override diff --git a/lib/src/user_tag.dart b/lib/src/user_tag.dart index 75ab314..4629322 100644 --- a/lib/src/user_tag.dart +++ b/lib/src/user_tag.dart @@ -40,7 +40,7 @@ class UserTagLinkifier extends Linkifier { } if (match?.group(2)?.isNotEmpty == true) { - list.add(UserTagElement('@${match!.group(2)!}')); + list.add(UserTagElement('@${match!.group(2)!}', match!.group(2))); } if (text.isNotEmpty) { @@ -60,7 +60,7 @@ class UserTagLinkifier extends Linkifier { class UserTagElement extends LinkableElement { final String userTag; - UserTagElement(this.userTag) : super(userTag, userTag); + UserTagElement(this.userTag, String? originText) : super(userTag, userTag, originText); @override String toString() {