kramdown-prismic 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb835641c9e7f2e9e600e0307e3bfd6e9eb46e5d83ae257c505c659c20865931
4
- data.tar.gz: cba5da2b2d81fff052b24d7921872ec8e9607b726bdbe210ff516b6cf7b6810a
3
+ metadata.gz: 3229f319815e16e39608a957bb9f596e623a6ef605be3955c46723de2aedbb98
4
+ data.tar.gz: '08f9b62d41e583e99d51373ddb875352abec6226f2a584c6f9d21b61c15ed26f'
5
5
  SHA512:
6
- metadata.gz: 9b4e02f18a5dbf5c51f46cc729c8dd2018d1eec8809790e0492ee22f7886627e5bc77d20dabde755f44883f1c062cd7a7dda33ba8acbe9c4dac165218f23ca70
7
- data.tar.gz: 5428075b5c8eac073a1729feac6803a378ac55ba330540c46c230f78b5e965caeb95b26ea60be9f059611d182cb0f6c764c2817f9b03c53b1dcde03ec923d86b
6
+ metadata.gz: 8c3bf867920d85af049006027d70f156cca4c0863cd8c40784eb473121153652acc368906e1100fabdb90d36a04f73c9a966090c8a68e7d55fc8c55f0e3610e7
7
+ data.tar.gz: e4daf1cfe1886f809f0234d7a181b22e677be78401f06c4f4657d89a519e61b13d56ce1dcabcad11ed13bbe782f359c3214c5650da098b8b72c65fccdeb230b4
data/Changelog.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 0.2.2
4
+
5
+ - Convert links with only an image inside. See #1.
6
+
3
7
  ## Version 0.2.1
4
8
 
5
9
  - Parse embed elements
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kramdown-prismic (0.2.1)
4
+ kramdown-prismic (0.2.2)
5
5
  kramdown (~> 1.0)
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ GEM
9
9
  specs:
10
10
  kramdown (1.17.0)
11
11
  minitest (5.10.3)
12
- rake (12.2.1)
12
+ rake (13.0.6)
13
13
 
14
14
  PLATFORMS
15
15
  ruby
@@ -17,7 +17,7 @@ PLATFORMS
17
17
  DEPENDENCIES
18
18
  kramdown-prismic!
19
19
  minitest (~> 5.0)
20
- rake (~> 12.0)
20
+ rake (~> 13.0)
21
21
 
22
22
  BUNDLED WITH
23
23
  1.17.2
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_dependency "kramdown", "~> 1.0"
19
19
  s.add_development_dependency "minitest", "~> 5.0"
20
- s.add_development_dependency "rake", "~> 12.0"
20
+ s.add_development_dependency "rake", "~> 13.0"
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module KramdownPrismic
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -32,7 +32,9 @@ module Kramdown
32
32
 
33
33
  def extract_non_nestable_elements(child, elements)
34
34
  child.children = child.children.inject([]) do |memo, element|
35
- if element.type == :img
35
+ if element.type == :a && element.children.size === 1 && element.children.first.type == :img
36
+ elements << element
37
+ elsif element.type == :img
36
38
  elements << element
37
39
  warning('images inside content will be moved to the top level and may be rendered differently') if child.children.size > 1
38
40
  elsif element.type == :ul
@@ -123,6 +125,27 @@ module Kramdown
123
125
  }
124
126
  end
125
127
 
128
+ # This can only apply when an link with an image inside has been detected
129
+ def convert_a(element)
130
+ image = element.children.first
131
+ {
132
+ type: 'image',
133
+ content: {
134
+ text: '',
135
+ spans: []
136
+ },
137
+ data: {
138
+ origin: {
139
+ url: image.attr['src']
140
+ },
141
+ alt: image.attr['alt'],
142
+ linkTo: {
143
+ url: element.attr['href']
144
+ }
145
+ }
146
+ }
147
+ end
148
+
126
149
  def convert_html_element(element)
127
150
  warning('translating html elements is not supported')
128
151
  nil
@@ -367,6 +367,31 @@ class KramdownPrismicConverterTest < Minitest::Test
367
367
  assert_equal 2, doc.warnings.size
368
368
  end
369
369
 
370
+ def test_convert_img_with_link
371
+ expected = [
372
+ {
373
+ type: "image",
374
+ content: {
375
+ text: "",
376
+ spans: []
377
+ },
378
+ data: {
379
+ origin: {
380
+ url: '/img.png'
381
+ },
382
+ alt: 'alt text',
383
+ linkTo: {
384
+ url: "https://example.net/"
385
+ }
386
+ }
387
+ }
388
+ ]
389
+ markdown = "[![alt text](/img.png)](https://example.net/)"
390
+ doc = Kramdown::Document.new(markdown)
391
+ assert_equal expected, doc.to_prismic
392
+ assert_equal 0, doc.warnings.size
393
+ end
394
+
370
395
  def test_convert_entity
371
396
  expected = [
372
397
  {
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - François de Metz
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '12.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '12.0'
54
+ version: '13.0'
55
55
  description: A Kramdown converter to convert documents into prismic rich text format.
56
56
  email: francois@2metz.fr
57
57
  executables: []