@@ -438,22 +438,24 @@ abstract class EmojiNode extends InlineContentNode {
438
438
}
439
439
440
440
class UnicodeEmojiNode extends EmojiNode {
441
- const UnicodeEmojiNode ({super .debugHtmlNode, required this .text });
441
+ const UnicodeEmojiNode ({super .debugHtmlNode, required this .emojiName, required this .emojiUnicode });
442
442
443
- final String text;
443
+ final String emojiName;
444
+ final String ? emojiUnicode;
444
445
445
446
@override
446
447
bool operator == (Object other) {
447
- return other is UnicodeEmojiNode && other.text == text ;
448
+ return other is UnicodeEmojiNode && other.emojiName == emojiName && other.emojiUnicode == emojiUnicode ;
448
449
}
449
450
450
451
@override
451
- int get hashCode => Object .hash ('UnicodeEmojiNode' , text );
452
+ int get hashCode => Object .hash ('UnicodeEmojiNode' , emojiName, emojiUnicode );
452
453
453
454
@override
454
455
void debugFillProperties (DiagnosticPropertiesBuilder properties) {
455
456
super .debugFillProperties (properties);
456
- properties.add (StringProperty ('text' , text));
457
+ properties.add (StringProperty ('emojiName' , emojiName));
458
+ properties.add (StringProperty ('emojiUnicode' , emojiUnicode));
457
459
}
458
460
}
459
461
@@ -568,7 +570,8 @@ class _ZulipContentParser {
568
570
&& classes.length == 2
569
571
&& classes.contains ('emoji' )
570
572
&& classes.every (_emojiClassRegexp.hasMatch)) {
571
- return UnicodeEmojiNode (text: element.text, debugHtmlNode: debugHtmlNode);
573
+ final emojiUnicode = tryParseEmojiCodeToUnicode (classes.elementAt (1 ).replaceFirst ('emoji-' , '' ));
574
+ return UnicodeEmojiNode (emojiName: element.text, emojiUnicode: emojiUnicode, debugHtmlNode: debugHtmlNode);
572
575
}
573
576
574
577
if (localName == 'img'
@@ -627,6 +630,25 @@ class _ZulipContentParser {
627
630
return ListNode (listStyle! , items, debugHtmlNode: debugHtmlNode);
628
631
}
629
632
633
+ // Ported from https://github.com/zulip/zulip-mobile/tree/main/src/emoji/data.js
634
+ //
635
+ // Which was in turn ported from https://github.com/zulip/zulip/blob/main/zerver/models.py
636
+ // and that describes the encoding as follows:
637
+ //
638
+ // > * For Unicode emoji, [emoji_code is] a dash-separated hex encoding of
639
+ // > the sequence of Unicode codepoints that define this emoji in the
640
+ // > Unicode specification. For examples, see "non_qualified" or
641
+ // > "unified" in the following data, with "non_qualified" taking
642
+ // > precedence when both present:
643
+ // > https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji_pretty.json
644
+ String ? tryParseEmojiCodeToUnicode (String code) {
645
+ try {
646
+ return String .fromCharCodes (code.split ('-' ).map ((hex) => int .parse (hex, radix: 16 )));
647
+ } catch (_) {
648
+ return null ;
649
+ }
650
+ }
651
+
630
652
BlockContentNode parseCodeBlock (dom.Element divElement) {
631
653
assert (_debugParserContext == _ParserContext .block);
632
654
final mainElement = () {
0 commit comments