mdTextCompiler function

String mdTextCompiler(
  1. String originalText, {
  2. bool isUseQQPackage = false,
  3. bool isUseTencentCloudChatPackage = false,
  4. bool isUseTencentCloudChatPackageOldKeys = false,
  5. List<CustomEmojiFaceData> customEmojiStickerList = const [],
})

Implementation

String mdTextCompiler(String originalText, {
  bool isUseQQPackage = false,
  bool isUseTencentCloudChatPackage = false,
  bool isUseTencentCloudChatPackageOldKeys = false,
  List<CustomEmojiFaceData> customEmojiStickerList = const [],
}) {
  String text = originalText;
  final EmojiUtil emojiUtil = EmojiUtil(
      isUseQQPackage: isUseQQPackage,
      isUseTencentCloudChatPackage: isUseTencentCloudChatPackage,
      isUseTencentCloudChatPackageOldKeys: isUseTencentCloudChatPackageOldKeys,
      customEmojiStickerList: customEmojiStickerList);

  text = text.replaceAllMapped(emojiExp, (match) {
    String key = match.group(0)!;

    // Check if the emoji exists in the emoji map
    if (emojiUtil.emojiMap.containsKey(key)) {
      String assetPath = emojiUtil.emojiMap[key]!;
      return '![sticker](resource:$assetPath#22x22)';
    }
    return key;
  });

  return text;
}