forked from zulip/zulip-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_test.dart
1221 lines (1108 loc) · 61 KB
/
content_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import 'dart:io';
import 'package:checks/checks.dart';
import 'package:html/parser.dart';
import 'package:stack_trace/stack_trace.dart';
import 'package:test/scaffolding.dart';
import 'package:zulip/model/code_block.dart';
import 'package:zulip/model/content.dart';
import 'content_checks.dart';
/// An example of Zulip content for test cases.
//
// When writing examples:
//
// * Try to use actual HTML emitted by a Zulip server for [html].
// Record the corresponding Markdown source in [markdown].
//
// * Here's a handy `curl` command for getting the server's HTML.
// First, as one-time setup, create a file with a test account's
// Zulip credentials in "netrc" format, meaning one line that looks like:
// machine HOSTNAME login EMAIL password API_KEY
//
// * Then send some test messages, and fetch with a command like this.
// (Change "sender" operand to your user ID, and "topic" etc. as desired.)
/* $ curl -sS --netrc-file ../.netrc -G https://chat.zulip.org/api/v1/messages \
--data-urlencode 'narrow=[{"operator":"sender", "operand":2187},
{"operator":"stream", "operand":"test here"},
{"operator":"topic", "operand":"content"}]' \
--data-urlencode anchor=newest --data-urlencode num_before=10 --data-urlencode num_after=0 \
--data-urlencode apply_markdown=true \
| jq '.messages[] | .content'
*/
//
// * To get the corresponding Markdown source, use the same command
// with `apply_markdown` changed to `false`.
class ContentExample {
const ContentExample(this.description, this.markdown, this.html,
this.expectedNodes, {this.expectedText});
ContentExample.inline(this.description, this.markdown, this.html,
InlineContentNode parsed, {this.expectedText})
: expectedNodes = [ParagraphNode(links: null, nodes: [parsed])];
/// A description string, for use in names of tests.
final String description;
/// The Zulip Markdown source, if any, that the server renders as [html].
///
/// This is useful for reproducing the example content for live use in the
/// app, and as a starting point for variations on it.
///
/// Currently the test suite does not verify the relationship between
/// [markdown] and [html].
///
/// If there is no known Markdown that a Zulip server can render as [html],
/// then this should be null and a comment should explain why the test uses
/// such an example.
final String? markdown;
/// A fragment of Zulip HTML, to be parsed as a [ZulipContent].
///
/// Generally this should be actual HTML emitted by a Zulip server.
/// See the example `curl` command in comments on this class for help in
/// conveniently getting such HTML.
final String html;
/// The [ZulipContent.nodes] expected from parsing [html].
final List<BlockContentNode> expectedNodes;
/// The text, if applicable, of a text widget expected from
/// rendering [expectedNodes].
///
/// Strictly this belongs to the widget tests, not the model tests, as it
/// encodes choices about how the content widgets work. But it's convenient
/// to have it defined for each test case right next to [html] and [expectedNodes].
final String? expectedText;
static final strong = ContentExample.inline(
'strong/bold',
'**bold**',
expectedText: 'bold',
'<p><strong>bold</strong></p>',
const StrongNode(nodes: [TextNode('bold')]));
static final emphasis = ContentExample.inline(
'emphasis/italic',
'*italic*',
expectedText: 'italic',
'<p><em>italic</em></p>',
const EmphasisNode(nodes: [TextNode('italic')]));
static final inlineCode = ContentExample.inline(
'inline code',
'`inline code`',
expectedText: 'inline code',
'<p><code>inline code</code></p>',
const InlineCodeNode(nodes: [TextNode('inline code')]));
static final userMentionPlain = ContentExample.inline(
'plain user @-mention',
"@**Greg Price**",
expectedText: '@Greg Price',
'<p><span class="user-mention" data-user-id="2187">@Greg Price</span></p>',
const UserMentionNode(nodes: [TextNode('@Greg Price')]));
static final userMentionSilent = ContentExample.inline(
'silent user @-mention',
"@_**Greg Price**",
expectedText: 'Greg Price',
'<p><span class="user-mention silent" data-user-id="2187">Greg Price</span></p>',
const UserMentionNode(nodes: [TextNode('Greg Price')]));
static final userMentionSilentClassOrderReversed = ContentExample.inline(
'silent user @-mention, class order reversed',
"@_**Greg Price**", // (hypothetical server variation)
expectedText: 'Greg Price',
'<p><span class="silent user-mention" data-user-id="2187">Greg Price</span></p>',
const UserMentionNode(nodes: [TextNode('Greg Price')]));
static final groupMentionPlain = ContentExample.inline(
'plain group @-mention',
"@*test-empty*",
expectedText: '@test-empty',
'<p><span class="user-group-mention" data-user-group-id="186">@test-empty</span></p>',
const UserMentionNode(nodes: [TextNode('@test-empty')]));
static final groupMentionSilent = ContentExample.inline(
'silent group @-mention',
"@_*test-empty*",
expectedText: 'test-empty',
'<p><span class="user-group-mention silent" data-user-group-id="186">test-empty</span></p>',
const UserMentionNode(nodes: [TextNode('test-empty')]));
static final groupMentionSilentClassOrderReversed = ContentExample.inline(
'silent group @-mention, class order reversed',
"@_*test-empty*", // (hypothetical server variation)
expectedText: 'test-empty',
'<p><span class="silent user-group-mention" data-user-group-id="186">test-empty</span></p>',
const UserMentionNode(nodes: [TextNode('test-empty')]));
static final emojiUnicode = ContentExample.inline(
'Unicode emoji, encoded in span element',
":thumbs_up:",
expectedText: '\u{1f44d}', // "👍"
'<p><span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span></p>',
const UnicodeEmojiNode(emojiUnicode: '\u{1f44d}'));
static final emojiUnicodeClassesFlipped = ContentExample.inline(
'Unicode emoji, encoded in span element, class order reversed',
null, // ":thumbs_up:" (hypothetical server variation)
expectedText: '\u{1f44d}', // "👍"
'<p><span aria-label="thumbs up" class="emoji-1f44d emoji" role="img" title="thumbs up">:thumbs_up:</span></p>',
const UnicodeEmojiNode(emojiUnicode: '\u{1f44d}'));
static final emojiUnicodeMultiCodepoint = ContentExample.inline(
'Unicode emoji, encoded in span element, multiple codepoints',
":transgender_flag:",
expectedText: '\u{1f3f3}\u{fe0f}\u{200d}\u{26a7}\u{fe0f}', // "🏳️⚧️"
'<p><span aria-label="transgender flag" class="emoji emoji-1f3f3-fe0f-200d-26a7-fe0f" role="img" title="transgender flag">:transgender_flag:</span></p>',
const UnicodeEmojiNode(emojiUnicode: '\u{1f3f3}\u{fe0f}\u{200d}\u{26a7}\u{fe0f}'));
static final emojiUnicodeLiteral = ContentExample.inline(
'Unicode emoji, not encoded in span element',
"\u{1fabf}",
expectedText: '\u{1fabf}', // "🪿"
'<p>\u{1fabf}</p>',
const TextNode('\u{1fabf}'));
static final emojiCustom = ContentExample.inline(
'custom emoji',
":flutter:",
'<p><img alt=":flutter:" class="emoji" src="/user_avatars/2/emoji/images/204.png" title="flutter"></p>',
const ImageEmojiNode(
src: '/user_avatars/2/emoji/images/204.png', alt: ':flutter:'));
static final emojiCustomInvalidUrl = ContentExample.inline(
'custom emoji with invalid URL',
null, // hypothetical, to test for a risk of crashing
'<p><img alt=":invalid:" class="emoji" src="::not a URL::" title="invalid"></p>',
const ImageEmojiNode(
src: '::not a URL::', alt: ':invalid:'));
static final emojiZulipExtra = ContentExample.inline(
'Zulip extra emoji',
":zulip:",
'<p><img alt=":zulip:" class="emoji" src="/static/generated/emoji/images/emoji/unicode/zulip.png" title="zulip"></p>',
const ImageEmojiNode(
src: '/static/generated/emoji/images/emoji/unicode/zulip.png', alt: ':zulip:'));
static final globalTime = ContentExample.inline(
'global time',
"<time:2024-03-07T15:00:00-08:00>",
'<p><time datetime="2024-03-07T23:00:00Z">2024-03-07T15:00:00-08:00</time></p>',
GlobalTimeNode(
datetime: DateTime.parse("2024-03-07T23:00:00Z")));
static const spoilerDefaultHeader = ContentExample(
'spoiler with default header',
'```spoiler\nhello world\n```',
expectedText: 'Spoiler', // or a translation
'<div class="spoiler-block"><div class="spoiler-header">\n'
'</div><div class="spoiler-content" aria-hidden="true">\n'
'<p>hello world</p>\n'
'</div></div>',
[SpoilerNode(
header: [],
content: [ParagraphNode(links: null, nodes: [TextNode('hello world')])],
)]);
static const spoilerPlainCustomHeader = ContentExample(
'spoiler with plain custom header',
'```spoiler hello\nworld\n```',
expectedText: 'hello',
'<div class="spoiler-block"><div class="spoiler-header">\n'
'<p>hello</p>\n'
'</div><div class="spoiler-content" aria-hidden="true">\n'
'<p>world</p>\n'
'</div></div>',
[SpoilerNode(
header: [ParagraphNode(links: null, nodes: [TextNode('hello')])],
content: [ParagraphNode(links: null, nodes: [TextNode('world')])],
)]);
static const spoilerRichHeaderAndContent = ContentExample(
'spoiler with rich header and content',
'```spoiler 1. * ## hello\n*italic* [zulip](https://zulip.com/)\n```',
expectedText: 'hello',
'<div class="spoiler-block"><div class="spoiler-header">\n'
'<ol>\n<li>\n<ul>\n<li>\n<h2>hello</h2>\n</li>\n</ul>\n</li>\n</ol>\n</div>'
'<div class="spoiler-content" aria-hidden="true">\n'
'<p><em>italic</em> <a href="https://zulip.com/">zulip</a></p>\n'
'</div></div>',
[SpoilerNode(
header: [ListNode(ListStyle.ordered, [
[ListNode(ListStyle.unordered, [
[HeadingNode(level: HeadingLevel.h2, links: null, nodes: [
TextNode('hello'),
])]
])],
])],
content: [ParagraphNode(links: null, nodes: [
EmphasisNode(nodes: [TextNode('italic')]),
TextNode(' '),
LinkNode(url: 'https://zulip.com/', nodes: [TextNode('zulip')])
])],
)]);
static const spoilerHeaderHasImage = ContentExample(
'spoiler a header that has an image in it',
'```spoiler [image](https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3)\nhello world\n```',
'<div class="spoiler-block"><div class="spoiler-header">\n'
'<p><a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3">image</a></p>\n'
'<div class="message_inline_image"><a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3" title="image"><img src="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3"></a></div></div>'
'<div class="spoiler-content" aria-hidden="true">\n'
'<p>hello world</p>\n'
'</div></div>\n',
[SpoilerNode(
header: [
ParagraphNode(links: null, nodes: [
LinkNode(url: 'https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3',
nodes: [TextNode('image')]),
]),
ImageNodeList([
ImageNode(srcUrl: 'https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
]),
],
content: [ParagraphNode(links: null, nodes: [TextNode('hello world')])],
)]);
static const quotation = ContentExample(
'quotation',
"```quote\nwords\n```",
expectedText: 'words',
'<blockquote>\n<p>words</p>\n</blockquote>', [
QuotationNode([ParagraphNode(links: null, nodes: [TextNode('words')])])
]);
static const codeBlockPlain = ContentExample(
'code block without syntax highlighting',
"```\nverb\natim\n```",
expectedText: 'verb\natim',
'<div class="codehilite"><pre><span></span><code>verb\natim\n</code></pre></div>', [
CodeBlockNode([
CodeBlockSpanNode(text: 'verb\natim', type: CodeBlockSpanType.text),
]),
]);
static const codeBlockHighlightedShort = ContentExample(
'code block with syntax highlighting',
"```dart\nclass A {}\n```",
expectedText: 'class A {}',
'<div class="codehilite" data-code-language="Dart"><pre>'
'<span></span><code><span class="kd">class</span><span class="w"> </span>'
'<span class="nc">A</span><span class="w"> </span><span class="p">{}</span>'
'\n</code></pre></div>', [
CodeBlockNode([
CodeBlockSpanNode(text: 'class', type: CodeBlockSpanType.keywordDeclaration),
CodeBlockSpanNode(text: ' ', type: CodeBlockSpanType.whitespace),
CodeBlockSpanNode(text: 'A', type: CodeBlockSpanType.nameClass),
CodeBlockSpanNode(text: ' ', type: CodeBlockSpanType.whitespace),
CodeBlockSpanNode(text: '{}', type: CodeBlockSpanType.punctuation),
]),
]);
static const codeBlockHighlightedMultiline = ContentExample(
'code block, multiline, with syntax highlighting',
'```rust\nfn main() {\n print!("Hello ");\n\n print!("world!\\n");\n}\n```',
expectedText: 'fn main() {\n print!("Hello ");\n\n print!("world!\\n");\n}',
'<div class="codehilite" data-code-language="Rust"><pre>'
'<span></span><code><span class="k">fn</span> <span class="nf">main</span>'
'<span class="p">()</span><span class="w"> </span><span class="p">{</span>\n'
'<span class="w"> </span><span class="fm">print!</span><span class="p">(</span>'
'<span class="s">"Hello "</span><span class="p">);</span>\n\n'
'<span class="w"> </span><span class="fm">print!</span><span class="p">(</span>'
'<span class="s">"world!</span><span class="se">\\n</span><span class="s">"</span>'
'<span class="p">);</span>\n<span class="p">}</span>\n'
'</code></pre></div>', [
CodeBlockNode([
CodeBlockSpanNode(text: 'fn', type: CodeBlockSpanType.keyword),
CodeBlockSpanNode(text: ' ', type: CodeBlockSpanType.text),
CodeBlockSpanNode(text: 'main', type: CodeBlockSpanType.nameFunction),
CodeBlockSpanNode(text: '()', type: CodeBlockSpanType.punctuation),
CodeBlockSpanNode(text: ' ', type: CodeBlockSpanType.whitespace),
CodeBlockSpanNode(text: '{', type: CodeBlockSpanType.punctuation),
CodeBlockSpanNode(text: '\n', type: CodeBlockSpanType.text),
CodeBlockSpanNode(text: ' ', type: CodeBlockSpanType.whitespace),
CodeBlockSpanNode(text: 'print!', type: CodeBlockSpanType.nameFunctionMagic),
CodeBlockSpanNode(text: '(', type: CodeBlockSpanType.punctuation),
CodeBlockSpanNode(text: '"Hello "', type: CodeBlockSpanType.string),
CodeBlockSpanNode(text: ');', type: CodeBlockSpanType.punctuation),
CodeBlockSpanNode(text: '\n\n', type: CodeBlockSpanType.text),
CodeBlockSpanNode(text: ' ', type: CodeBlockSpanType.whitespace),
CodeBlockSpanNode(text: 'print!', type: CodeBlockSpanType.nameFunctionMagic),
CodeBlockSpanNode(text: '(', type: CodeBlockSpanType.punctuation),
CodeBlockSpanNode(text: '"world!', type: CodeBlockSpanType.string),
CodeBlockSpanNode(text: '\\n', type: CodeBlockSpanType.stringEscape),
CodeBlockSpanNode(text: '"', type: CodeBlockSpanType.string),
CodeBlockSpanNode(text: ');', type: CodeBlockSpanType.punctuation),
CodeBlockSpanNode(text: '\n', type: CodeBlockSpanType.text),
CodeBlockSpanNode(text: '}', type: CodeBlockSpanType.punctuation),
]),
]);
static final codeBlockWithHighlightedLines = ContentExample(
'code block, with syntax highlighting and highlighted lines',
'```\n::markdown hl_lines="2 4"\n# he\n## llo\n### world\n```',
'<div class="codehilite"><pre>'
'<span></span><code>::markdown hl_lines="2 4"\n'
'<span class="hll"><span class="gh"># he</span>\n'
'</span><span class="gu">## llo</span>\n'
'<span class="hll"><span class="gu">### world</span>\n'
'</span></code></pre></div>', [
// TODO: Fix this, see comment under `CodeBlockSpanType.highlightedLines` case in lib/model/content.dart.
blockUnimplemented('<div class="codehilite"><pre>'
'<span></span><code>::markdown hl_lines="2 4"\n'
'<span class="hll"><span class="gh"># he</span>\n'
'</span><span class="gu">## llo</span>\n'
'<span class="hll"><span class="gu">### world</span>\n'
'</span></code></pre></div>'),
]);
static final codeBlockWithUnknownSpanType = ContentExample(
'code block, with an unknown span type',
null, // this test is for future Pygments versions adding new token types
'<div class="codehilite" data-code-language="Dart"><pre>'
'<span></span><code><span class="unknown">class</span>'
'\n</code></pre></div>', [
blockUnimplemented('<div class="codehilite" data-code-language="Dart"><pre>'
'<span></span><code><span class="unknown">class</span>'
'\n</code></pre></div>'),
]);
static const codeBlockFollowedByMultipleLineBreaks = ContentExample(
'blank text nodes after code blocks',
' code block.\n\nsome content',
// https://chat.zulip.org/#narrow/stream/7-test-here/near/1774823
'<div class="codehilite">'
'<pre><span></span><code>code block.\n</code></pre></div>\n\n'
'<p>some content</p>', [
CodeBlockNode([CodeBlockSpanNode(text: "code block.", type: CodeBlockSpanType.text)]),
ParagraphNode(links: null, nodes: [TextNode("some content")]),
]);
static final mathInline = ContentExample.inline(
'inline math',
r"$$ \lambda $$",
expectedText: r'\lambda',
'<p><span class="katex">'
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>λ</mi></mrow>'
'<annotation encoding="application/x-tex"> \\lambda </annotation></semantics></math></span>'
'<span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">λ</span></span></span></span></p>',
const MathInlineNode(texSource: r'\lambda'));
static const mathBlock = ContentExample(
'math block',
"```math\n\\lambda\n```",
expectedText: r'\lambda',
'<p><span class="katex-display"><span class="katex">'
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>λ</mi></mrow>'
'<annotation encoding="application/x-tex">\\lambda</annotation></semantics></math></span>'
'<span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">λ</span></span></span></span></span></p>',
[MathBlockNode(texSource: r'\lambda')]);
static const mathBlockInQuote = ContentExample(
'math block in quote',
// There's sometimes a quirky extra `<br>\n` at the end of the `<p>` that
// encloses the math block. In particular this happens when the math block
// is the last thing in the quote; though not in a doubly-nested quote;
// and there might be further wrinkles yet to be found. Some experiments:
// https://chat.zulip.org/#narrow/stream/7-test-here/topic/content/near/1715732
"````quote\n```math\n\\lambda\n```\n````",
'<blockquote>\n<p>'
'<span class="katex-display"><span class="katex">'
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>λ</mi></mrow>'
'<annotation encoding="application/x-tex">\\lambda</annotation></semantics></math></span>'
'<span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">λ</span></span></span></span></span>'
'<br>\n</p>\n</blockquote>',
[QuotationNode([MathBlockNode(texSource: r'\lambda')])]);
static const imageSingle = ContentExample(
'single image',
// https://chat.zulip.org/#narrow/stream/7-test-here/topic/Thumbnails/near/1900103
"[image.jpg](/user_uploads/2/ce/nvoNL2LaZOciwGZ-FYagddtK/image.jpg)",
'<div class="message_inline_image">'
'<a href="/user_uploads/2/ce/nvoNL2LaZOciwGZ-FYagddtK/image.jpg" title="image.jpg">'
'<img data-original-dimensions="6000x4000" src="/user_uploads/thumbnail/2/ce/nvoNL2LaZOciwGZ-FYagddtK/image.jpg/840x560.webp"></a></div>', [
ImageNodeList([
ImageNode(srcUrl: '/user_uploads/2/ce/nvoNL2LaZOciwGZ-FYagddtK/image.jpg',
thumbnailUrl: '/user_uploads/thumbnail/2/ce/nvoNL2LaZOciwGZ-FYagddtK/image.jpg/840x560.webp',
loading: false,
originalWidth: 6000,
originalHeight: 4000),
]),
]);
static const imageSingleNoDimensions = ContentExample(
'single image no dimensions',
// https://chat.zulip.org/#narrow/stream/7-test-here/topic/Thumbnails/near/1893590
"[image.jpg](/user_uploads/2/c3/wb9FXk8Ej6qIc28aWKcqUogD/image.jpg)",
'<div class="message_inline_image">'
'<a href="/user_uploads/2/c3/wb9FXk8Ej6qIc28aWKcqUogD/image.jpg" title="image.jpg">'
'<img src="/user_uploads/thumbnail/2/c3/wb9FXk8Ej6qIc28aWKcqUogD/image.jpg/840x560.webp"/></a></div>', [
ImageNodeList([
ImageNode(srcUrl: '/user_uploads/2/c3/wb9FXk8Ej6qIc28aWKcqUogD/image.jpg',
thumbnailUrl: '/user_uploads/thumbnail/2/c3/wb9FXk8Ej6qIc28aWKcqUogD/image.jpg/840x560.webp',
loading: false,
originalWidth: null,
originalHeight: null),
]),
]);
static const imageSingleNoThumbnail = ContentExample(
'single image no thumbnail',
"https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3",
'<div class="message_inline_image">'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3">'
'<img src="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3"></a></div>', [
ImageNodeList([
ImageNode(srcUrl: 'https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
]),
]);
static const imageSingleLoadingPlaceholder = ContentExample(
'single image loading placeholder',
// https://chat.zulip.org/#narrow/stream/7-test-here/topic/Thumbnails/near/1893590
"[image.jpg](/user_uploads/2/c3/wb9FXk8Ej6qIc28aWKcqUogD/image.jpg)",
'<div class="message_inline_image">'
'<a href="/user_uploads/2/c3/wb9FXk8Ej6qIc28aWKcqUogD/image.jpg" title="image.jpg">'
'<img class="image-loading-placeholder" src="/static/images/loading/loader-black.svg"></a></div>', [
ImageNodeList([
ImageNode(srcUrl: '/user_uploads/2/c3/wb9FXk8Ej6qIc28aWKcqUogD/image.jpg',
thumbnailUrl: null, loading: true,
originalWidth: null, originalHeight: null),
]),
]);
static const imageSingleExternal = ContentExample(
'single image external',
// https://chat.zulip.org/#narrow/stream/7-test-here/topic/Greg/near/1892172
"https://upload.wikimedia.org/wikipedia/commons/7/78/Verregende_bloem_van_een_Helenium_%27El_Dorado%27._22-07-2023._%28d.j.b%29.jpg",
'<div class="message_inline_image">'
'<a href="https://upload.wikimedia.org/wikipedia/commons/7/78/Verregende_bloem_van_een_Helenium_%27El_Dorado%27._22-07-2023._%28d.j.b%29.jpg">'
'<img src="/external_content/de28eb3abf4b7786de4545023dc42d434a2ea0c2/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f372f37382f566572726567656e64655f626c6f656d5f76616e5f65656e5f48656c656e69756d5f253237456c5f446f7261646f2532372e5f32322d30372d323032332e5f253238642e6a2e622532392e6a7067"></a></div>', [
ImageNodeList([
ImageNode(srcUrl: '/external_content/de28eb3abf4b7786de4545023dc42d434a2ea0c2/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f372f37382f566572726567656e64655f626c6f656d5f76616e5f65656e5f48656c656e69756d5f253237456c5f446f7261646f2532372e5f32322d30372d323032332e5f253238642e6a2e622532392e6a7067',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
]),
]);
static const imageInvalidUrl = ContentExample(
'single image with invalid URL',
null, // hypothetical, to test for a risk of crashing
'<div class="message_inline_image">'
'<a href="::not a URL::">'
'<img src="::not a URL::"></a></div>', [
ImageNodeList([
ImageNode(srcUrl: '::not a URL::',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
]),
]);
static const imageCluster = ContentExample(
'multiple images',
// https://chat.zulip.org/#narrow/stream/7-test-here/topic/Thumbnails/near/1893154
"[image.jpg](/user_uploads/2/9b/WkDt2Qsy79iwf3sM9EMp9fYL/image.jpg)\n[image2.jpg](/user_uploads/2/70/pVeI52TwFUEoFE2qT_u9AMCO/image2.jpg)",
'<p>'
'<a href="/user_uploads/2/9b/WkDt2Qsy79iwf3sM9EMp9fYL/image.jpg">image.jpg</a><br/>\n'
'<a href="/user_uploads/2/70/pVeI52TwFUEoFE2qT_u9AMCO/image2.jpg">image2.jpg</a></p>\n'
'<div class="message_inline_image">'
'<a href="/user_uploads/2/9b/WkDt2Qsy79iwf3sM9EMp9fYL/image.jpg" title="image.jpg">'
'<img src="/user_uploads/thumbnail/2/9b/WkDt2Qsy79iwf3sM9EMp9fYL/image.jpg/840x560.webp"/></a></div>'
'<div class="message_inline_image">'
'<a href="/user_uploads/2/70/pVeI52TwFUEoFE2qT_u9AMCO/image2.jpg" title="image2.jpg">'
'<img src="/user_uploads/thumbnail/2/70/pVeI52TwFUEoFE2qT_u9AMCO/image2.jpg/840x560.webp"/></a></div>', [
ParagraphNode(links: null, nodes: [
LinkNode(url: '/user_uploads/2/9b/WkDt2Qsy79iwf3sM9EMp9fYL/image.jpg', nodes: [TextNode('image.jpg')]),
LineBreakInlineNode(),
TextNode('\n'),
LinkNode(url: '/user_uploads/2/70/pVeI52TwFUEoFE2qT_u9AMCO/image2.jpg', nodes: [TextNode('image2.jpg')]),
]),
ImageNodeList([
ImageNode(srcUrl: '/user_uploads/2/9b/WkDt2Qsy79iwf3sM9EMp9fYL/image.jpg',
thumbnailUrl: '/user_uploads/thumbnail/2/9b/WkDt2Qsy79iwf3sM9EMp9fYL/image.jpg/840x560.webp',
loading: false,
originalWidth: null,
originalHeight: null),
ImageNode(srcUrl: '/user_uploads/2/70/pVeI52TwFUEoFE2qT_u9AMCO/image2.jpg',
thumbnailUrl: '/user_uploads/thumbnail/2/70/pVeI52TwFUEoFE2qT_u9AMCO/image2.jpg/840x560.webp',
loading: false,
originalWidth: null,
originalHeight: null),
]),
]);
static const imageClusterNoThumbnails = ContentExample(
'multiple images no thumbnails',
"https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3\nhttps://chat.zulip.org/user_avatars/2/realm/icon.png?version=4",
'<p>'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3">https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3</a><br>\n'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=4">https://chat.zulip.org/user_avatars/2/realm/icon.png?version=4</a></p>\n'
'<div class="message_inline_image">'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3">'
'<img src="https://uploads.zulipusercontent.net/f535ba07f95b99a83aa48e44fd62bbb6c6cf6615/68747470733a2f2f636861742e7a756c69702e6f72672f757365725f617661746172732f322f7265616c6d2f69636f6e2e706e673f76657273696f6e3d33"></a></div>'
'<div class="message_inline_image">'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=4">'
'<img src="https://uploads.zulipusercontent.net/8f63bc2632a0e41be3f457d86c077e61b4a03e7e/68747470733a2f2f636861742e7a756c69702e6f72672f757365725f617661746172732f322f7265616c6d2f69636f6e2e706e673f76657273696f6e3d34"></a></div>', [
ParagraphNode(links: null, nodes: [
LinkNode(url: 'https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3', nodes: [TextNode('https://chat.zulip.org/user_avatars/2/realm/icon.png?version=3')]),
LineBreakInlineNode(),
TextNode('\n'),
LinkNode(url: 'https://chat.zulip.org/user_avatars/2/realm/icon.png?version=4', nodes: [TextNode('https://chat.zulip.org/user_avatars/2/realm/icon.png?version=4')]),
]),
ImageNodeList([
ImageNode(srcUrl: 'https://uploads.zulipusercontent.net/f535ba07f95b99a83aa48e44fd62bbb6c6cf6615/68747470733a2f2f636861742e7a756c69702e6f72672f757365725f617661746172732f322f7265616c6d2f69636f6e2e706e673f76657273696f6e3d33',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
ImageNode(srcUrl: 'https://uploads.zulipusercontent.net/8f63bc2632a0e41be3f457d86c077e61b4a03e7e/68747470733a2f2f636861742e7a756c69702e6f72672f757365725f617661746172732f322f7265616c6d2f69636f6e2e706e673f76657273696f6e3d34',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
]),
]);
static const imageClusterThenContent = ContentExample(
'content after image cluster',
"https://chat.zulip.org/user_avatars/2/realm/icon.png\nhttps://chat.zulip.org/user_avatars/2/realm/icon.png?version=2\n\nmore content",
'<p>content '
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png">icon.png</a> '
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2">icon.png</a></p>\n'
'<div class="message_inline_image">'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png" title="icon.png">'
'<img src="https://chat.zulip.org/user_avatars/2/realm/icon.png"></a></div>'
'<div class="message_inline_image">'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2" title="icon.png">'
'<img src="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2"></a></div>'
'<p>more content</p>', [
ParagraphNode(links: null, nodes: [
TextNode('content '),
LinkNode(url: 'https://chat.zulip.org/user_avatars/2/realm/icon.png', nodes: [TextNode('icon.png')]),
TextNode(' '),
LinkNode(url: 'https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2', nodes: [TextNode('icon.png')]),
]),
ImageNodeList([
ImageNode(srcUrl: 'https://chat.zulip.org/user_avatars/2/realm/icon.png',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
ImageNode(srcUrl: 'https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
]),
ParagraphNode(links: null, nodes: [
TextNode('more content'),
]),
]);
static const imageMultipleClusters = ContentExample(
'multiple clusters of images',
"https://en.wikipedia.org/static/images/icons/wikipedia.png\nhttps://en.wikipedia.org/static/images/icons/wikipedia.png?v=1\n\nTest\n\nhttps://en.wikipedia.org/static/images/icons/wikipedia.png?v=2\nhttps://en.wikipedia.org/static/images/icons/wikipedia.png?v=3",
'<p>'
'<a href="https://en.wikipedia.org/static/images/icons/wikipedia.png">https://en.wikipedia.org/static/images/icons/wikipedia.png</a><br>\n' '<a href="https://en.wikipedia.org/static/images/icons/wikipedia.png?v=1">https://en.wikipedia.org/static/images/icons/wikipedia.png?v=1</a></p>\n'
'<div class="message_inline_image">'
'<a href="https://en.wikipedia.org/static/images/icons/wikipedia.png">'
'<img src="https://uploads.zulipusercontent.net/34b2695ca83af76204b0b25a8f2019ee35ec38fa/68747470733a2f2f656e2e77696b6970656469612e6f72672f7374617469632f696d616765732f69636f6e732f77696b6970656469612e706e67"></a></div>'
'<div class="message_inline_image">'
'<a href="https://en.wikipedia.org/static/images/icons/wikipedia.png?v=1">'
'<img src="https://uploads.zulipusercontent.net/d200fb112aaccbff9df767373a201fa59601f362/68747470733a2f2f656e2e77696b6970656469612e6f72672f7374617469632f696d616765732f69636f6e732f77696b6970656469612e706e673f763d31"></a></div>'
'<p>Test</p>\n'
'<p>'
'<a href="https://en.wikipedia.org/static/images/icons/wikipedia.png?v=2">https://en.wikipedia.org/static/images/icons/wikipedia.png?v=2</a><br>\n'
'<a href="https://en.wikipedia.org/static/images/icons/wikipedia.png?v=3">https://en.wikipedia.org/static/images/icons/wikipedia.png?v=3</a></p>\n'
'<div class="message_inline_image">'
'<a href="https://en.wikipedia.org/static/images/icons/wikipedia.png?v=2">'
'<img src="https://uploads.zulipusercontent.net/c4db87e81348dac94eacaa966b46d968b34029cc/68747470733a2f2f656e2e77696b6970656469612e6f72672f7374617469632f696d616765732f69636f6e732f77696b6970656469612e706e673f763d32"></a></div>'
'<div class="message_inline_image">'
'<a href="https://en.wikipedia.org/static/images/icons/wikipedia.png?v=3">'
'<img src="https://uploads.zulipusercontent.net/51b70540cf6a5b3c8a0b919c893b8abddd447e88/68747470733a2f2f656e2e77696b6970656469612e6f72672f7374617469632f696d616765732f69636f6e732f77696b6970656469612e706e673f763d33"></a></div>', [
ParagraphNode(links: null, nodes: [
LinkNode(url: 'https://en.wikipedia.org/static/images/icons/wikipedia.png', nodes: [TextNode('https://en.wikipedia.org/static/images/icons/wikipedia.png')]),
LineBreakInlineNode(),
TextNode('\n'),
LinkNode(url: 'https://en.wikipedia.org/static/images/icons/wikipedia.png?v=1', nodes: [TextNode('https://en.wikipedia.org/static/images/icons/wikipedia.png?v=1')]),
]),
ImageNodeList([
ImageNode(srcUrl: 'https://uploads.zulipusercontent.net/34b2695ca83af76204b0b25a8f2019ee35ec38fa/68747470733a2f2f656e2e77696b6970656469612e6f72672f7374617469632f696d616765732f69636f6e732f77696b6970656469612e706e67',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
ImageNode(srcUrl: 'https://uploads.zulipusercontent.net/d200fb112aaccbff9df767373a201fa59601f362/68747470733a2f2f656e2e77696b6970656469612e6f72672f7374617469632f696d616765732f69636f6e732f77696b6970656469612e706e673f763d31',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
]),
ParagraphNode(links: null, nodes: [
TextNode('Test'),
]),
ParagraphNode(links: null, nodes: [
LinkNode(url: 'https://en.wikipedia.org/static/images/icons/wikipedia.png?v=2', nodes: [TextNode('https://en.wikipedia.org/static/images/icons/wikipedia.png?v=2')]),
LineBreakInlineNode(),
TextNode('\n'),
LinkNode(url: 'https://en.wikipedia.org/static/images/icons/wikipedia.png?v=3', nodes: [TextNode('https://en.wikipedia.org/static/images/icons/wikipedia.png?v=3')]),
]),
ImageNodeList([
ImageNode(srcUrl: 'https://uploads.zulipusercontent.net/c4db87e81348dac94eacaa966b46d968b34029cc/68747470733a2f2f656e2e77696b6970656469612e6f72672f7374617469632f696d616765732f69636f6e732f77696b6970656469612e706e673f763d32',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
ImageNode(srcUrl: 'https://uploads.zulipusercontent.net/51b70540cf6a5b3c8a0b919c893b8abddd447e88/68747470733a2f2f656e2e77696b6970656469612e6f72672f7374617469632f696d616765732f69636f6e732f77696b6970656469612e706e673f763d33',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
]),
]);
static const imageInImplicitParagraph = ContentExample(
'image as immediate child in implicit paragraph',
"* https://chat.zulip.org/user_avatars/2/realm/icon.png",
'<ul>\n'
'<li>'
'<div class="message_inline_image">'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png">'
'<img src="https://chat.zulip.org/user_avatars/2/realm/icon.png"></a></div></li>\n</ul>', [
ListNode(ListStyle.unordered, [[
ImageNodeList([
ImageNode(srcUrl: 'https://chat.zulip.org/user_avatars/2/realm/icon.png',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
]),
]]),
]);
static const imageClusterInImplicitParagraph = ContentExample(
'image cluster in implicit paragraph',
"* [icon.png](https://chat.zulip.org/user_avatars/2/realm/icon.png) [icon.png](https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2)",
'<ul>\n'
'<li>'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png">icon.png</a> '
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2">icon.png</a>'
'<div class="message_inline_image">'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png" title="icon.png">'
'<img src="https://chat.zulip.org/user_avatars/2/realm/icon.png"></a></div>'
'<div class="message_inline_image">'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2" title="icon.png">'
'<img src="https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2"></a></div></li>\n</ul>', [
ListNode(ListStyle.unordered, [[
ParagraphNode(wasImplicit: true, links: null, nodes: [
LinkNode(url: 'https://chat.zulip.org/user_avatars/2/realm/icon.png', nodes: [TextNode('icon.png')]),
TextNode(' '),
LinkNode(url: 'https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2', nodes: [TextNode('icon.png')]),
]),
ImageNodeList([
ImageNode(srcUrl: 'https://chat.zulip.org/user_avatars/2/realm/icon.png',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
ImageNode(srcUrl: 'https://chat.zulip.org/user_avatars/2/realm/icon.png?version=2',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
]),
]]),
]);
static final imageClusterInImplicitParagraphThenContent = ContentExample(
'impossible content after image cluster in implicit paragraph',
// Image previews are always inserted at the end of the paragraph
// so it would be impossible to have content after.
null,
'<ul>\n'
'<li>'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png">icon.png</a> '
'<div class="message_inline_image">'
'<a href="https://chat.zulip.org/user_avatars/2/realm/icon.png" title="icon.png">'
'<img src="https://chat.zulip.org/user_avatars/2/realm/icon.png"></a></div>'
'more text</li>\n</ul>', [
ListNode(ListStyle.unordered, [[
const ParagraphNode(wasImplicit: true, links: null, nodes: [
LinkNode(url: 'https://chat.zulip.org/user_avatars/2/realm/icon.png', nodes: [TextNode('icon.png')]),
TextNode(' '),
]),
const ImageNodeList([
ImageNode(srcUrl: 'https://chat.zulip.org/user_avatars/2/realm/icon.png',
thumbnailUrl: null, loading: false,
originalWidth: null, originalHeight: null),
]),
blockUnimplemented('more text'),
]]),
]);
static const thematicBreak = ContentExample(
'parse thematic break (<hr>)',
// https://chat.zulip.org/#narrow/stream/7-test-here/near/1774718
'a\n---\nb',
'<p>a</p>\n<hr>\n<p>b</p>',
[
ParagraphNode(links: null, nodes: [TextNode('a')]),
ThematicBreakNode(),
ParagraphNode(links: null, nodes: [TextNode('b')]),
]);
static const videoEmbedYoutube = ContentExample(
'video preview for youtube embed with thumbnail',
'https://www.youtube.com/watch?v=aqz-KE-bpKQ',
'<p>'
'<a href="https://www.youtube.com/watch?v=aqz-KE-bpKQ">https://www.youtube.com/watch?v=aqz-KE-bpKQ</a>'
'</p>\n'
'<div class="youtube-video message_inline_image">'
'<a data-id="aqz-KE-bpKQ" href="https://www.youtube.com/watch?v=aqz-KE-bpKQ">'
'<img src="/external_content/ecb96e8f884f481c4bc0179287a44ab9014aa78f/68747470733a2f2f692e7974696d672e636f6d2f76692f61717a2d4b452d62704b512f64656661756c742e6a7067"></a></div>', [
ParagraphNode(links: null, nodes: [
LinkNode(url: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ', nodes: [TextNode('https://www.youtube.com/watch?v=aqz-KE-bpKQ')]),
]),
EmbedVideoNode(
hrefUrl: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ',
previewImageSrcUrl: '/external_content/ecb96e8f884f481c4bc0179287a44ab9014aa78f/68747470733a2f2f692e7974696d672e636f6d2f76692f61717a2d4b452d62704b512f64656661756c742e6a7067'
),
]);
static const videoEmbedYoutubeClassesFlipped = ContentExample(
'video preview for youtube embed with thumbnail, (hypothetical) class name reorder',
null, // "https://www.youtube.com/watch?v=aqz-KE-bpKQ" (hypothetical server variation)
'<p>'
'<a href="https://www.youtube.com/watch?v=aqz-KE-bpKQ">https://www.youtube.com/watch?v=aqz-KE-bpKQ</a>'
'</p>\n'
'<div class="message_inline_image youtube-video">'
'<a data-id="aqz-KE-bpKQ" href="https://www.youtube.com/watch?v=aqz-KE-bpKQ">'
'<img src="/external_content/ecb96e8f884f481c4bc0179287a44ab9014aa78f/68747470733a2f2f692e7974696d672e636f6d2f76692f61717a2d4b452d62704b512f64656661756c742e6a7067"></a></div>', [
ParagraphNode(links: null, nodes: [
LinkNode(url: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ', nodes: [TextNode('https://www.youtube.com/watch?v=aqz-KE-bpKQ')]),
]),
EmbedVideoNode(
hrefUrl: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ',
previewImageSrcUrl: '/external_content/ecb96e8f884f481c4bc0179287a44ab9014aa78f/68747470733a2f2f692e7974696d672e636f6d2f76692f61717a2d4b452d62704b512f64656661756c742e6a7067'
),
]);
static const videoEmbedVimeoPreviewDisabled = ContentExample(
'video non-preview for attempted vimeo embed with realm link previews disabled',
'https://vimeo.com/1084537',
'<p>'
'<a href="https://vimeo.com/1084537">https://vimeo.com/1084537</a></p>', [
ParagraphNode(links: null, nodes: [
LinkNode(url: 'https://vimeo.com/1084537', nodes: [TextNode('https://vimeo.com/1084537')]),
]),
]);
static const videoEmbedVimeo = ContentExample(
'video preview for vimeo embed with realm link previews enabled',
'https://vimeo.com/1084537',
// The server really does generate an attribute called "data-id" whose value
// is a blob of HTML. The web client uses this to show Vimeo's video player
// inside a sandbox iframe. The HTML comes from Vimeo and may change form;
// that's OK the way web uses it, but we shouldn't try to parse it. See:
// https://chat.zulip.org/#narrow/stream/9-issues/topic/Vimeo.20link.20previews.20HTML.20.22data-id.22.20isn't.20a.20.20Vimeo.20video.20ID/near/1767563
'<p>'
'<a href="https://vimeo.com/1084537">Vimeo - Big Buck Bunny</a>'
'</p>\n'
'<div class="embed-video message_inline_image">'
'<a data-id="<iframe src="https://player.vimeo.com/video/1084537?app_id=122963" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture; clipboard-write" title="Big Buck Bunny"></iframe>" href="https://vimeo.com/1084537" title="Big Buck Bunny">'
'<img src="https://uploads.zulipusercontent.net/75aed2df4a1e8657176fcd6159fc40876ace4070/68747470733a2f2f692e76696d656f63646e2e636f6d2f766964656f2f32303936333634392d663032383137343536666334386537633331376566346330376261323539636434623430613336343962643865623530613434313862353965633366356166352d645f363430"></a></div>', [
ParagraphNode(links: null, nodes: [
LinkNode(url: 'https://vimeo.com/1084537', nodes: [TextNode('Vimeo - Big Buck Bunny')]),
]),
EmbedVideoNode(
hrefUrl: 'https://vimeo.com/1084537',
previewImageSrcUrl: 'https://uploads.zulipusercontent.net/75aed2df4a1e8657176fcd6159fc40876ace4070/68747470733a2f2f692e76696d656f63646e2e636f6d2f766964656f2f32303936333634392d663032383137343536666334386537633331376566346330376261323539636434623430613336343962643865623530613434313862353965633366356166352d645f363430'
),
]);
static const videoEmbedVimeoClassesFlipped = ContentExample(
'video preview for vimeo embed with realm link previews enabled, (hypothetical) class name reorder',
'https://vimeo.com/1084537',
'<p>'
'<a href="https://vimeo.com/1084537">Vimeo - Big Buck Bunny</a>'
'</p>\n'
'<div class="message_inline_image embed-video">'
'<a data-id="<iframe src="https://player.vimeo.com/video/1084537?app_id=122963" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture; clipboard-write" title="Big Buck Bunny"></iframe>" href="https://vimeo.com/1084537" title="Big Buck Bunny">'
'<img src="https://uploads.zulipusercontent.net/75aed2df4a1e8657176fcd6159fc40876ace4070/68747470733a2f2f692e76696d656f63646e2e636f6d2f766964656f2f32303936333634392d663032383137343536666334386537633331376566346330376261323539636434623430613336343962643865623530613434313862353965633366356166352d645f363430"></a></div>', [
ParagraphNode(links: null, nodes: [
LinkNode(url: 'https://vimeo.com/1084537', nodes: [TextNode('Vimeo - Big Buck Bunny')]),
]),
EmbedVideoNode(
hrefUrl: 'https://vimeo.com/1084537',
previewImageSrcUrl: 'https://uploads.zulipusercontent.net/75aed2df4a1e8657176fcd6159fc40876ace4070/68747470733a2f2f692e76696d656f63646e2e636f6d2f766964656f2f32303936333634392d663032383137343536666334386537633331376566346330376261323539636434623430613336343962643865623530613434313862353965633366356166352d645f363430'
),
]);
static const videoInline = ContentExample(
'video preview for user uploaded video',
'[Big-Buck-Bunny.webm](/user_uploads/2/78/_KoRecCHZTFrVtyTKCkIh5Hq/Big-Buck-Bunny.webm)',
'<p>'
'<a href="/user_uploads/2/78/_KoRecCHZTFrVtyTKCkIh5Hq/Big-Buck-Bunny.webm">Big-Buck-Bunny.webm</a>'
'</p>\n'
'<div class="message_inline_image message_inline_video">'
'<a href="/user_uploads/2/78/_KoRecCHZTFrVtyTKCkIh5Hq/Big-Buck-Bunny.webm" title="Big-Buck-Bunny.webm">'
'<video preload="metadata" src="/user_uploads/2/78/_KoRecCHZTFrVtyTKCkIh5Hq/Big-Buck-Bunny.webm"></video></a></div>', [
ParagraphNode(links: null, nodes: [
LinkNode(url: '/user_uploads/2/78/_KoRecCHZTFrVtyTKCkIh5Hq/Big-Buck-Bunny.webm', nodes: [TextNode('Big-Buck-Bunny.webm')]),
]),
InlineVideoNode(srcUrl: '/user_uploads/2/78/_KoRecCHZTFrVtyTKCkIh5Hq/Big-Buck-Bunny.webm'),
]);
static const videoInlineClassesFlipped = ContentExample(
'video preview for user uploaded video, (hypothetical) class name reorder',
'[Big-Buck-Bunny.webm](/user_uploads/2/78/_KoRecCHZTFrVtyTKCkIh5Hq/Big-Buck-Bunny.webm)',
'<p>'
'<a href="/user_uploads/2/78/_KoRecCHZTFrVtyTKCkIh5Hq/Big-Buck-Bunny.webm">Big-Buck-Bunny.webm</a>'
'</p>\n'
'<div class="message_inline_video message_inline_image">'
'<a href="/user_uploads/2/78/_KoRecCHZTFrVtyTKCkIh5Hq/Big-Buck-Bunny.webm" title="Big-Buck-Bunny.webm">'
'<video preload="metadata" src="/user_uploads/2/78/_KoRecCHZTFrVtyTKCkIh5Hq/Big-Buck-Bunny.webm"></video></a></div>', [
ParagraphNode(links: null, nodes: [
LinkNode(url: '/user_uploads/2/78/_KoRecCHZTFrVtyTKCkIh5Hq/Big-Buck-Bunny.webm', nodes: [TextNode('Big-Buck-Bunny.webm')]),
]),
InlineVideoNode(srcUrl: '/user_uploads/2/78/_KoRecCHZTFrVtyTKCkIh5Hq/Big-Buck-Bunny.webm'),
]);
}
UnimplementedBlockContentNode blockUnimplemented(String html) {
var fragment = HtmlParser(html, parseMeta: false).parseFragment();
return UnimplementedBlockContentNode(htmlNode: fragment.nodes.single);
}
UnimplementedInlineContentNode inlineUnimplemented(String html) {
var fragment = HtmlParser(html, parseMeta: false).parseFragment();
return UnimplementedInlineContentNode(htmlNode: fragment.nodes.single);
}
void testParse(String name, String html, List<BlockContentNode> nodes) {
test(name, () {
check(parseContent(html))
.equalsNode(ZulipContent(nodes: nodes));
});
}
void testParseExample(ContentExample example) {
testParse('parse ${example.description}', example.html, example.expectedNodes);
}
void main() {
// When writing test cases in this file:
//
// * Prefer to add a [ContentExample] static and use [testParseExample].
// Then add one line of code to `test/widgets/content_test.dart`,
// calling `testContentSmoke`, for a widgets test on the same example.
//
// * To write the example, see comment at top of [ContentExample].
//
// Inline content.
//
void testParseInline(String name, String html, InlineContentNode node) {
testParse(name, html, [ParagraphNode(links: null, nodes: [node])]);
}
testParse('parse a plain-text paragraph',
// "hello world"
'<p>hello world</p>', const [ParagraphNode(links: null, nodes: [
TextNode('hello world'),
])]);
testParse('parse <br> inside a paragraph',
// "a\nb"
'<p>a<br>\nb</p>', const [ParagraphNode(links: null, nodes: [
TextNode('a'),
LineBreakInlineNode(),
TextNode('\nb'),
])]);
testParseExample(ContentExample.strong);
testParseInline('parse deleted/strike-through',
// "~~strike through~~"
'<p><del>strike through</del></p>',
const DeletedNode(nodes: [TextNode('strike through')]));
testParseExample(ContentExample.emphasis);
testParseExample(ContentExample.inlineCode);
testParseInline('parse nested del, strong, em, code',
// "~~***`word`***~~"
'<p><del><strong><em><code>word</code></em></strong></del></p>',
const DeletedNode(
nodes: [StrongNode(nodes: [EmphasisNode(nodes: [InlineCodeNode(nodes: [
TextNode('word')])])])]));
group('LinkNode', () {
testParseInline('parse link',
// "[text](https://example/)"
'<p><a href="https://example/">text</a></p>',
const LinkNode(url: 'https://example/', nodes: [TextNode('text')]));
testParseInline('parse #-mention of stream',
// "#**general**"
'<p><a class="stream" data-stream-id="2" href="/#narrow/stream/2-general">'
'#general</a></p>',
const LinkNode(url: '/#narrow/stream/2-general',
nodes: [TextNode('#general')]));
testParseInline('parse #-mention of topic',
// "#**mobile-team>zulip-flutter**"
'<p><a class="stream-topic" data-stream-id="243" '
'href="/#narrow/stream/243-mobile-team/topic/zulip-flutter">'
'#mobile-team > zulip-flutter</a></p>',
const LinkNode(url: '/#narrow/stream/243-mobile-team/topic/zulip-flutter',
nodes: [TextNode('#mobile-team > zulip-flutter')]));
});
testParseInline('parse nested link, del, strong, em, code',
// "[~~***`word`***~~](https://example/)"
'<p><a href="https://example/"><del><strong><em><code>word'
'</code></em></strong></del></a></p>',
const LinkNode(url: 'https://example/',
nodes: [DeletedNode(nodes: [
StrongNode(nodes: [EmphasisNode(nodes: [InlineCodeNode(nodes: [
TextNode('word')])])])])]));
testParseInline('parse nested del, strong, em, link',
// "~~***[t](/u)***~~"
'<p><del><strong><em><a href="/u">t</a></em></strong></del></p>',
const DeletedNode(
nodes: [StrongNode(nodes: [EmphasisNode(nodes: [LinkNode(url: '/u',
nodes: [TextNode('t')])])])]));
group('parse @-mentions', () {
testParseExample(ContentExample.userMentionPlain);
testParseExample(ContentExample.userMentionSilent);
testParseExample(ContentExample.userMentionSilentClassOrderReversed);
testParseExample(ContentExample.groupMentionPlain);
testParseExample(ContentExample.groupMentionSilent);
testParseExample(ContentExample.groupMentionSilentClassOrderReversed);
// TODO test wildcard mentions
});
testParseExample(ContentExample.emojiUnicode);
testParseExample(ContentExample.emojiUnicodeClassesFlipped);
testParseExample(ContentExample.emojiUnicodeMultiCodepoint);
testParseExample(ContentExample.emojiUnicodeLiteral);
testParseExample(ContentExample.emojiCustom);
testParseExample(ContentExample.emojiCustomInvalidUrl);
testParseExample(ContentExample.emojiZulipExtra);
testParseExample(ContentExample.mathInline);
group('global times', () {
testParseExample(ContentExample.globalTime);
testParseInline('handles missing attribute',
// No markdown, this is unexpected response
'<p><time>2024-01-30T17:33:00Z</time></p>',
inlineUnimplemented('<time>2024-01-30T17:33:00Z</time>'),
);
testParseInline('handles DateTime.parse failure',
// No markdown, this is unexpected response
'<p><time datetime="2024">2024-01-30T17:33:00Z</time></p>',
inlineUnimplemented('<time datetime="2024">2024-01-30T17:33:00Z</time>'),