diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 510c1695..3c623f3b 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -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('&', '&') - .replaceAll('<', '<') - .replaceAll('>', '>') - .replaceAll('"', '"') - .replaceAll(''', "'") - .replaceAll(' ', ' '); + message = parse(message).body?.text ?? message; + // .replaceAll('&', '&') + // .replaceAll('<', '<') + // .replaceAll('>', '>') + // .replaceAll('"', '"') + // .replaceAll(''', "'") + // .replaceAll(' ', ' '); // 构建正则表达式 final List 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 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); } diff --git a/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart b/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart index 4b974239..38e33a5e 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item_grpc.dart @@ -19,6 +19,7 @@ import 'package:PiliPalaX/utils/storage.dart'; import 'package:PiliPalaX/utils/url_utils.dart'; import 'package:PiliPalaX/utils/utils.dart'; import '../../../../../utils/app_scheme.dart'; +import 'package:html/parser.dart' show parse; class ReplyItemGrpc extends StatelessWidget { const ReplyItemGrpc({ @@ -640,13 +641,13 @@ class ReplyItemGrpc extends StatelessWidget { }); message = message.replaceAll(RegExp(r"\{vote:\d+?\}"), ""); } - message = message - .replaceAll('&', '&') - .replaceAll('<', '<') - .replaceAll('>', '>') - .replaceAll('"', '"') - .replaceAll(''', "'") - .replaceAll(' ', ' '); + message = parse(message).body?.text ?? message; + // .replaceAll('&', '&') + // .replaceAll('<', '<') + // .replaceAll('>', '>') + // .replaceAll('"', '"') + // .replaceAll(''', "'") + // .replaceAll(' ', ' '); // 构建正则表达式 final List specialTokens = [ ...content.emote.keys, @@ -666,7 +667,7 @@ class ReplyItemGrpc extends StatelessWidget { if (jumpUrlKeysList.isNotEmpty) { patternStr += '|${jumpUrlKeysList.map(RegExp.escape).join('|')}'; } - patternStr += r'|https://b23\.tv/[a-zA-Z0-9]{7}'; + patternStr += r'|https?://\S+\b'; final RegExp pattern = RegExp(patternStr); List matchedStrs = []; void addPlainTextSpan(str) { @@ -908,7 +909,7 @@ class ReplyItemGrpc extends StatelessWidget { }, ), ); - } else if (matchStr.startsWith('https://b23.tv/')) { + } else if (RegExp(r'https?://\S+\b').hasMatch(matchStr)) { spanChildren.add( TextSpan( text: ' $matchStr ',