fix: 评论区@跟jumpUrl共存时链接解析 issues #404

This commit is contained in:
guozhigq
2024-01-10 23:58:14 +08:00
parent 5fa32f1e2b
commit 2dc7cf28c9
2 changed files with 11 additions and 5 deletions

View File

@ -552,7 +552,7 @@ InlineSpan buildContent(
);
}
final List<InlineSpan> spanChilds = <InlineSpan>[];
bool hasMatchMember = true;
bool hasMatchMember = false;
// 投票
if (content.vote.isNotEmpty) {
@ -643,7 +643,7 @@ InlineSpan buildContent(
reg,
onMatch: (Match match) {
if (match[0] != null) {
hasMatchMember = false;
hasMatchMember = true;
content.atNameToMid.forEach((key, value) {
if (str.contains('回复')) {
spanChilds.add(
@ -682,6 +682,7 @@ InlineSpan buildContent(
if (!str.contains('@')) {
spanChilds.add(TextSpan(text: str));
}
print(str);
return str;
},
);
@ -691,7 +692,7 @@ InlineSpan buildContent(
// 匹配 jumpUrl
String matchUrl = matchMember;
if (content.jumpUrl.isNotEmpty && hasMatchMember) {
if (content.jumpUrl.isNotEmpty) {
final List urlKeys = content.jumpUrl.keys.toList().reversed.toList();
for (int index = 0; index < urlKeys.length; index++) {
var i = urlKeys[index];
@ -705,6 +706,11 @@ InlineSpan buildContent(
urlKeys[index] = i.replaceAll('*', '\\*');
}
}
if (hasMatchMember) {
matchMember = matchMember.split('回复 @ :').length > 1
? matchMember.split('回复 @ :')[1]
: matchMember;
}
matchUrl = matchMember.splitMapJoin(
/// RegExp.escape() 转义特殊字符
RegExp(urlKeys.map((key) => key).join("|")),