fix: 带问号的评论内容匹配

This commit is contained in:
guozhigq
2023-10-22 14:11:43 +08:00
parent 9fd5193259
commit 48030d5ee7

View File

@ -669,58 +669,70 @@ InlineSpan buildContent(
String matchUrl = matchMember; String matchUrl = matchMember;
if (content.jumpUrl.isNotEmpty && hasMatchMember) { if (content.jumpUrl.isNotEmpty && hasMatchMember) {
List urlKeys = content.jumpUrl.keys.toList().reversed.toList(); List urlKeys = content.jumpUrl.keys.toList().reversed.toList();
for (var index = 0; index < urlKeys.length; index++) {
var i = urlKeys[index];
if (i.contains('?')) {
urlKeys[index] = i.replaceAll('?', '\\?');
}
}
matchUrl = matchMember.splitMapJoin( matchUrl = matchMember.splitMapJoin(
/// RegExp.escape() 转义特殊字符 /// RegExp.escape() 转义特殊字符
RegExp(urlKeys.map((key) => key).join("|")), RegExp(urlKeys.map((key) => key).join("|")),
// RegExp(RegExp.escape(urlKeys.join("|"))), // RegExp('What does the fox say\\?'),
onMatch: (Match match) { onMatch: (Match match) {
String matchStr = match[0]!; String matchStr = match[0]!;
String appUrlSchema = content.jumpUrl[matchStr]['app_url_schema']; String appUrlSchema = '';
if (content.jumpUrl[matchStr] != null) {
appUrlSchema = content.jumpUrl[matchStr]['app_url_schema'];
}
// 默认不显示关键词 // 默认不显示关键词
bool enableWordRe = bool enableWordRe =
setting.get(SettingBoxKey.enableWordRe, defaultValue: false); setting.get(SettingBoxKey.enableWordRe, defaultValue: false);
spanChilds.add( if (content.jumpUrl[matchStr] != null) {
TextSpan( spanChilds.add(
text: content.jumpUrl[matchStr]['title'], TextSpan(
style: TextStyle( text: content.jumpUrl[matchStr]['title'],
color: enableWordRe style: TextStyle(
? Theme.of(context).colorScheme.primary color: enableWordRe
: null, ? Theme.of(context).colorScheme.primary
), : null,
recognizer: TapGestureRecognizer() ),
..onTap = () { recognizer: TapGestureRecognizer()
if (appUrlSchema == '') { ..onTap = () {
String str = Uri.parse(matchStr).pathSegments[0]; if (appUrlSchema == '') {
Map matchRes = IdUtils.matchAvorBv(input: str); String str = Uri.parse(matchStr).pathSegments[0];
List matchKeys = matchRes.keys.toList(); Map matchRes = IdUtils.matchAvorBv(input: str);
if (matchKeys.isNotEmpty) { List matchKeys = matchRes.keys.toList();
if (matchKeys.first == 'BV') { if (matchKeys.isNotEmpty) {
if (matchKeys.first == 'BV') {
Get.toNamed(
'/searchResult',
parameters: {'keyword': matchRes['BV']},
);
}
} else {
Get.toNamed( Get.toNamed(
'/searchResult', '/webview',
parameters: {'keyword': matchRes['BV']}, parameters: {
'url': matchStr,
'type': 'url',
'pageTitle': ''
},
); );
} }
} else { } else {
Get.toNamed( if (appUrlSchema.startsWith('bilibili://search') &&
'/webview', enableWordRe) {
parameters: { Get.toNamed('/searchResult', parameters: {
'url': matchStr, 'keyword': content.jumpUrl[matchStr]['title']
'type': 'url', });
'pageTitle': '' }
},
);
} }
} else { },
if (appUrlSchema.startsWith('bilibili://search') && ),
enableWordRe) { );
Get.toNamed('/searchResult', parameters: { }
'keyword': content.jumpUrl[matchStr]['title']
});
}
}
},
),
);
if (appUrlSchema.startsWith('bilibili://search') && enableWordRe) { if (appUrlSchema.startsWith('bilibili://search') && enableWordRe) {
spanChilds.add( spanChilds.add(
WidgetSpan( WidgetSpan(