kramdown-prismic 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/kramdown-prismic/version.rb +1 -1
- data/lib/kramdown/converter/prismic.rb +14 -12
- data/test/kramdown-prismic_test.rb +35 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8f60ad20cbfb6c159e57a59ea79acf3123ba6a3
|
4
|
+
data.tar.gz: 28bd2d6a6faf005cbc406ea2c4381369b5499d10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5726fb2ec12cf1c292691b0e92dff4065f42f29bbdf2c7d101a7959faaf5dfb2f823b17133fdb689a31cac08e96b043724e78270f8f9d517bd27e195f593531
|
7
|
+
data.tar.gz: 72a178508efc47257ea3c21970ee3524f307ccfb58df87f7b889caced19b8e442f746de9d7af5433f58aaacd5d65af22fabdf170ff1ba860edc1a05d6edd4e81
|
data/Gemfile.lock
CHANGED
@@ -14,33 +14,35 @@ module Kramdown
|
|
14
14
|
def cleanup_ast(root)
|
15
15
|
remove_blanks(root)
|
16
16
|
root.children.map do |child|
|
17
|
-
elements =
|
17
|
+
elements = []
|
18
|
+
extract_non_nestable_elements(child, elements)
|
18
19
|
[child, elements]
|
19
20
|
end.flatten.compact
|
20
21
|
end
|
21
22
|
|
22
23
|
def remove_blanks(root)
|
23
|
-
root.children.
|
24
|
-
|
25
|
-
root.children.slice!(root.children.find_index(child))
|
26
|
-
else
|
24
|
+
root.children = root.children.inject([]) do |memo, child|
|
25
|
+
unless child.type == :blank
|
27
26
|
remove_blanks(child)
|
27
|
+
memo << child
|
28
28
|
end
|
29
|
+
memo
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
def extract_non_nestable_elements(child)
|
33
|
-
child.children.
|
33
|
+
def extract_non_nestable_elements(child, elements)
|
34
|
+
child.children = child.children.inject([]) do |memo, element|
|
34
35
|
if element.type == :img
|
35
|
-
|
36
|
-
element
|
36
|
+
elements << element
|
37
37
|
elsif element.type == :ul
|
38
38
|
warning('nested list moved to the top level')
|
39
|
-
|
40
|
-
|
39
|
+
elements << element
|
40
|
+
extract_non_nestable_elements(element, elements)
|
41
41
|
else
|
42
|
-
|
42
|
+
memo << element
|
43
|
+
extract_non_nestable_elements(element, elements)
|
43
44
|
end
|
45
|
+
memo
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
@@ -297,7 +297,7 @@ class KramdownPrismicTest < Minitest::Test
|
|
297
297
|
}
|
298
298
|
}
|
299
299
|
]
|
300
|
-
markdown = "
|
300
|
+
markdown = "\n1. Test\n\n test\n"
|
301
301
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
302
302
|
end
|
303
303
|
|
@@ -331,6 +331,40 @@ class KramdownPrismicTest < Minitest::Test
|
|
331
331
|
assert_equal expected, Kramdown::Document.new(markdown).to_prismic
|
332
332
|
end
|
333
333
|
|
334
|
+
def test_convert_double_img
|
335
|
+
expected = [
|
336
|
+
{
|
337
|
+
type: "paragraph",
|
338
|
+
content: {
|
339
|
+
text: "",
|
340
|
+
spans: []
|
341
|
+
}
|
342
|
+
},
|
343
|
+
{
|
344
|
+
type: "image",
|
345
|
+
content: {
|
346
|
+
text: "",
|
347
|
+
spans: []
|
348
|
+
},
|
349
|
+
data: {
|
350
|
+
url: '/img.png'
|
351
|
+
}
|
352
|
+
},
|
353
|
+
{
|
354
|
+
type: "image",
|
355
|
+
content: {
|
356
|
+
text: "",
|
357
|
+
spans: []
|
358
|
+
},
|
359
|
+
data: {
|
360
|
+
url: '/img2.png'
|
361
|
+
}
|
362
|
+
}
|
363
|
+
]
|
364
|
+
markdown = "![](/img.png)![](/img2.png)"
|
365
|
+
assert_equal expected, Kramdown::Document.new(markdown).to_prismic
|
366
|
+
end
|
367
|
+
|
334
368
|
def test_convert_entity
|
335
369
|
expected = [
|
336
370
|
{type: "paragraph",
|