mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-04 00:00:14 +08:00
@@ -5,8 +5,26 @@ abstract final class Em {
|
||||
);
|
||||
|
||||
static String regCate(String origin) {
|
||||
Iterable<Match> matches = _exp.allMatches(origin);
|
||||
return matches.lastOrNull?.group(1) ?? origin;
|
||||
final matches = _exp.firstMatch(origin);
|
||||
return matches?.group(1) ?? origin;
|
||||
}
|
||||
|
||||
static String parseHtml(String str) {
|
||||
return str.replaceAllMapped(
|
||||
_htmlRegExp,
|
||||
(match) => switch (match.group(1)) {
|
||||
'lt' => '<',
|
||||
'gt' => '>',
|
||||
'quot' => '"',
|
||||
'apos' => "'",
|
||||
'nbsp' => ' ',
|
||||
'amp' => '&',
|
||||
var i? when (i.startsWith('#x')) => String.fromCharCode(
|
||||
int.parse(i.substring(2), radix: 16),
|
||||
),
|
||||
_ => match.group(0)!,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static List<({bool isEm, String text})> regTitle(String origin) {
|
||||
@@ -14,30 +32,12 @@ abstract final class Em {
|
||||
origin.splitMapJoin(
|
||||
_exp,
|
||||
onMatch: (Match match) {
|
||||
String matchStr = match[0]!;
|
||||
res.add((isEm: true, text: regCate(matchStr)));
|
||||
res.add((isEm: true, text: parseHtml(match[1] ?? match[0]!)));
|
||||
return '';
|
||||
},
|
||||
onNonMatch: (String str) {
|
||||
if (str != '') {
|
||||
res.add((
|
||||
isEm: false,
|
||||
text: str.replaceAllMapped(
|
||||
_htmlRegExp,
|
||||
(m) => switch (m.group(1)) {
|
||||
'lt' => '<',
|
||||
'gt' => '>',
|
||||
'quot' => '"',
|
||||
'apos' => "'",
|
||||
'nbsp' => ' ',
|
||||
'amp' => '&',
|
||||
var i? when (i.startsWith('#x')) => String.fromCharCode(
|
||||
int.parse(i.substring(2), radix: 16),
|
||||
),
|
||||
_ => m.group(0)!,
|
||||
},
|
||||
),
|
||||
));
|
||||
res.add((isEm: false, text: parseHtml(str)));
|
||||
}
|
||||
return '';
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user