diff --git a/core/lib/presentation/utils/html_transformer/text/convert_url_string_to_html_links_transformers.dart b/core/lib/presentation/utils/html_transformer/text/convert_url_string_to_html_links_transformers.dart
index 96d7c6bcd..5f9f3d0cb 100644
--- a/core/lib/presentation/utils/html_transformer/text/convert_url_string_to_html_links_transformers.dart
+++ b/core/lib/presentation/utils/html_transformer/text/convert_url_string_to_html_links_transformers.dart
@@ -1,6 +1,5 @@
import 'package:core/presentation/utils/html_transformer/base/text_transformer.dart';
-import 'package:core/utils/app_logger.dart';
import 'package:core/utils/linkify_html.dart';
class ConvertUrlStringToHtmlLinksTransformers extends TextTransformer {
@@ -9,9 +8,7 @@ class ConvertUrlStringToHtmlLinksTransformers extends TextTransformer {
@override
String process(String text) {
- log('ConvertUrlStringToHtmlLinksTransformers::process(): BEFORE: $text');
final texValid = LinkifyHtml().generateLinkify(text);
- log('ConvertUrlStringToHtmlLinksTransformers::process(): AFTER: $texValid');
return texValid;
}
}
\ No newline at end of file
diff --git a/core/lib/utils/linkify_html.dart b/core/lib/utils/linkify_html.dart
index 9c5a56988..b0653417a 100644
--- a/core/lib/utils/linkify_html.dart
+++ b/core/lib/utils/linkify_html.dart
@@ -1,5 +1,4 @@
-import 'package:collection/collection.dart';
import 'package:core/utils/app_logger.dart';
class LinkifyHtml {
@@ -20,38 +19,29 @@ class LinkifyHtml {
// URLs starting with http://, https://, ftp://
final regexLinkWithHttp = _generateRegExp(r'(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])');
-
- final listUrlMatch = regexLinkWithHttp.allMatches(replacedText)
- .map((regexMatch) => regexMatch.group(1))
- .whereNotNull()
- .toSet();
-
- log('ConvertUrlStringToHtmlLinksTransformers::_linkifyUrlAddress(): listUrlMatch: $listUrlMatch');
-
- if (listUrlMatch.isNotEmpty) {
- listUrlMatch.forEach((link) {
- replacedText = replacedText.replaceAll(
- link,
- '$link');
- });
- }
+ final newReplacedTextWithHttp = replacedText.replaceAllMapped(regexLinkWithHttp, (regexMatch) {
+ final link = regexMatch.group(1);
+ final newLinkWithHttp = link?.isNotEmpty == true
+ ? '$link'
+ : '';
+ log('ConvertUrlStringToHtmlLinksTransformers::_linkifyUrlAddress(): newLinkWithHttp: $newLinkWithHttp');
+ return newLinkWithHttp;
+ });
+ replacedText = newReplacedTextWithHttp;
// URLs starting with "www." without // before it or it'd re-link the ones done above.
final regexLinkWithWWW = _generateRegExp(r'(^|[^\/])(www\.[\S]+(\b|\$))');
-
- final listLinkMatch = regexLinkWithWWW.allMatches(replacedText)
- .map((regexMatch) => regexMatch.group(2))
- .whereNotNull()
- .toSet();
- log('ConvertUrlStringToHtmlLinksTransformers::_linkifyUrlAddress(): listLinkMatch: $listLinkMatch');
-
- if (listLinkMatch.isNotEmpty) {
- listLinkMatch.forEach((link) {
- replacedText = replacedText.replaceAll(
- link,
- '$link');
- });
- }
+ final newReplacedTextWithWWW = replacedText.replaceAllMapped(regexLinkWithWWW, (regexMatch) {
+ final previousChar = regexMatch.group(1);
+ log('LinkifyHtml::_linkifyUrlAddress(): previousChar: $previousChar');
+ final link = regexMatch.group(2);
+ final newLinkWithWWW = link?.isNotEmpty == true
+ ? '$previousChar$link'
+ : '';
+ log('ConvertUrlStringToHtmlLinksTransformers::_linkifyUrlAddress(): newLinkWithWWW: $newLinkWithWWW');
+ return newLinkWithWWW;
+ });
+ replacedText = newReplacedTextWithWWW;
return replacedText;
}
@@ -60,20 +50,15 @@ class LinkifyHtml {
String _linkifyMailToAddress(String inputText) {
final regexMailTo = _generateRegExp(r'(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)');
- final listEmailAddressMatch = regexMailTo.allMatches(inputText)
- .map((regexMatch) => regexMatch.group(1))
- .whereNotNull()
- .toSet();
+ final newReplacedTextWitMailTo = inputText.replaceAllMapped(regexMailTo, (regexMatch) {
+ final emailAddress = regexMatch.group(1);
+ final newMailToLink = emailAddress?.isNotEmpty == true
+ ? '$emailAddress'
+ : '';
+ log('ConvertUrlStringToHtmlLinksTransformers::_linkifyUrlAddress(): newMailToLink: $newMailToLink');
+ return newMailToLink;
+ });
- log('ConvertUrlStringToHtmlLinksTransformers::generateLinkifyHtml(): listEmailAddressMatch: $listEmailAddressMatch');
-
- if (listEmailAddressMatch.isNotEmpty) {
- listEmailAddressMatch.forEach((emailAddress) {
- inputText = inputText.replaceAll(
- emailAddress,
- '$emailAddress');
- });
- }
- return inputText;
+ return newReplacedTextWitMailTo;
}
}
\ No newline at end of file