parse method
Return the parsed version of your text
Eg "Hey [@Ironman:uid3000
]" => "Hey @Ironman"
Implementation
String parse(String stringifiedText) {
if (matchers.isEmpty) {
return stringifiedText;
}
return stringifiedText.splitMapJoin(
_combinedParseRegex,
onMatch: (Match match) {
final fullMatch = match[0]!;
final matcher = matchers.firstWhere((m) => m.parseRegExp.hasMatch(fullMatch));
final parsedMatch = matcher.parse(matcher.parseRegExp, fullMatch);
final suggestions = matcher.suggestions.where((s) => matcher.idProp(s) == matcher.idProp(parsedMatch)).toList();
if (suggestions.isNotEmpty) {
assert(suggestions.length == 1);
return '${matcher.trigger}${matcher.displayProp(suggestions.first)}';
}
if (matcher.alwaysHighlight) {
return '${matcher.trigger}${matcher.displayProp(parsedMatch)}';
}
throw '`suggestions` is empty and `alwaysHighlight` is false.';
},
onNonMatch: (String text) => text,
);
}