stringify method
Return the stringified version of your text
Eg "Hey @Ironman" => "Hey [@Ironman:uid3000
]"
Implementation
String stringify() {
if (matchers.isEmpty) {
return text;
}
return text.splitMapJoin(
_combinedRegex,
onMatch: (Match match) {
final display = match[0]!;
final matcher = matchers.firstWhere((m) => m.regexPattern.isNotEmpty && RegExp(m.regexPattern).hasMatch(display));
final suggestions = matcher.suggestions.where((e) => '${matcher.trigger}${matcher.displayProp(e)}' == display).toList();
if (suggestions.isNotEmpty) {
assert(suggestions.length == 1);
return matcher.stringify(matcher.trigger, suggestions.first);
}
if (matcher.alwaysHighlight) {
return matcher.stringify(matcher.trigger, display);
}
throw '`suggestions` is empty and `alwaysHighlight` is false.';
},
onNonMatch: (String text) => text,
);
}