kramdown-prismic 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +39 -0
- data/CHANGELOG.md +36 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +8 -6
- data/LICENSE +1 -0
- data/README.md +36 -9
- data/Rakefile +3 -2
- data/bin/html2prismic +6 -0
- data/bin/markdown2prismic +6 -0
- data/bin/prismic2markdown +8 -0
- data/kramdown-prismic.gemspec +12 -8
- data/kramdown1.gemfile +6 -0
- data/kramdown2.gemfile +6 -0
- data/lib/kramdown-prismic.rb +2 -0
- data/lib/kramdown-prismic/version.rb +3 -1
- data/lib/kramdown/converter/prismic.rb +82 -39
- data/lib/kramdown/parser/prismic.rb +23 -19
- data/test/converter_test.rb +190 -124
- data/test/parser_test.rb +56 -48
- metadata +30 -15
- data/.travis.yml +0 -6
- data/Changelog.md +0 -13
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Kramdown
|
2
4
|
module Parser
|
3
5
|
class Prismic < Base
|
@@ -5,9 +7,7 @@ module Kramdown
|
|
5
7
|
@root.options[:encoding] = 'UTF-8'
|
6
8
|
@root.children = @source.map do |block|
|
7
9
|
type = block[:type]
|
8
|
-
if type.match(/heading/)
|
9
|
-
type = 'heading'
|
10
|
-
end
|
10
|
+
type = 'heading' if type.match(/heading/)
|
11
11
|
element = send("parse_#{type}", block)
|
12
12
|
parse_spans(element, block)
|
13
13
|
element
|
@@ -18,33 +18,36 @@ module Kramdown
|
|
18
18
|
|
19
19
|
def parse_heading(block)
|
20
20
|
level = block[:type].match(/heading([1-6])/)[1].to_i
|
21
|
-
Kramdown::Element.new(:header, nil, nil, {level: level, raw_text: ''})
|
21
|
+
Kramdown::Element.new(:header, nil, nil, { level: level, raw_text: '' })
|
22
22
|
end
|
23
23
|
|
24
|
-
def parse_paragraph(
|
24
|
+
def parse_paragraph(_block)
|
25
25
|
Kramdown::Element.new(:p)
|
26
26
|
end
|
27
27
|
|
28
28
|
def parse_image(block)
|
29
29
|
p = Kramdown::Element.new(:p)
|
30
|
-
img = Kramdown::Element.new(:img, nil, {
|
30
|
+
img = Kramdown::Element.new(:img, nil, { 'src' => block[:data][:origin][:url], 'alt' => block[:data][:alt] })
|
31
31
|
p.children << img
|
32
32
|
p
|
33
33
|
end
|
34
34
|
|
35
|
-
def parse_preformatted(
|
35
|
+
def parse_preformatted(_block)
|
36
36
|
Kramdown::Element.new(:blockquote)
|
37
37
|
end
|
38
38
|
|
39
|
+
def parse_embed(block)
|
40
|
+
Kramdown::Element.new(:html_element, 'iframe', { src: block[:data][:embed_url] })
|
41
|
+
end
|
42
|
+
|
39
43
|
def parse_spans(element, block)
|
40
44
|
stack = []
|
41
45
|
|
42
46
|
(block[:content][:text].size + 1).times do |index|
|
43
|
-
|
44
47
|
starting_spans = find_starting_spans_for(block, index)
|
45
48
|
ending_spans = find_ending_spans_for(block, index)
|
46
49
|
|
47
|
-
ending_spans.each do |
|
50
|
+
ending_spans.each do |_ending_span|
|
48
51
|
el = stack.pop
|
49
52
|
if stack.empty?
|
50
53
|
element.children << el
|
@@ -53,22 +56,23 @@ module Kramdown
|
|
53
56
|
end
|
54
57
|
end
|
55
58
|
starting_spans.each do |starting_span|
|
56
|
-
stack << if starting_span[:type] ==
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
stack << if starting_span[:type] == 'hyperlink'
|
60
|
+
Element.new(:a, nil, { 'href' => starting_span[:data][:url] })
|
61
|
+
else
|
62
|
+
Element.new(starting_span[:type].to_sym)
|
63
|
+
end
|
61
64
|
end
|
62
65
|
|
63
66
|
char = block[:content][:text][index]
|
64
67
|
next if char.nil?
|
68
|
+
|
65
69
|
current_text = if stack.empty?
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
+
element.children.last
|
71
|
+
else
|
72
|
+
stack[-1].children.last
|
73
|
+
end
|
70
74
|
if current_text.nil? || current_text.type != :text
|
71
|
-
current_text = Element.new(:text,
|
75
|
+
current_text = Element.new(:text, '')
|
72
76
|
if stack.empty?
|
73
77
|
element.children << current_text
|
74
78
|
else
|
data/test/converter_test.rb
CHANGED
@@ -1,44 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'kramdown-prismic'
|
3
5
|
|
4
6
|
class KramdownPrismicConverterTest < Minitest::Test
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
6.times do |heading|
|
8
|
+
define_method "test_convert_heading_#{heading}" do
|
9
|
+
expected = [
|
10
|
+
{
|
11
|
+
type: "heading#{heading + 1}",
|
12
|
+
content: {
|
13
|
+
text: 'This is the document title',
|
14
|
+
spans: []
|
15
|
+
}
|
12
16
|
}
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
]
|
18
|
+
markdown = "#{'#' * (heading + 1)} This is the document title"
|
19
|
+
assert_equal expected, Kramdown::Document.new(markdown, input: :kramdown).to_prismic
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
|
-
def
|
23
|
+
def test_convert_heading7
|
20
24
|
expected = [
|
21
25
|
{
|
22
|
-
type:
|
26
|
+
type: 'heading6',
|
23
27
|
content: {
|
24
|
-
text:
|
28
|
+
text: '# This is the document title',
|
25
29
|
spans: []
|
26
30
|
}
|
27
31
|
}
|
28
32
|
]
|
29
|
-
markdown =
|
33
|
+
markdown = '####### This is the document title'
|
30
34
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
31
35
|
end
|
32
36
|
|
33
37
|
def test_convert_heading_with_spans
|
34
38
|
expected = [
|
35
39
|
{
|
36
|
-
type:
|
40
|
+
type: 'heading2',
|
37
41
|
content: {
|
38
|
-
text:
|
42
|
+
text: 'This is a document title',
|
39
43
|
spans: [
|
40
44
|
{
|
41
|
-
type:
|
45
|
+
type: 'em',
|
42
46
|
start: 0,
|
43
47
|
end: 4
|
44
48
|
}
|
@@ -46,56 +50,56 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
46
50
|
}
|
47
51
|
}
|
48
52
|
]
|
49
|
-
markdown =
|
53
|
+
markdown = '## *This* is a document title'
|
50
54
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
51
55
|
end
|
52
56
|
|
53
57
|
def test_convert_paragraph
|
54
58
|
expected = [
|
55
59
|
{
|
56
|
-
type:
|
60
|
+
type: 'paragraph',
|
57
61
|
content: {
|
58
|
-
text:
|
62
|
+
text: 'This is a paragraph',
|
59
63
|
spans: []
|
60
64
|
}
|
61
65
|
}
|
62
66
|
]
|
63
|
-
markdown =
|
67
|
+
markdown = 'This is a paragraph'
|
64
68
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
65
69
|
end
|
66
70
|
|
67
71
|
def test_convert_paragraph_with_spans
|
68
72
|
expected = [
|
69
73
|
{
|
70
|
-
type:
|
74
|
+
type: 'paragraph',
|
71
75
|
content: {
|
72
|
-
text:
|
76
|
+
text: 'This is a paragraph',
|
73
77
|
spans: [
|
74
78
|
{
|
75
|
-
type:
|
79
|
+
type: 'hyperlink',
|
76
80
|
start: 0,
|
77
81
|
end: 19,
|
78
82
|
data: {
|
79
|
-
url:
|
83
|
+
url: 'https://prismic.io'
|
80
84
|
}
|
81
85
|
}
|
82
86
|
]
|
83
87
|
}
|
84
88
|
}
|
85
89
|
]
|
86
|
-
markdown =
|
90
|
+
markdown = '[This is a paragraph](https://prismic.io)'
|
87
91
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
88
92
|
end
|
89
93
|
|
90
94
|
def test_convert_paragraph_with_strong
|
91
95
|
expected = [
|
92
96
|
{
|
93
|
-
type:
|
97
|
+
type: 'paragraph',
|
94
98
|
content: {
|
95
|
-
text:
|
99
|
+
text: 'This is a paragraph',
|
96
100
|
spans: [
|
97
101
|
{
|
98
|
-
type:
|
102
|
+
type: 'strong',
|
99
103
|
start: 0,
|
100
104
|
end: 19
|
101
105
|
}
|
@@ -103,19 +107,19 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
103
107
|
}
|
104
108
|
}
|
105
109
|
]
|
106
|
-
markdown =
|
110
|
+
markdown = '**This is a paragraph**'
|
107
111
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
108
112
|
end
|
109
113
|
|
110
114
|
def test_convert_paragraph_with_strong2
|
111
115
|
expected = [
|
112
116
|
{
|
113
|
-
type:
|
117
|
+
type: 'paragraph',
|
114
118
|
content: {
|
115
|
-
text:
|
119
|
+
text: 'This is a paragraph',
|
116
120
|
spans: [
|
117
121
|
{
|
118
|
-
type:
|
122
|
+
type: 'strong',
|
119
123
|
start: 0,
|
120
124
|
end: 4
|
121
125
|
}
|
@@ -123,19 +127,19 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
123
127
|
}
|
124
128
|
}
|
125
129
|
]
|
126
|
-
markdown =
|
130
|
+
markdown = '**This** is a paragraph'
|
127
131
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
128
132
|
end
|
129
133
|
|
130
134
|
def test_convert_paragraph_with_em
|
131
135
|
expected = [
|
132
136
|
{
|
133
|
-
type:
|
137
|
+
type: 'paragraph',
|
134
138
|
content: {
|
135
|
-
text:
|
139
|
+
text: 'This is a paragraph',
|
136
140
|
spans: [
|
137
141
|
{
|
138
|
-
type:
|
142
|
+
type: 'em',
|
139
143
|
start: 0,
|
140
144
|
end: 4
|
141
145
|
}
|
@@ -143,19 +147,19 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
143
147
|
}
|
144
148
|
}
|
145
149
|
]
|
146
|
-
markdown =
|
150
|
+
markdown = '*This* is a paragraph'
|
147
151
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
148
152
|
end
|
149
153
|
|
150
154
|
def test_convert_list_o
|
151
155
|
expected = [
|
152
156
|
{
|
153
|
-
type:
|
157
|
+
type: 'o-list-item',
|
154
158
|
content: {
|
155
|
-
text:
|
159
|
+
text: 'This is a list item',
|
156
160
|
spans: [
|
157
161
|
{
|
158
|
-
type:
|
162
|
+
type: 'em',
|
159
163
|
start: 0,
|
160
164
|
end: 4
|
161
165
|
}
|
@@ -163,9 +167,9 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
163
167
|
}
|
164
168
|
},
|
165
169
|
{
|
166
|
-
type:
|
170
|
+
type: 'o-list-item',
|
167
171
|
content: {
|
168
|
-
text:
|
172
|
+
text: 'This is a second list item',
|
169
173
|
spans: []
|
170
174
|
}
|
171
175
|
}
|
@@ -177,12 +181,12 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
177
181
|
def test_convert_list_u
|
178
182
|
expected = [
|
179
183
|
{
|
180
|
-
type:
|
184
|
+
type: 'list-item',
|
181
185
|
content: {
|
182
|
-
text:
|
186
|
+
text: 'This is a list item',
|
183
187
|
spans: [
|
184
188
|
{
|
185
|
-
type:
|
189
|
+
type: 'em',
|
186
190
|
start: 0,
|
187
191
|
end: 4
|
188
192
|
}
|
@@ -190,9 +194,9 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
190
194
|
}
|
191
195
|
},
|
192
196
|
{
|
193
|
-
type:
|
197
|
+
type: 'list-item',
|
194
198
|
content: {
|
195
|
-
text:
|
199
|
+
text: 'This is a second list item',
|
196
200
|
spans: []
|
197
201
|
}
|
198
202
|
}
|
@@ -204,16 +208,16 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
204
208
|
def test_convert_nested_ul
|
205
209
|
expected = [
|
206
210
|
{
|
207
|
-
type:
|
211
|
+
type: 'list-item',
|
208
212
|
content: {
|
209
213
|
text: "item1\n",
|
210
214
|
spans: []
|
211
215
|
}
|
212
216
|
},
|
213
217
|
{
|
214
|
-
type:
|
218
|
+
type: 'list-item',
|
215
219
|
content: {
|
216
|
-
text:
|
220
|
+
text: 'item2',
|
217
221
|
spans: []
|
218
222
|
}
|
219
223
|
}
|
@@ -227,23 +231,23 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
227
231
|
def test_convert_nested_nested_ul
|
228
232
|
expected = [
|
229
233
|
{
|
230
|
-
type:
|
234
|
+
type: 'list-item',
|
231
235
|
content: {
|
232
236
|
text: "item1\n",
|
233
237
|
spans: []
|
234
238
|
}
|
235
239
|
},
|
236
240
|
{
|
237
|
-
type:
|
241
|
+
type: 'list-item',
|
238
242
|
content: {
|
239
243
|
text: "item2\n",
|
240
244
|
spans: []
|
241
245
|
}
|
242
246
|
},
|
243
247
|
{
|
244
|
-
type:
|
248
|
+
type: 'list-item',
|
245
249
|
content: {
|
246
|
-
text:
|
250
|
+
text: 'item3',
|
247
251
|
spans: []
|
248
252
|
}
|
249
253
|
}
|
@@ -257,7 +261,7 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
257
261
|
def test_convert_preformatted
|
258
262
|
expected = [
|
259
263
|
{
|
260
|
-
type:
|
264
|
+
type: 'preformatted',
|
261
265
|
content: {
|
262
266
|
text: "This is a pre block\n",
|
263
267
|
spans: []
|
@@ -271,9 +275,9 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
271
275
|
def test_convert_blockquote
|
272
276
|
expected = [
|
273
277
|
{
|
274
|
-
type:
|
278
|
+
type: 'preformatted',
|
275
279
|
content: {
|
276
|
-
text:
|
280
|
+
text: 'This is a blockquote',
|
277
281
|
spans: []
|
278
282
|
}
|
279
283
|
}
|
@@ -284,17 +288,18 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
284
288
|
|
285
289
|
def test_convert_empty
|
286
290
|
expected = []
|
287
|
-
markdown =
|
291
|
+
markdown = ''
|
288
292
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
289
293
|
end
|
290
294
|
|
291
295
|
def test_convert_span_blank
|
292
296
|
expected = [
|
293
|
-
{
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
297
|
+
{
|
298
|
+
type: 'o-list-item',
|
299
|
+
content: {
|
300
|
+
text: 'Testtest',
|
301
|
+
spans: []
|
302
|
+
}
|
298
303
|
}
|
299
304
|
]
|
300
305
|
markdown = "\n1. Test\n\n test\n"
|
@@ -303,16 +308,16 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
303
308
|
|
304
309
|
def test_convert_hr
|
305
310
|
expected = []
|
306
|
-
markdown =
|
311
|
+
markdown = '---'
|
307
312
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
308
313
|
end
|
309
314
|
|
310
315
|
def test_convert_img
|
311
316
|
expected = [
|
312
317
|
{
|
313
|
-
type:
|
318
|
+
type: 'image',
|
314
319
|
content: {
|
315
|
-
text:
|
320
|
+
text: '',
|
316
321
|
spans: []
|
317
322
|
},
|
318
323
|
data: {
|
@@ -323,7 +328,7 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
323
328
|
}
|
324
329
|
}
|
325
330
|
]
|
326
|
-
markdown =
|
331
|
+
markdown = '![alt text](/img.png)'
|
327
332
|
doc = Kramdown::Document.new(markdown)
|
328
333
|
assert_equal expected, doc.to_prismic
|
329
334
|
assert_equal 0, doc.warnings.size
|
@@ -332,9 +337,9 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
332
337
|
def test_convert_double_img
|
333
338
|
expected = [
|
334
339
|
{
|
335
|
-
type:
|
340
|
+
type: 'image',
|
336
341
|
content: {
|
337
|
-
text:
|
342
|
+
text: '',
|
338
343
|
spans: []
|
339
344
|
},
|
340
345
|
data: {
|
@@ -345,9 +350,9 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
345
350
|
}
|
346
351
|
},
|
347
352
|
{
|
348
|
-
type:
|
353
|
+
type: 'image',
|
349
354
|
content: {
|
350
|
-
text:
|
355
|
+
text: '',
|
351
356
|
spans: []
|
352
357
|
},
|
353
358
|
data: {
|
@@ -358,38 +363,62 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
358
363
|
}
|
359
364
|
}
|
360
365
|
]
|
361
|
-
markdown =
|
366
|
+
markdown = '![](/img.png)![](/img2.png)'
|
362
367
|
doc = Kramdown::Document.new(markdown)
|
363
368
|
assert_equal expected, doc.to_prismic
|
364
369
|
assert_equal 2, doc.warnings.size
|
365
370
|
end
|
366
371
|
|
372
|
+
def test_convert_img_with_link
|
373
|
+
expected = [
|
374
|
+
{
|
375
|
+
type: 'image',
|
376
|
+
content: {
|
377
|
+
text: '',
|
378
|
+
spans: []
|
379
|
+
},
|
380
|
+
data: {
|
381
|
+
origin: {
|
382
|
+
url: '/img.png'
|
383
|
+
},
|
384
|
+
alt: 'alt text',
|
385
|
+
linkTo: {
|
386
|
+
url: 'https://example.net/'
|
387
|
+
}
|
388
|
+
}
|
389
|
+
}
|
390
|
+
]
|
391
|
+
markdown = '[![alt text](/img.png)](https://example.net/)'
|
392
|
+
doc = Kramdown::Document.new(markdown)
|
393
|
+
assert_equal expected, doc.to_prismic
|
394
|
+
assert_equal 0, doc.warnings.size
|
395
|
+
end
|
396
|
+
|
367
397
|
def test_convert_entity
|
368
398
|
expected = [
|
369
399
|
{
|
370
|
-
type:
|
400
|
+
type: 'paragraph',
|
371
401
|
content: {
|
372
402
|
text: "\u00a0",
|
373
403
|
spans: []
|
374
404
|
}
|
375
405
|
}
|
376
406
|
]
|
377
|
-
markdown =
|
407
|
+
markdown = ' '
|
378
408
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
379
409
|
end
|
380
410
|
|
381
|
-
[['mdash'
|
382
|
-
['ndash'
|
383
|
-
['hellip'
|
384
|
-
['laquo'
|
385
|
-
['raquo'
|
386
|
-
['laquo_space'
|
387
|
-
['raquo_space'
|
388
|
-
].each do |symbol|
|
411
|
+
[['mdash', ' ---', ' —'],
|
412
|
+
['ndash', ' --', ' –'],
|
413
|
+
['hellip', ' ...', ' …'],
|
414
|
+
['laquo', ' <<', ' «'],
|
415
|
+
['raquo', '>>', '»'],
|
416
|
+
['laquo_space', ' << T', ' « T'],
|
417
|
+
['raquo_space', ' >>', ' »']].each do |symbol|
|
389
418
|
define_method "test_convert_typographic_symbols_#{symbol[0]}" do
|
390
419
|
expected = [
|
391
420
|
{
|
392
|
-
type:
|
421
|
+
type: 'paragraph',
|
393
422
|
content: {
|
394
423
|
text: "Hello#{symbol[2]}",
|
395
424
|
spans: []
|
@@ -403,33 +432,84 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
403
432
|
|
404
433
|
def test_convert_smart_quote
|
405
434
|
expected = [
|
406
|
-
{
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
435
|
+
{
|
436
|
+
type: 'paragraph',
|
437
|
+
content: {
|
438
|
+
text: "Test\u2019",
|
439
|
+
spans: []
|
440
|
+
}
|
411
441
|
}
|
412
442
|
]
|
413
443
|
markdown = "Test'"
|
414
444
|
assert_equal expected, Kramdown::Document.new(markdown, input: :kramdown).to_prismic
|
415
445
|
end
|
416
446
|
|
447
|
+
def test_convert_inline_code
|
448
|
+
expected = [
|
449
|
+
{
|
450
|
+
type: 'paragraph',
|
451
|
+
content: {
|
452
|
+
text: 'Hello code',
|
453
|
+
spans: []
|
454
|
+
}
|
455
|
+
}
|
456
|
+
]
|
457
|
+
markdown = 'Hello `code`'
|
458
|
+
doc = Kramdown::Document.new(markdown)
|
459
|
+
assert_equal expected, doc.to_prismic
|
460
|
+
assert_equal 1, doc.warnings.size
|
461
|
+
end
|
462
|
+
|
417
463
|
def test_convert_br
|
418
464
|
expected = [
|
419
|
-
{
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
465
|
+
{
|
466
|
+
type: 'paragraph',
|
467
|
+
content: {
|
468
|
+
text: "Test\n",
|
469
|
+
spans: []
|
470
|
+
}
|
471
|
+
}
|
472
|
+
]
|
473
|
+
html = '<p>Test<br></p>'
|
474
|
+
assert_equal expected, Kramdown::Document.new(html, input: :html).to_prismic
|
475
|
+
end
|
476
|
+
|
477
|
+
def test_convert_html_with_no_tags
|
478
|
+
expected = [
|
479
|
+
{
|
480
|
+
type: 'paragraph',
|
481
|
+
content: {
|
482
|
+
text: "Test\n",
|
483
|
+
spans: []
|
484
|
+
}
|
424
485
|
}
|
425
486
|
]
|
426
|
-
html =
|
487
|
+
html = 'Test'
|
427
488
|
assert_equal expected, Kramdown::Document.new(html, input: :html).to_prismic
|
428
489
|
end
|
429
490
|
|
491
|
+
def test_convert_iframe
|
492
|
+
expected = [
|
493
|
+
{
|
494
|
+
type: 'embed',
|
495
|
+
content: {
|
496
|
+
text: '',
|
497
|
+
spans: []
|
498
|
+
},
|
499
|
+
data: {
|
500
|
+
embed_url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
501
|
+
type: 'link'
|
502
|
+
}
|
503
|
+
}
|
504
|
+
]
|
505
|
+
html = '<iframe src="https://www.youtube.com/watch?v=dQw4w9WgXcQ"></iframe>'
|
506
|
+
doc = Kramdown::Document.new(html, input: :markdown)
|
507
|
+
assert_equal expected, doc.to_prismic
|
508
|
+
end
|
509
|
+
|
430
510
|
def test_convert_html
|
431
511
|
expected = []
|
432
|
-
html =
|
512
|
+
html = '<div></div>'
|
433
513
|
doc = Kramdown::Document.new(html, input: :markdown)
|
434
514
|
assert_equal expected, doc.to_prismic
|
435
515
|
assert_equal 1, doc.warnings.size
|
@@ -438,14 +518,14 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
438
518
|
def test_convert_span_html
|
439
519
|
expected = [
|
440
520
|
{
|
441
|
-
type:
|
521
|
+
type: 'paragraph',
|
442
522
|
content: {
|
443
|
-
text:
|
523
|
+
text: '',
|
444
524
|
spans: []
|
445
525
|
}
|
446
526
|
}
|
447
527
|
]
|
448
|
-
html =
|
528
|
+
html = '<br>'
|
449
529
|
doc = Kramdown::Document.new(html, input: :markdown)
|
450
530
|
assert_equal expected, doc.to_prismic
|
451
531
|
assert_equal 1, doc.warnings.size
|
@@ -453,7 +533,7 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
453
533
|
|
454
534
|
def test_convert_table
|
455
535
|
expected = []
|
456
|
-
markdown =
|
536
|
+
markdown = '| First cell|Second cell|Third cell|'
|
457
537
|
doc = Kramdown::Document.new(markdown, input: :kramdown)
|
458
538
|
assert_equal expected, doc.to_prismic
|
459
539
|
assert_equal 1, doc.warnings.size
|
@@ -469,7 +549,7 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
469
549
|
|
470
550
|
def test_convert_math
|
471
551
|
expected = []
|
472
|
-
markdown =
|
552
|
+
markdown = '$$ 5 + 5 $$'
|
473
553
|
doc = Kramdown::Document.new(markdown, input: :kramdown)
|
474
554
|
assert_equal expected, doc.to_prismic
|
475
555
|
assert_equal 1, doc.warnings.size
|
@@ -478,12 +558,13 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
478
558
|
def test_convert_footnote
|
479
559
|
expected = [
|
480
560
|
{
|
481
|
-
type:
|
561
|
+
type: 'paragraph',
|
482
562
|
content: {
|
483
|
-
text:
|
563
|
+
text: 'test',
|
484
564
|
spans: []
|
485
565
|
}
|
486
|
-
}
|
566
|
+
}
|
567
|
+
]
|
487
568
|
markdown = "test[^1]\n\n[^1]: test"
|
488
569
|
doc = Kramdown::Document.new(markdown, input: :kramdown)
|
489
570
|
assert_equal expected, doc.to_prismic
|
@@ -493,12 +574,13 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
493
574
|
def test_convert_abbreviation
|
494
575
|
expected = [
|
495
576
|
{
|
496
|
-
type:
|
577
|
+
type: 'paragraph',
|
497
578
|
content: {
|
498
|
-
text:
|
579
|
+
text: 'HTML',
|
499
580
|
spans: []
|
500
581
|
}
|
501
|
-
}
|
582
|
+
}
|
583
|
+
]
|
502
584
|
markdown = "HTML\n\n*[HTML]: test"
|
503
585
|
doc = Kramdown::Document.new(markdown, input: :kramdown)
|
504
586
|
assert_equal expected, doc.to_prismic
|
@@ -513,22 +595,6 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
513
595
|
assert_equal 1, doc.warnings.size
|
514
596
|
end
|
515
597
|
|
516
|
-
def test_convert_xml_comment
|
517
|
-
expected = []
|
518
|
-
markdown = "<!-- a *comment* -->"
|
519
|
-
doc = Kramdown::Document.new(markdown, input: :kramdown)
|
520
|
-
assert_equal expected, doc.to_prismic
|
521
|
-
assert_equal 1, doc.warnings.size
|
522
|
-
end
|
523
|
-
|
524
|
-
def test_convert_xml_pi
|
525
|
-
expected = []
|
526
|
-
markdown = "<? a processing `instruction`?>"
|
527
|
-
doc = Kramdown::Document.new(markdown, input: :kramdown)
|
528
|
-
assert_equal expected, doc.to_prismic
|
529
|
-
assert_equal 1, doc.warnings.size
|
530
|
-
end
|
531
|
-
|
532
598
|
def test_convert_raw
|
533
599
|
expected = []
|
534
600
|
markdown = "{::nomarkdown}\nComment\n{:/nomarkdown}"
|