@tryghost/mg-tinynews 0.10.8-0 → 0.11.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +112 -30
  2. package/build/index.d.ts +8 -0
  3. package/build/index.js +5 -0
  4. package/build/index.js.map +1 -0
  5. package/build/lib/ingest.d.ts +18 -0
  6. package/build/lib/ingest.js +91 -0
  7. package/build/lib/ingest.js.map +1 -0
  8. package/build/lib/json-to-html.d.ts +35 -0
  9. package/build/lib/json-to-html.js +238 -0
  10. package/build/lib/json-to-html.js.map +1 -0
  11. package/build/lib/map.d.ts +26 -0
  12. package/build/lib/map.js +209 -0
  13. package/build/lib/map.js.map +1 -0
  14. package/build/lib/process.d.ts +76 -0
  15. package/build/lib/process.js +235 -0
  16. package/build/lib/process.js.map +1 -0
  17. package/build/lib/text.d.ts +6 -0
  18. package/build/lib/text.js +60 -0
  19. package/build/lib/text.js.map +1 -0
  20. package/build/lib/types.d.ts +112 -0
  21. package/build/lib/types.js +3 -0
  22. package/build/lib/types.js.map +1 -0
  23. package/build/test/helpers.d.ts +25 -0
  24. package/build/test/helpers.js +74 -0
  25. package/build/test/helpers.js.map +1 -0
  26. package/build/test/ingest.test.d.ts +1 -0
  27. package/build/test/ingest.test.js +134 -0
  28. package/build/test/ingest.test.js.map +1 -0
  29. package/build/test/json-to-html.test.d.ts +1 -0
  30. package/build/test/json-to-html.test.js +662 -0
  31. package/build/test/json-to-html.test.js.map +1 -0
  32. package/build/test/map.test.d.ts +1 -0
  33. package/build/test/map.test.js +367 -0
  34. package/build/test/map.test.js.map +1 -0
  35. package/build/test/process.test.d.ts +1 -0
  36. package/build/test/process.test.js +261 -0
  37. package/build/test/process.test.js.map +1 -0
  38. package/package.json +24 -10
  39. package/index.js +0 -7
  40. package/lib/json-to-html.js +0 -324
  41. package/lib/mapper.js +0 -368
  42. package/lib/text.js +0 -95
@@ -0,0 +1,662 @@
1
+ import assert from 'node:assert/strict';
2
+ import { describe, it } from 'node:test';
3
+ import { jsonToHtml, formatChildStyles, EntryList, EntryText, EntryImage, EntryHeading, EntryBlockquote, EntryHorizontalRule, EntryTwitterEmbed, EntryTikTokEmbed, EntryFacebookEmbed, EntryVimeoEmbed, EntryYoutubeEmbed, EntryApplePodcastsEmbed, EntryInstagramPostEmbed, EntryInstagramReelEmbed, EntryGoogleDocsEmbed, EntrySpotifyEmbed } from '../lib/json-to-html.js';
4
+ import { TextNode } from '../lib/text.js';
5
+ describe('JSON to HTML', function () {
6
+ it('Returns HTML if given HTML', function () {
7
+ const formatted = jsonToHtml('<p>Hello world</p>');
8
+ assert.equal(formatted, '<p>Hello world</p>');
9
+ });
10
+ describe('formatChildStyles', function () {
11
+ it('Bold', function () {
12
+ const childElement = {
13
+ style: {
14
+ bold: true
15
+ },
16
+ content: 'This sentence is bold.'
17
+ };
18
+ const formatted = formatChildStyles(childElement);
19
+ assert.equal(formatted, '<strong>This sentence is bold.</strong>');
20
+ });
21
+ it('Bold, italic and underlined', function () {
22
+ const childElement = {
23
+ style: {
24
+ bold: true,
25
+ italic: true,
26
+ underline: true
27
+ },
28
+ content: 'This sentence is bold, italic and underlined.'
29
+ };
30
+ const formatted = formatChildStyles(childElement);
31
+ assert.equal(formatted, '<strong><em><u>This sentence is bold, italic and underlined.</u></em></strong>');
32
+ });
33
+ it('A bold, italic and underlined link', function () {
34
+ const childElement = {
35
+ link: 'https://ghost.org',
36
+ style: {
37
+ bold: true,
38
+ italic: true,
39
+ underline: true
40
+ },
41
+ content: 'This link is bold, italic and underlined.'
42
+ };
43
+ const formatted = formatChildStyles(childElement);
44
+ assert.equal(formatted, '<a href="https://ghost.org"><strong><em><u>This link is bold, italic and underlined.</u></em></strong></a>');
45
+ });
46
+ });
47
+ describe('Title', function () {
48
+ it('Basic heading', function () {
49
+ const block = {
50
+ html: null,
51
+ link: null,
52
+ type: 'text',
53
+ style: 'TITLE',
54
+ children: [
55
+ {
56
+ index: 14,
57
+ style: {},
58
+ content: 'Lorem Ipsum'
59
+ }
60
+ ]
61
+ };
62
+ const formatted = EntryHeading(block);
63
+ assert.equal(formatted, '<h1>Lorem Ipsum </h1>');
64
+ });
65
+ });
66
+ describe('Subtitle', function () {
67
+ it('Basic heading', function () {
68
+ const block = {
69
+ html: null,
70
+ link: null,
71
+ type: 'text',
72
+ style: 'SUBTITLE',
73
+ children: [
74
+ {
75
+ index: 14,
76
+ style: {},
77
+ content: 'Lorem Ipsum'
78
+ }
79
+ ]
80
+ };
81
+ const formatted = EntryHeading(block);
82
+ assert.equal(formatted, '<h2>Lorem Ipsum </h2>');
83
+ });
84
+ });
85
+ describe('EntryHeading', function () {
86
+ it('Basic heading', function () {
87
+ const block = {
88
+ html: null,
89
+ link: null,
90
+ type: 'text',
91
+ style: 'HEADING_2',
92
+ children: [
93
+ {
94
+ style: {},
95
+ content: 'Heading 2'
96
+ }
97
+ ]
98
+ };
99
+ const formatted = EntryHeading(block);
100
+ assert.equal(formatted, '<h2>Heading 2 </h2>');
101
+ });
102
+ });
103
+ describe('EntryText', function () {
104
+ it('Paragraph with basic text', function () {
105
+ const block = {
106
+ html: null,
107
+ link: null,
108
+ type: 'text',
109
+ style: 'NORMAL_TEXT',
110
+ children: [
111
+ {
112
+ style: {},
113
+ content: 'This is a sentence in bold.'
114
+ },
115
+ {
116
+ style: {},
117
+ content: ''
118
+ },
119
+ {
120
+ style: {},
121
+ content: 'This is a sentence in italics.'
122
+ },
123
+ {
124
+ style: {},
125
+ content: ''
126
+ },
127
+ {
128
+ style: {},
129
+ content: 'This sentence is underlined.'
130
+ },
131
+ {
132
+ style: {},
133
+ content: ''
134
+ },
135
+ {
136
+ style: {},
137
+ content: 'This sentence is bold, italic and underlined.'
138
+ },
139
+ {
140
+ style: {},
141
+ content: ''
142
+ },
143
+ {
144
+ style: {},
145
+ content: 'This is a multi word link.'
146
+ },
147
+ {
148
+ style: {},
149
+ content: 'This is a plain sentence.'
150
+ }
151
+ ]
152
+ };
153
+ const formatted = EntryText(block);
154
+ assert.equal(formatted, '<p>This is a sentence in bold. This is a sentence in italics. This sentence is underlined. This sentence is bold, italic and underlined. This is a multi word link. This is a plain sentence. </p>');
155
+ });
156
+ it('Paragraph with styles & links', function () {
157
+ const block = {
158
+ html: null,
159
+ link: null,
160
+ type: 'text',
161
+ style: 'NORMAL_TEXT',
162
+ children: [
163
+ {
164
+ style: {
165
+ bold: true
166
+ },
167
+ content: 'This is a sentence in bold.'
168
+ },
169
+ {
170
+ style: {},
171
+ content: ''
172
+ },
173
+ {
174
+ style: {
175
+ italic: true
176
+ },
177
+ content: 'This is a sentence in italics.'
178
+ },
179
+ {
180
+ style: {},
181
+ content: ''
182
+ },
183
+ {
184
+ style: {
185
+ underline: true
186
+ },
187
+ content: 'This sentence is underlined.'
188
+ },
189
+ {
190
+ style: {},
191
+ content: ''
192
+ },
193
+ {
194
+ style: {
195
+ bold: true,
196
+ italic: true,
197
+ underline: true
198
+ },
199
+ content: 'This sentence is bold, italic and underlined.'
200
+ },
201
+ {
202
+ style: {},
203
+ content: ''
204
+ },
205
+ {
206
+ link: 'https://example.com/',
207
+ style: {
208
+ underline: true
209
+ },
210
+ content: 'This is a multi word link.'
211
+ },
212
+ {
213
+ style: {},
214
+ content: 'This is a plain sentence.'
215
+ }
216
+ ]
217
+ };
218
+ const formatted = EntryText(block);
219
+ assert.equal(formatted, '<p><strong>This is a sentence in bold. </strong> <em>This is a sentence in italics. </em> <u>This sentence is underlined. </u> <strong><em> <u>This sentence is bold, italic and underlined. </u> </em> </strong> <a href="https://example.com/">This is a multi word link.</a> This is a plain sentence. </p>');
220
+ });
221
+ it('Handles spaces correctly for page content', function () {
222
+ const block = {
223
+ html: null,
224
+ link: null,
225
+ type: 'text',
226
+ style: 'NORMAL_TEXT',
227
+ children: [
228
+ {
229
+ index: 435,
230
+ style: {},
231
+ content: 'Donate'
232
+ },
233
+ {
234
+ link: 'https://example.com/donate',
235
+ index: 439,
236
+ style: {
237
+ underline: true
238
+ },
239
+ content: 'here'
240
+ },
241
+ {
242
+ index: 451,
243
+ style: {},
244
+ content: '. Subscribe'
245
+ },
246
+ {
247
+ link: 'https://example.com/subscribe',
248
+ index: 455,
249
+ style: {
250
+ underline: true
251
+ },
252
+ content: 'here'
253
+ },
254
+ {
255
+ index: 458,
256
+ style: {},
257
+ content: '.'
258
+ }
259
+ ]
260
+ };
261
+ const formatted = EntryText(block);
262
+ assert.equal(formatted, '<p>Donate <a href="https://example.com/donate">here</a>. Subscribe <a href="https://example.com/subscribe">here</a>. </p>');
263
+ });
264
+ });
265
+ describe('EntryList', function () {
266
+ it('Unordered list', function () {
267
+ const block = {
268
+ html: null,
269
+ link: null,
270
+ type: 'list',
271
+ items: [
272
+ {
273
+ children: [
274
+ {
275
+ style: {},
276
+ content: 'Pellentesque eu quam eget orci varius vitae dui.'
277
+ }
278
+ ],
279
+ nestingLevel: 0
280
+ },
281
+ {
282
+ children: [
283
+ {
284
+ style: {},
285
+ content: 'Maecenas pretium convallis nunc non hendrerit.'
286
+ }
287
+ ],
288
+ nestingLevel: 0
289
+ },
290
+ {
291
+ children: [
292
+ {
293
+ style: {},
294
+ content: 'Vivamus congue, odio in placerat consequat, ex lorem venenatis risus, ut pretium felis nunc sit amet erat.'
295
+ }
296
+ ],
297
+ nestingLevel: 0
298
+ }
299
+ ],
300
+ listType: 'BULLET'
301
+ };
302
+ const formatted = EntryList(block);
303
+ assert.equal(formatted, '<ul><li>Pellentesque eu quam eget orci varius vitae dui.</li><li>Maecenas pretium convallis nunc non hendrerit.</li><li>Vivamus congue, odio in placerat consequat, ex lorem venenatis risus, ut pretium felis nunc sit amet erat.</li></ul>');
304
+ });
305
+ it('Ordered list', function () {
306
+ const block = {
307
+ html: null,
308
+ link: null,
309
+ type: 'list',
310
+ items: [
311
+ {
312
+ children: [
313
+ {
314
+ style: {},
315
+ content: 'Pellentesque eu quam eget orci varius vitae dui.'
316
+ }
317
+ ],
318
+ nestingLevel: 0
319
+ },
320
+ {
321
+ children: [
322
+ {
323
+ style: {},
324
+ content: 'Maecenas pretium convallis nunc non hendrerit.'
325
+ }
326
+ ],
327
+ nestingLevel: 0
328
+ },
329
+ {
330
+ children: [
331
+ {
332
+ style: {},
333
+ content: 'Vivamus congue, odio in placerat consequat, ex lorem venenatis risus, ut pretium felis nunc sit amet erat.'
334
+ }
335
+ ],
336
+ nestingLevel: 0
337
+ }
338
+ ],
339
+ listType: 'NUMBER'
340
+ };
341
+ const formatted = EntryList(block);
342
+ assert.equal(formatted, '<ol><li>Pellentesque eu quam eget orci varius vitae dui.</li><li>Maecenas pretium convallis nunc non hendrerit.</li><li>Vivamus congue, odio in placerat consequat, ex lorem venenatis risus, ut pretium felis nunc sit amet erat.</li></ol>');
343
+ });
344
+ });
345
+ describe('EntryImage', function () {
346
+ it('Basic image', function () {
347
+ const block = {
348
+ link: null,
349
+ type: 'image',
350
+ children: [
351
+ {
352
+ index: 1123,
353
+ width: 746,
354
+ height: 850,
355
+ imageId: '1234',
356
+ imageAlt: null,
357
+ imageUrl: 'https://example.com/image.1234.jpg'
358
+ }
359
+ ]
360
+ };
361
+ const formatted = EntryImage(block);
362
+ assert.equal(formatted, '<figure class="kg-card kg-image-card"><img src="https://example.com/image.1234.jpg" class="kg-image" alt loading="lazy"></figure>');
363
+ });
364
+ it('Linked image with caption', function () {
365
+ const block = {
366
+ link: 'https://ghost.org',
367
+ type: 'image',
368
+ children: [
369
+ {
370
+ index: 1123,
371
+ width: 746,
372
+ height: 850,
373
+ imageId: '1234',
374
+ imageAlt: 'Lorem ipsum',
375
+ imageUrl: 'https://example.com/image.1234.jpg'
376
+ }
377
+ ]
378
+ };
379
+ const formatted = EntryImage(block);
380
+ assert.equal(formatted, '<figure class="kg-card kg-image-card kg-card-hascaption"><a href="https://ghost.org"><img src="https://example.com/image.1234.jpg" class="kg-image" alt="Lorem ipsum" loading="lazy"></a><figcaption>Lorem ipsum</figcaption></figure>');
381
+ });
382
+ });
383
+ describe('EntryBlockquote', function () {
384
+ it('Make HR', function () {
385
+ const block = {
386
+ html: null,
387
+ link: null,
388
+ type: 'blockquote',
389
+ style: 'NORMAL_TEXT',
390
+ children: [
391
+ {
392
+ style: {},
393
+ content: 'Lorem ipsum'
394
+ }
395
+ ]
396
+ };
397
+ const formatted = EntryBlockquote(block);
398
+ assert.equal(formatted, '<blockquote><p>Lorem ipsum</p></blockquote>');
399
+ });
400
+ });
401
+ describe('EntryHorizontalRule', function () {
402
+ it('Make HR', function () {
403
+ const block = {
404
+ type: 'hr',
405
+ children: []
406
+ };
407
+ const formatted = EntryHorizontalRule(block);
408
+ assert.equal(formatted, '<hr>');
409
+ });
410
+ });
411
+ });
412
+ describe('Embeds', function () {
413
+ it('Twitter', function () {
414
+ const block = {
415
+ html: null,
416
+ link: 'https://twitter.com/Example/status/12345678240918675457?s=20&t=abcd12345jQ3oSayj4TNRQ',
417
+ type: 'embed',
418
+ children: []
419
+ };
420
+ const formatted = EntryTwitterEmbed(block);
421
+ assert.equal(formatted, '<figure class="kg-card kg-embed-card"><blockquote class="twitter-tweet"><a href="https://twitter.com/Example/status/12345678240918675457?s=20&t=abcd12345jQ3oSayj4TNRQ"></a></blockquote><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></figure>');
422
+ });
423
+ it('TikTok', function () {
424
+ const block = {
425
+ html: null,
426
+ link: 'https://www.tiktok.com/@example/video/1234567857666835739?is_from_webapp=1&sender_device=pc',
427
+ type: 'embed',
428
+ children: []
429
+ };
430
+ const formatted = EntryTikTokEmbed(block);
431
+ assert.equal(formatted, '<figure class="kg-card kg-embed-card"><blockquote class="tiktok-embed" cite="https://www.tiktok.com/@example/video/1234567857666835739" data-video-id="1234567857666835739" style="max-width: 605px;min-width: 325px;"><section><a target="_blank" title="@example" href="https://www.tiktok.com/@example?refer=embed">@example</a></section></blockquote><script async src="https://www.tiktok.com/embed.js"></script></figure>');
432
+ });
433
+ it('Facebook (link)', function () {
434
+ const block = {
435
+ html: null,
436
+ link: 'https://www.facebook.com/example/posts/12345678abcdergh',
437
+ type: 'embed',
438
+ children: []
439
+ };
440
+ const formatted = EntryFacebookEmbed(block);
441
+ assert.equal(formatted, '<p><a href="https://www.facebook.com/example/posts/12345678abcdergh">https://www.facebook.com/example/posts/12345678abcdergh</a></p>');
442
+ });
443
+ it('Facebook (html)', function () {
444
+ const block = {
445
+ html: '<div class="fb-post" data-href="https://www.facebook.com/example/posts/12345678abcdergh" data-width="552"><blockquote cite="https://graph.facebook.com/123456782492602/posts/9876543278806123/" class="fb-xfbml-parse-ignore">Posted by <a href="https://www.facebook.com/example">Example</a> on&nbsp;<a href="https://graph.facebook.com/123456782492602/posts/9876543278806123/">Saturday, August 20, 2022</a></blockquote></div>',
446
+ link: 'https://www.facebook.com/example/posts/12345678abcdergh',
447
+ type: 'embed',
448
+ children: []
449
+ };
450
+ const formatted = EntryFacebookEmbed(block);
451
+ assert.equal(formatted, '<!--kg-card-begin: html--><div class="fb-post" data-href="https://www.facebook.com/example/posts/12345678abcdergh" data-width="552"><blockquote cite="https://graph.facebook.com/123456782492602/posts/9876543278806123/" class="fb-xfbml-parse-ignore">Posted by <a href="https://www.facebook.com/example">Example</a> on&nbsp;<a href="https://graph.facebook.com/123456782492602/posts/9876543278806123/">Saturday, August 20, 2022</a></blockquote></div><!--kg-card-end: html-->');
452
+ });
453
+ it('Vimeo', function () {
454
+ const block = {
455
+ html: null,
456
+ link: 'https://vimeo.com/723429393',
457
+ type: 'embed',
458
+ children: []
459
+ };
460
+ const formatted = EntryVimeoEmbed(block);
461
+ assert.equal(formatted, '<iframe src="https://player.vimeo.com/video/723429393" width="160" height="90" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>');
462
+ });
463
+ it('YouTube (youtube.com)', function () {
464
+ const block = {
465
+ html: null,
466
+ link: 'https://www.youtube.com/watch?v=n_abcd12345',
467
+ type: 'embed',
468
+ children: []
469
+ };
470
+ const formatted = EntryYoutubeEmbed(block);
471
+ assert.equal(formatted, '<iframe width="160" height="90" src="https://www.youtube.com/embed/n_abcd12345" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>');
472
+ });
473
+ it('YouTube (youtu.be)', function () {
474
+ const block = {
475
+ html: null,
476
+ link: 'https://youtu.be/n_abcd12345',
477
+ type: 'embed',
478
+ children: []
479
+ };
480
+ const formatted = EntryYoutubeEmbed(block);
481
+ assert.equal(formatted, '<iframe width="160" height="90" src="https://www.youtube.com/embed/n_abcd12345" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>');
482
+ });
483
+ it('Apple Podcast', function () {
484
+ const block = {
485
+ html: null,
486
+ link: 'https://podcasts.apple.com/us/podcast/example/id12345678',
487
+ type: 'embed',
488
+ children: []
489
+ };
490
+ const formatted = EntryApplePodcastsEmbed(block);
491
+ assert.equal(formatted, '<iframe allow="autoplay *; encrypted-media *; fullscreen *; clipboard-write" frameborder="0" height="450" style="width:100%;max-width:660px;overflow:hidden;border-radius:10px;" sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-storage-access-by-user-activation allow-top-navigation-by-user-activation" src="https://embed.podcasts.apple.com/us/podcast/example/id12345678"></iframe>');
492
+ });
493
+ it('Instagram Post', function () {
494
+ const block = {
495
+ html: null,
496
+ link: 'https://www.instagram.com/p/abcd1234567/',
497
+ type: 'embed',
498
+ children: []
499
+ };
500
+ const formatted = EntryInstagramPostEmbed(block);
501
+ assert.equal(formatted, '<iframe src="https://www.instagram.com/p/abcd1234567/embed/captioned/" class="instagram-media" allowtransparency="true" allowfullscreen="true" frameborder="0" scrolling="no" style="background: white; max-width: 658px; width: calc(100% - 2px); border-radius: 3px; border: 1px solid rgb(219, 219, 219); box-shadow: none; display: block; margin: 0px; min-width: 326px; padding: 0px;"></iframe><script async="" src="//www.instagram.com/embed.js"></script>');
502
+ });
503
+ it('Instagram Reel', function () {
504
+ const block = {
505
+ html: null,
506
+ link: 'https://www.instagram.com/reel/CqvvNv1NAFw/',
507
+ type: 'embed',
508
+ children: []
509
+ };
510
+ const formatted = EntryInstagramReelEmbed(block);
511
+ assert.equal(formatted, '<iframe class="instagram-media" src="https://www.instagram.com/reel/CqvvNv1NAFw/embed/captioned/" allowtransparency="true" allowfullscreen="true" frameborder="0" scrolling="no" style="background: white; max-width: 540px; width: calc(100% - 2px); border-radius: 3px; border: 1px solid rgb(219, 219, 219); box-shadow: none; display: block; margin: 0px; min-width: 326px; padding: 0px; position: relative;"></iframe><script async="" src="//www.instagram.com/embed.js"></script>');
512
+ });
513
+ it('Google Docs', function () {
514
+ const block = {
515
+ html: null,
516
+ link: 'https://docs.google.com/forms/d/e/12345678abcdefghyQHFRldkioVOLrwqofXDjTJFMgH5nnZN93xt0oA/viewform?embedded=true',
517
+ type: 'embed',
518
+ children: []
519
+ };
520
+ const formatted = EntryGoogleDocsEmbed(block);
521
+ assert.equal(formatted, '<iframe class="googledocs-embed" src="https://docs.google.com/forms/d/e/12345678abcdefghyQHFRldkioVOLrwqofXDjTJFMgH5nnZN93xt0oA/viewform?embedded=true" allowtransparency="true" allowfullscreen="true" frameborder="0" style="width: 100%; height: 500px;"></iframe>');
522
+ });
523
+ });
524
+ describe('Embeds without the parts they need', function () {
525
+ it('Link TikTok and Vimeo embeds without a video', function () {
526
+ assert.equal(EntryTikTokEmbed({ link: 'https://www.tiktok.com/discover' }), '<p><a href="https://www.tiktok.com/discover">https://www.tiktok.com/discover</a></p>');
527
+ assert.equal(EntryVimeoEmbed({ link: 'https://vimeo.com/channels' }), '<p><a href="https://vimeo.com/channels">https://vimeo.com/channels</a></p>');
528
+ });
529
+ it('Embeds YouTube links without a video ID as they are', function () {
530
+ assert.match(EntryYoutubeEmbed({ link: 'https://www.youtube.com/live' }), /src="https:\/\/www\.youtube\.com\/embed\/https:\/\/www\.youtube\.com\/live"/);
531
+ });
532
+ it('Spotify episodes and shows', function () {
533
+ assert.equal(EntrySpotifyEmbed({ link: 'https://open.spotify.com/episode/abc' }), '<iframe src="https://open.spotify.com/embed/episode/abc" width="300" height="380" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>');
534
+ assert.match(EntrySpotifyEmbed({ link: 'https://open.spotify.com/show/def' }), /src="https:\/\/open\.spotify\.com\/embed\/show\/def"/);
535
+ });
536
+ });
537
+ describe('Blocks with missing parts', function () {
538
+ it('Formats children without styles or content', function () {
539
+ assert.equal(formatChildStyles({}), '');
540
+ assert.equal(formatChildStyles({ content: 'Plain', link: 'https://example.com' }), '<a href="https://example.com">Plain</a>');
541
+ });
542
+ it('Converts lists, images and quotes without children to nothing', function () {
543
+ assert.equal(EntryList({ listType: 'NUMBER' }), '<ol></ol>');
544
+ assert.equal(EntryList({ items: [{}, { children: [{ content: 'One' }] }] }), '<ul><li>One</li></ul>');
545
+ assert.equal(EntryImage({}), '');
546
+ assert.equal(EntryImage({ children: [] }), '');
547
+ assert.equal(EntryBlockquote({}), '');
548
+ assert.equal(EntryBlockquote({ children: [{ content: ' ' }, {}] }), '');
549
+ assert.equal(EntryBlockquote({ children: [{ content: ' ' }, { content: 'Quote', style: { italic: true } }] }), '<blockquote><p><em>Quote</em></p></blockquote>');
550
+ });
551
+ it('Converts text blocks by style', function () {
552
+ const children = [{ content: 'Text', style: {} }];
553
+ assert.equal(TextNode({ node: { style: 'HEADING_4', children } }), '<h4>Text </h4>');
554
+ assert.equal(TextNode({ node: { style: 'FORMATTED_TEXT', children } }), '<pre>Text </pre>');
555
+ assert.equal(TextNode({ node: { children } }), 'Text ');
556
+ assert.equal(TextNode({ node: { style: 'NORMAL_TEXT' } }), null);
557
+ assert.equal(TextNode({ node: { style: 'NORMAL_TEXT', children: [{ content: 'FORMAT START' }, { content: '' }] } }), null);
558
+ });
559
+ it('Breaks lines for blank children and doubles spaces after children without styles', function () {
560
+ assert.equal(TextNode({
561
+ node: {
562
+ style: 'NORMAL_TEXT',
563
+ children: [
564
+ { content: ' ', style: {} },
565
+ { content: 'After', style: {} }
566
+ ]
567
+ }
568
+ }), '<p><br />After </p>');
569
+ assert.equal(TextNode({
570
+ node: {
571
+ style: 'NORMAL_TEXT',
572
+ children: [
573
+ { content: ' ', style: {} },
574
+ { content: ' ', style: {} }
575
+ ]
576
+ }
577
+ }), '<p> </p>');
578
+ assert.equal(TextNode({ node: { style: 'NORMAL_TEXT', children: [{ content: ' ', style: {} }] } }), '<p> </p>');
579
+ assert.equal(TextNode({ node: { style: 'NORMAL_TEXT', children: [{ content: 'Unstyled' }] } }), '<p>Unstyled </p>');
580
+ assert.equal(TextNode({ node: { style: 'NORMAL_TEXT', children: [{ content: 'Link', link: 'https://example.com' }] } }), '<p> <a href="https://example.com">Link</a> </p>');
581
+ });
582
+ });
583
+ describe('jsonToHtml', function () {
584
+ it('Converts every supported block and embed, skipping main images', function () {
585
+ const embed = (link) => ({ type: 'embed', link });
586
+ const blocks = [
587
+ { type: 'mainImage', children: [{ imageUrl: 'https://example.com/main.jpg' }] },
588
+ { type: 'text', style: 'TITLE', children: [{ content: 'Title', style: {} }] },
589
+ { type: 'text', style: 'NORMAL_TEXT', children: [{ content: 'Text', style: {} }] },
590
+ { type: 'blockquote', children: [{ content: 'Quote', style: {} }] },
591
+ { type: 'hr' },
592
+ { type: 'list', items: [{ children: [{ content: 'Item', style: {} }] }] },
593
+ { type: 'image', children: [{ imageUrl: 'https://example.com/image.jpg', imageAlt: 'Alt' }] },
594
+ embed('https://twitter.com/example/status/1'),
595
+ embed('https://www.tiktok.com/@example/video/1234567890123'),
596
+ embed('https://www.facebook.com/example/posts/1'),
597
+ embed('https://vimeo.com/123456'),
598
+ embed('https://www.youtube.com/watch?v=abc123'),
599
+ embed('https://youtu.be/def456'),
600
+ embed('https://podcasts.apple.com/us/podcast/example/id1'),
601
+ embed('https://open.spotify.com/episode/abc'),
602
+ embed('https://open.spotify.com/show/def'),
603
+ embed('https://www.instagram.com/p/abc/'),
604
+ embed('https://www.instagram.com/reel/def/'),
605
+ embed('https://docs.google.com/forms/d/e/abc/viewform')
606
+ ];
607
+ const reasons = [];
608
+ const html = jsonToHtml(blocks, { onUnhandled: reason => reasons.push(reason) });
609
+ assert.deepEqual(reasons, []);
610
+ assert.ok(!html.includes('main.jpg'));
611
+ for (const expected of [
612
+ '<h1>Title </h1><p>Text </p><blockquote><p>Quote</p></blockquote><hr><ul><li>Item</li></ul>',
613
+ 'src="https://example.com/image.jpg"',
614
+ 'class="twitter-tweet"',
615
+ 'class="tiktok-embed"',
616
+ '<p><a href="https://www.facebook.com/example/posts/1">',
617
+ 'https://player.vimeo.com/video/123456',
618
+ 'https://www.youtube.com/embed/abc123',
619
+ 'https://www.youtube.com/embed/def456',
620
+ 'https://embed.podcasts.apple.com/us/podcast/example/id1',
621
+ 'https://open.spotify.com/embed/episode/abc',
622
+ 'https://open.spotify.com/embed/show/def',
623
+ 'src="https://www.instagram.com/p/abc/embed/captioned/" class="instagram-media"',
624
+ 'class="instagram-media" src="https://www.instagram.com/reel/def/embed/captioned/"',
625
+ 'class="googledocs-embed"'
626
+ ]) {
627
+ assert.ok(html.includes(expected), expected);
628
+ }
629
+ });
630
+ it('Leaves out blocks it cannot convert, passing them to onUnhandled', function () {
631
+ const blocks = [
632
+ { type: 'text', style: 'FORMATTED_TEXT', children: [{ content: 'Code' }] },
633
+ { type: 'text', children: [{ content: 'No style' }] },
634
+ { type: 'embed', link: 'https://open.spotify.com/track/abc' },
635
+ { type: 'embed', link: 'https://www.instagram.com/stories/abc/' },
636
+ { type: 'embed', link: 'https://example.com/embed' },
637
+ { type: 'embed', link: 'not a url' },
638
+ { type: 'embed', link: null },
639
+ { type: 'table' },
640
+ { children: [] },
641
+ { type: 'text', style: 'NORMAL_TEXT', children: [{ content: 'Kept', style: {} }] }
642
+ ];
643
+ const unhandled = [];
644
+ const html = jsonToHtml(blocks, { onUnhandled: (reason, block) => unhandled.push([reason, block]) });
645
+ assert.equal(html, '<p>Kept </p>');
646
+ assert.deepEqual(unhandled.map(([reason]) => reason), [
647
+ 'Unhandled text style: FORMATTED_TEXT',
648
+ 'Unhandled text style: null',
649
+ 'Unhandled embed: https://open.spotify.com/track/abc',
650
+ 'Unhandled embed: https://www.instagram.com/stories/abc/',
651
+ 'Unhandled embed: https://example.com/embed',
652
+ 'Unhandled embed: not a url',
653
+ 'Unhandled embed: null',
654
+ 'Unhandled block type: table',
655
+ 'Unhandled block type: null'
656
+ ]);
657
+ assert.equal(unhandled[7][1], blocks[7]);
658
+ assert.equal(jsonToHtml(blocks), '<p>Kept </p>');
659
+ assert.equal(jsonToHtml(null), '');
660
+ });
661
+ });
662
+ //# sourceMappingURL=json-to-html.test.js.map