kramdown-prismic 0.3.0 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module KramdownPrismic
2
- VERSION = "0.3.0"
4
+ VERSION = '0.3.4'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'kramdown'
2
4
 
3
5
  require 'kramdown/parser/prismic'
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  require 'minitest/autorun'
3
5
  require 'kramdown-prismic'
4
6
 
@@ -9,12 +11,12 @@ class KramdownPrismicConverterTest < Minitest::Test
9
11
  {
10
12
  type: "heading#{heading + 1}",
11
13
  content: {
12
- text: "This is the document title",
14
+ text: 'This is the document title',
13
15
  spans: []
14
16
  }
15
17
  }
16
18
  ]
17
- markdown = "#{"#" * (heading + 1)} This is the document title"
19
+ markdown = "#{'#' * (heading + 1)} This is the document title"
18
20
  assert_equal expected, Kramdown::Document.new(markdown, input: :kramdown).to_prismic
19
21
  end
20
22
  end
@@ -22,26 +24,26 @@ class KramdownPrismicConverterTest < Minitest::Test
22
24
  def test_convert_heading7
23
25
  expected = [
24
26
  {
25
- type: "heading6",
27
+ type: 'heading6',
26
28
  content: {
27
- text: "# This is the document title",
29
+ text: '# This is the document title',
28
30
  spans: []
29
31
  }
30
32
  }
31
33
  ]
32
- markdown = "####### This is the document title"
34
+ markdown = '####### This is the document title'
33
35
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
34
36
  end
35
37
 
36
38
  def test_convert_heading_with_spans
37
39
  expected = [
38
40
  {
39
- type: "heading2",
41
+ type: 'heading2',
40
42
  content: {
41
- text: "This is a document title",
43
+ text: 'This is a document title',
42
44
  spans: [
43
45
  {
44
- type: "em",
46
+ type: 'em',
45
47
  start: 0,
46
48
  end: 4
47
49
  }
@@ -49,56 +51,56 @@ class KramdownPrismicConverterTest < Minitest::Test
49
51
  }
50
52
  }
51
53
  ]
52
- markdown = "## *This* is a document title"
54
+ markdown = '## *This* is a document title'
53
55
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
54
56
  end
55
57
 
56
58
  def test_convert_paragraph
57
59
  expected = [
58
60
  {
59
- type: "paragraph",
61
+ type: 'paragraph',
60
62
  content: {
61
- text: "This is a paragraph",
63
+ text: 'This is a paragraph',
62
64
  spans: []
63
65
  }
64
66
  }
65
67
  ]
66
- markdown = "This is a paragraph"
68
+ markdown = 'This is a paragraph'
67
69
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
68
70
  end
69
71
 
70
72
  def test_convert_paragraph_with_spans
71
73
  expected = [
72
74
  {
73
- type: "paragraph",
75
+ type: 'paragraph',
74
76
  content: {
75
- text: "This is a paragraph",
77
+ text: 'This is a paragraph',
76
78
  spans: [
77
79
  {
78
- type: "hyperlink",
80
+ type: 'hyperlink',
79
81
  start: 0,
80
82
  end: 19,
81
83
  data: {
82
- url: "https://prismic.io"
84
+ url: 'https://prismic.io'
83
85
  }
84
86
  }
85
87
  ]
86
88
  }
87
89
  }
88
90
  ]
89
- markdown = "[This is a paragraph](https://prismic.io)"
91
+ markdown = '[This is a paragraph](https://prismic.io)'
90
92
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
91
93
  end
92
94
 
93
95
  def test_convert_paragraph_with_strong
94
96
  expected = [
95
97
  {
96
- type: "paragraph",
98
+ type: 'paragraph',
97
99
  content: {
98
- text: "This is a paragraph",
100
+ text: 'This is a paragraph',
99
101
  spans: [
100
102
  {
101
- type: "strong",
103
+ type: 'strong',
102
104
  start: 0,
103
105
  end: 19
104
106
  }
@@ -106,19 +108,19 @@ class KramdownPrismicConverterTest < Minitest::Test
106
108
  }
107
109
  }
108
110
  ]
109
- markdown = "**This is a paragraph**"
111
+ markdown = '**This is a paragraph**'
110
112
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
111
113
  end
112
114
 
113
115
  def test_convert_paragraph_with_strong2
114
116
  expected = [
115
117
  {
116
- type: "paragraph",
118
+ type: 'paragraph',
117
119
  content: {
118
- text: "This is a paragraph",
120
+ text: 'This is a paragraph',
119
121
  spans: [
120
122
  {
121
- type: "strong",
123
+ type: 'strong',
122
124
  start: 0,
123
125
  end: 4
124
126
  }
@@ -126,19 +128,39 @@ class KramdownPrismicConverterTest < Minitest::Test
126
128
  }
127
129
  }
128
130
  ]
129
- markdown = "**This** is a paragraph"
131
+ markdown = '**This** is a paragraph'
130
132
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
131
133
  end
132
134
 
135
+ def test_convert_html_strong
136
+ expected = [
137
+ {
138
+ type: 'paragraph',
139
+ content: {
140
+ text: 'This is a paragraph',
141
+ spans: [
142
+ {
143
+ type: 'strong',
144
+ start: 0,
145
+ end: 19
146
+ }
147
+ ]
148
+ }
149
+ }
150
+ ]
151
+ markdown = '<strong>This is a paragraph</strong>'
152
+ assert_equal expected, Kramdown::Document.new(markdown, input: :html).to_prismic
153
+ end
154
+
133
155
  def test_convert_paragraph_with_em
134
156
  expected = [
135
157
  {
136
- type: "paragraph",
158
+ type: 'paragraph',
137
159
  content: {
138
- text: "This is a paragraph",
160
+ text: 'This is a paragraph',
139
161
  spans: [
140
162
  {
141
- type: "em",
163
+ type: 'em',
142
164
  start: 0,
143
165
  end: 4
144
166
  }
@@ -146,19 +168,39 @@ class KramdownPrismicConverterTest < Minitest::Test
146
168
  }
147
169
  }
148
170
  ]
149
- markdown = "*This* is a paragraph"
171
+ markdown = '*This* is a paragraph'
150
172
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
151
173
  end
152
174
 
175
+ def test_convert_html_em
176
+ expected = [
177
+ {
178
+ type: 'paragraph',
179
+ content: {
180
+ text: 'This',
181
+ spans: [
182
+ {
183
+ type: 'em',
184
+ start: 0,
185
+ end: 4
186
+ }
187
+ ]
188
+ }
189
+ }
190
+ ]
191
+ markdown = '<em>This</em>'
192
+ assert_equal expected, Kramdown::Document.new(markdown, input: :html).to_prismic
193
+ end
194
+
153
195
  def test_convert_list_o
154
196
  expected = [
155
197
  {
156
- type: "o-list-item",
198
+ type: 'o-list-item',
157
199
  content: {
158
- text: "This is a list item",
200
+ text: 'This is a list item',
159
201
  spans: [
160
202
  {
161
- type: "em",
203
+ type: 'em',
162
204
  start: 0,
163
205
  end: 4
164
206
  }
@@ -166,9 +208,9 @@ class KramdownPrismicConverterTest < Minitest::Test
166
208
  }
167
209
  },
168
210
  {
169
- type: "o-list-item",
211
+ type: 'o-list-item',
170
212
  content: {
171
- text: "This is a second list item",
213
+ text: 'This is a second list item',
172
214
  spans: []
173
215
  }
174
216
  }
@@ -180,12 +222,12 @@ class KramdownPrismicConverterTest < Minitest::Test
180
222
  def test_convert_list_u
181
223
  expected = [
182
224
  {
183
- type: "list-item",
225
+ type: 'list-item',
184
226
  content: {
185
- text: "This is a list item",
227
+ text: 'This is a list item',
186
228
  spans: [
187
229
  {
188
- type: "em",
230
+ type: 'em',
189
231
  start: 0,
190
232
  end: 4
191
233
  }
@@ -193,9 +235,9 @@ class KramdownPrismicConverterTest < Minitest::Test
193
235
  }
194
236
  },
195
237
  {
196
- type: "list-item",
238
+ type: 'list-item',
197
239
  content: {
198
- text: "This is a second list item",
240
+ text: 'This is a second list item',
199
241
  spans: []
200
242
  }
201
243
  }
@@ -207,16 +249,16 @@ class KramdownPrismicConverterTest < Minitest::Test
207
249
  def test_convert_nested_ul
208
250
  expected = [
209
251
  {
210
- type: "list-item",
252
+ type: 'list-item',
211
253
  content: {
212
254
  text: "item1\n",
213
255
  spans: []
214
256
  }
215
257
  },
216
258
  {
217
- type: "list-item",
259
+ type: 'list-item',
218
260
  content: {
219
- text: "item2",
261
+ text: 'item2',
220
262
  spans: []
221
263
  }
222
264
  }
@@ -230,23 +272,23 @@ class KramdownPrismicConverterTest < Minitest::Test
230
272
  def test_convert_nested_nested_ul
231
273
  expected = [
232
274
  {
233
- type: "list-item",
275
+ type: 'list-item',
234
276
  content: {
235
277
  text: "item1\n",
236
278
  spans: []
237
279
  }
238
280
  },
239
281
  {
240
- type: "list-item",
282
+ type: 'list-item',
241
283
  content: {
242
284
  text: "item2\n",
243
285
  spans: []
244
286
  }
245
287
  },
246
288
  {
247
- type: "list-item",
289
+ type: 'list-item',
248
290
  content: {
249
- text: "item3",
291
+ text: 'item3',
250
292
  spans: []
251
293
  }
252
294
  }
@@ -260,7 +302,7 @@ class KramdownPrismicConverterTest < Minitest::Test
260
302
  def test_convert_preformatted
261
303
  expected = [
262
304
  {
263
- type: "preformatted",
305
+ type: 'preformatted',
264
306
  content: {
265
307
  text: "This is a pre block\n",
266
308
  spans: []
@@ -274,9 +316,9 @@ class KramdownPrismicConverterTest < Minitest::Test
274
316
  def test_convert_blockquote
275
317
  expected = [
276
318
  {
277
- type: "preformatted",
319
+ type: 'preformatted',
278
320
  content: {
279
- text: "This is a blockquote",
321
+ text: 'This is a blockquote',
280
322
  spans: []
281
323
  }
282
324
  }
@@ -287,17 +329,18 @@ class KramdownPrismicConverterTest < Minitest::Test
287
329
 
288
330
  def test_convert_empty
289
331
  expected = []
290
- markdown = ""
332
+ markdown = ''
291
333
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
292
334
  end
293
335
 
294
336
  def test_convert_span_blank
295
337
  expected = [
296
- {type: "o-list-item",
297
- content: {
298
- text: "Testtest",
299
- spans: []
300
- }
338
+ {
339
+ type: 'o-list-item',
340
+ content: {
341
+ text: 'Testtest',
342
+ spans: []
343
+ }
301
344
  }
302
345
  ]
303
346
  markdown = "\n1. Test\n\n test\n"
@@ -306,16 +349,16 @@ class KramdownPrismicConverterTest < Minitest::Test
306
349
 
307
350
  def test_convert_hr
308
351
  expected = []
309
- markdown = "---"
352
+ markdown = '---'
310
353
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
311
354
  end
312
355
 
313
356
  def test_convert_img
314
357
  expected = [
315
358
  {
316
- type: "image",
359
+ type: 'image',
317
360
  content: {
318
- text: "",
361
+ text: '',
319
362
  spans: []
320
363
  },
321
364
  data: {
@@ -326,7 +369,7 @@ class KramdownPrismicConverterTest < Minitest::Test
326
369
  }
327
370
  }
328
371
  ]
329
- markdown = "![alt text](/img.png)"
372
+ markdown = '![alt text](/img.png)'
330
373
  doc = Kramdown::Document.new(markdown)
331
374
  assert_equal expected, doc.to_prismic
332
375
  assert_equal 0, doc.warnings.size
@@ -335,9 +378,9 @@ class KramdownPrismicConverterTest < Minitest::Test
335
378
  def test_convert_double_img
336
379
  expected = [
337
380
  {
338
- type: "image",
381
+ type: 'image',
339
382
  content: {
340
- text: "",
383
+ text: '',
341
384
  spans: []
342
385
  },
343
386
  data: {
@@ -348,9 +391,9 @@ class KramdownPrismicConverterTest < Minitest::Test
348
391
  }
349
392
  },
350
393
  {
351
- type: "image",
394
+ type: 'image',
352
395
  content: {
353
- text: "",
396
+ text: '',
354
397
  spans: []
355
398
  },
356
399
  data: {
@@ -361,7 +404,7 @@ class KramdownPrismicConverterTest < Minitest::Test
361
404
  }
362
405
  }
363
406
  ]
364
- markdown = "![](/img.png)![](/img2.png)"
407
+ markdown = '![](/img.png)![](/img2.png)'
365
408
  doc = Kramdown::Document.new(markdown)
366
409
  assert_equal expected, doc.to_prismic
367
410
  assert_equal 2, doc.warnings.size
@@ -370,9 +413,9 @@ class KramdownPrismicConverterTest < Minitest::Test
370
413
  def test_convert_img_with_link
371
414
  expected = [
372
415
  {
373
- type: "image",
416
+ type: 'image',
374
417
  content: {
375
- text: "",
418
+ text: '',
376
419
  spans: []
377
420
  },
378
421
  data: {
@@ -381,12 +424,12 @@ class KramdownPrismicConverterTest < Minitest::Test
381
424
  },
382
425
  alt: 'alt text',
383
426
  linkTo: {
384
- url: "https://example.net/"
427
+ url: 'https://example.net/'
385
428
  }
386
429
  }
387
430
  }
388
431
  ]
389
- markdown = "[![alt text](/img.png)](https://example.net/)"
432
+ markdown = '[![alt text](/img.png)](https://example.net/)'
390
433
  doc = Kramdown::Document.new(markdown)
391
434
  assert_equal expected, doc.to_prismic
392
435
  assert_equal 0, doc.warnings.size
@@ -395,29 +438,28 @@ class KramdownPrismicConverterTest < Minitest::Test
395
438
  def test_convert_entity
396
439
  expected = [
397
440
  {
398
- type: "paragraph",
441
+ type: 'paragraph',
399
442
  content: {
400
443
  text: "\u00a0",
401
444
  spans: []
402
445
  }
403
446
  }
404
447
  ]
405
- markdown = "&nbsp;"
448
+ markdown = '&nbsp;'
406
449
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
407
450
  end
408
451
 
409
- [['mdash' , ' ---', ' —'],
410
- ['ndash' , ' --', ' –'],
411
- ['hellip' , ' ...', ' …'],
412
- ['laquo' , ' <<', ' «'],
413
- ['raquo' , '>>', '»'],
414
- ['laquo_space' , ' << T', ' « T'],
415
- ['raquo_space' , ' >>', ' »']
416
- ].each do |symbol|
452
+ [['mdash', ' ---', ' —'],
453
+ ['ndash', ' --', ' –'],
454
+ ['hellip', ' ...', ' …'],
455
+ ['laquo', ' <<', ' «'],
456
+ ['raquo', '>>', '»'],
457
+ ['laquo_space', ' << T', ' « T'],
458
+ ['raquo_space', ' >>', ' »']].each do |symbol|
417
459
  define_method "test_convert_typographic_symbols_#{symbol[0]}" do
418
460
  expected = [
419
461
  {
420
- type: "paragraph",
462
+ type: 'paragraph',
421
463
  content: {
422
464
  text: "Hello#{symbol[2]}",
423
465
  spans: []
@@ -431,11 +473,12 @@ class KramdownPrismicConverterTest < Minitest::Test
431
473
 
432
474
  def test_convert_smart_quote
433
475
  expected = [
434
- {type: "paragraph",
435
- content: {
436
- text: "Test\u2019",
437
- spans: []
438
- }
476
+ {
477
+ type: 'paragraph',
478
+ content: {
479
+ text: "Test\u2019",
480
+ spans: []
481
+ }
439
482
  }
440
483
  ]
441
484
  markdown = "Test'"
@@ -445,14 +488,14 @@ class KramdownPrismicConverterTest < Minitest::Test
445
488
  def test_convert_inline_code
446
489
  expected = [
447
490
  {
448
- type: "paragraph",
491
+ type: 'paragraph',
449
492
  content: {
450
- text: "Hello code",
493
+ text: 'Hello code',
451
494
  spans: []
452
495
  }
453
496
  }
454
497
  ]
455
- markdown = "Hello `code`"
498
+ markdown = 'Hello `code`'
456
499
  doc = Kramdown::Document.new(markdown)
457
500
  assert_equal expected, doc.to_prismic
458
501
  assert_equal 1, doc.warnings.size
@@ -460,20 +503,54 @@ class KramdownPrismicConverterTest < Minitest::Test
460
503
 
461
504
  def test_convert_br
462
505
  expected = [
463
- {type: "paragraph",
464
- content: {
465
- text: "Test\n",
466
- spans: []
467
- }
506
+ {
507
+ type: 'paragraph',
508
+ content: {
509
+ text: "Test\n",
510
+ spans: []
511
+ }
512
+ }
513
+ ]
514
+ html = '<p>Test<br></p>'
515
+ assert_equal expected, Kramdown::Document.new(html, input: :html).to_prismic
516
+ end
517
+
518
+ def test_convert_html_with_no_tags
519
+ expected = [
520
+ {
521
+ type: 'paragraph',
522
+ content: {
523
+ text: "Test\n",
524
+ spans: []
525
+ }
468
526
  }
469
527
  ]
470
- html = "<p>Test<br></p>"
528
+ html = 'Test'
471
529
  assert_equal expected, Kramdown::Document.new(html, input: :html).to_prismic
472
530
  end
473
531
 
532
+ def test_convert_iframe
533
+ expected = [
534
+ {
535
+ type: 'embed',
536
+ content: {
537
+ text: '',
538
+ spans: []
539
+ },
540
+ data: {
541
+ embed_url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
542
+ type: 'link'
543
+ }
544
+ }
545
+ ]
546
+ html = '<iframe src="https://www.youtube.com/watch?v=dQw4w9WgXcQ"></iframe>'
547
+ doc = Kramdown::Document.new(html, input: :markdown)
548
+ assert_equal expected, doc.to_prismic
549
+ end
550
+
474
551
  def test_convert_html
475
552
  expected = []
476
- html = "<div></div>"
553
+ html = '<div></div>'
477
554
  doc = Kramdown::Document.new(html, input: :markdown)
478
555
  assert_equal expected, doc.to_prismic
479
556
  assert_equal 1, doc.warnings.size
@@ -482,14 +559,14 @@ class KramdownPrismicConverterTest < Minitest::Test
482
559
  def test_convert_span_html
483
560
  expected = [
484
561
  {
485
- type: "paragraph",
562
+ type: 'paragraph',
486
563
  content: {
487
- text: "",
564
+ text: '',
488
565
  spans: []
489
566
  }
490
567
  }
491
568
  ]
492
- html = "<br>"
569
+ html = '<br>'
493
570
  doc = Kramdown::Document.new(html, input: :markdown)
494
571
  assert_equal expected, doc.to_prismic
495
572
  assert_equal 1, doc.warnings.size
@@ -497,7 +574,7 @@ class KramdownPrismicConverterTest < Minitest::Test
497
574
 
498
575
  def test_convert_table
499
576
  expected = []
500
- markdown = "| First cell|Second cell|Third cell|"
577
+ markdown = '| First cell|Second cell|Third cell|'
501
578
  doc = Kramdown::Document.new(markdown, input: :kramdown)
502
579
  assert_equal expected, doc.to_prismic
503
580
  assert_equal 1, doc.warnings.size
@@ -513,7 +590,7 @@ class KramdownPrismicConverterTest < Minitest::Test
513
590
 
514
591
  def test_convert_math
515
592
  expected = []
516
- markdown = "$$ 5 + 5 $$"
593
+ markdown = '$$ 5 + 5 $$'
517
594
  doc = Kramdown::Document.new(markdown, input: :kramdown)
518
595
  assert_equal expected, doc.to_prismic
519
596
  assert_equal 1, doc.warnings.size
@@ -522,12 +599,13 @@ class KramdownPrismicConverterTest < Minitest::Test
522
599
  def test_convert_footnote
523
600
  expected = [
524
601
  {
525
- type: "paragraph",
602
+ type: 'paragraph',
526
603
  content: {
527
- text: "test",
604
+ text: 'test',
528
605
  spans: []
529
606
  }
530
- }]
607
+ }
608
+ ]
531
609
  markdown = "test[^1]\n\n[^1]: test"
532
610
  doc = Kramdown::Document.new(markdown, input: :kramdown)
533
611
  assert_equal expected, doc.to_prismic
@@ -537,18 +615,43 @@ class KramdownPrismicConverterTest < Minitest::Test
537
615
  def test_convert_abbreviation
538
616
  expected = [
539
617
  {
540
- type: "paragraph",
618
+ type: 'paragraph',
541
619
  content: {
542
- text: "HTML",
620
+ text: 'HTML',
543
621
  spans: []
544
622
  }
545
- }]
623
+ }
624
+ ]
546
625
  markdown = "HTML\n\n*[HTML]: test"
547
626
  doc = Kramdown::Document.new(markdown, input: :kramdown)
548
627
  assert_equal expected, doc.to_prismic
549
628
  assert_equal 1, doc.warnings.size
550
629
  end
551
630
 
631
+ def test_convert_xml_comment
632
+ expected = []
633
+ markdown = "<!-- Main -->"
634
+ doc = Kramdown::Document.new(markdown, input: :kramdown)
635
+ assert_equal expected, doc.to_prismic
636
+ assert_equal 1, doc.warnings.size
637
+ end
638
+
639
+ def test_convert_span_xml_comment
640
+ expected = [
641
+ {
642
+ type: 'paragraph',
643
+ content: {
644
+ text: 'test test',
645
+ spans: []
646
+ }
647
+ }
648
+ ]
649
+ markdown = "test <!-- Main --> test"
650
+ doc = Kramdown::Document.new(markdown, input: :kramdown)
651
+ assert_equal expected, doc.to_prismic
652
+ assert_equal 1, doc.warnings.size
653
+ end
654
+
552
655
  def test_convert_comment
553
656
  expected = []
554
657
  markdown = "{::comment}\nComment\n{:/comment}"