kramdown-prismic 0.0.5 → 0.0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13cce49c2e7957ffcd0c71c62f18faff08817a27
4
- data.tar.gz: c637b24628b1c21d3b420e77b2468f3d257b38cc
3
+ metadata.gz: c8f60ad20cbfb6c159e57a59ea79acf3123ba6a3
4
+ data.tar.gz: 28bd2d6a6faf005cbc406ea2c4381369b5499d10
5
5
  SHA512:
6
- metadata.gz: fa1db25fb05c4fd1cc55d67b47db51bad9405a1dc22e215a8d749f8588b60b3c663b5d3e850b319261c284cfb9242dcbbbb9cb909ad98ec4f1d294bc0f4b5dfd
7
- data.tar.gz: 6033c3434686ec767e255cb9aaa925abe5fc9587e00a344c6bc6fdc641dc1a86616777aeb60303228f0d79c5504955ba0377861329f305246b927750fa539edc
6
+ metadata.gz: d5726fb2ec12cf1c292691b0e92dff4065f42f29bbdf2c7d101a7959faaf5dfb2f823b17133fdb689a31cac08e96b043724e78270f8f9d517bd27e195f593531
7
+ data.tar.gz: 72a178508efc47257ea3c21970ee3524f307ccfb58df87f7b889caced19b8e442f746de9d7af5433f58aaacd5d65af22fabdf170ff1ba860edc1a05d6edd4e81
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kramdown-prismic (0.0.4)
4
+ kramdown-prismic (0.0.5)
5
5
  kramdown (~> 1.0)
6
6
 
7
7
  GEM
@@ -1,3 +1,3 @@
1
1
  module KramdownPrismic
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -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 = extract_non_nestable_elements(child)
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.each do |child|
24
- if child.type == :blank
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.map do |element|
33
+ def extract_non_nestable_elements(child, elements)
34
+ child.children = child.children.inject([]) do |memo, element|
34
35
  if element.type == :img
35
- child.children.slice!(child.children.find_index(element))
36
- element
36
+ elements << element
37
37
  elsif element.type == :ul
38
38
  warning('nested list moved to the top level')
39
- child.children.slice!(child.children.find_index(element))
40
- [element, extract_non_nestable_elements(element)]
39
+ elements << element
40
+ extract_non_nestable_elements(element, elements)
41
41
  else
42
- extract_non_nestable_elements(element)
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 = "1. Test\n\n test"
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",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown-prismic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - François de Metz