opt: reply item

Closes #95

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-01-04 16:51:07 +08:00
parent 8186307f98
commit 76b37437d3
2 changed files with 33 additions and 16 deletions

View File

@@ -19,6 +19,7 @@ import 'package:PiliPalaX/utils/url_utils.dart';
import 'package:PiliPalaX/utils/utils.dart';
import '../../../../../utils/app_scheme.dart';
import 'zan.dart';
import 'package:html/parser.dart' show parse;
class ReplyItem extends StatelessWidget {
const ReplyItem({
@@ -614,13 +615,13 @@ class ReplyItem extends StatelessWidget {
});
message = message.replaceAll(RegExp(r"\{vote:\d+?\}"), "");
}
message = message
.replaceAll('&amp;', '&')
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>')
.replaceAll('&quot;', '"')
.replaceAll('&apos;', "'")
.replaceAll('&nbsp;', ' ');
message = parse(message).body?.text ?? message;
// .replaceAll('&amp;', '&')
// .replaceAll('&lt;', '<')
// .replaceAll('&gt;', '>')
// .replaceAll('&quot;', '"')
// .replaceAll('&apos;', "'")
// .replaceAll('&nbsp;', ' ');
// 构建正则表达式
final List<String> specialTokens = [
...content.emote.keys,
@@ -640,6 +641,7 @@ class ReplyItem extends StatelessWidget {
if (jumpUrlKeysList.isNotEmpty) {
patternStr += '|${jumpUrlKeysList.map(RegExp.escape).join('|')}';
}
patternStr += r'|https?://\S+\b';
final RegExp pattern = RegExp(patternStr);
List<String> matchedStrs = [];
void addPlainTextSpan(str) {
@@ -882,6 +884,20 @@ class ReplyItem extends StatelessWidget {
},
),
);
} else if (RegExp(r'https?://\S+\b').hasMatch(matchStr)) {
spanChildren.add(
TextSpan(
text: ' $matchStr ',
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
),
recognizer: TapGestureRecognizer()
..onTap = () => Get.toNamed(
'/webview',
parameters: {'url': matchStr},
),
),
);
} else {
addPlainTextSpan(matchStr);
}