kramdown-prismic 0.2.1 → 0.3.2

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.
data/test/parser_test.rb CHANGED
@@ -1,43 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'kramdown-prismic'
3
5
 
4
6
  class KramdownPrismicParserTest < Minitest::Test
5
- def test_parse_heading
6
- prismic = [
7
- {
8
- type: "heading1",
9
- content: {
10
- text: "This is the document title",
11
- spans: []
7
+ 6.times do |heading|
8
+ define_method "test_parse_heading_#{heading}" do
9
+ prismic = [
10
+ {
11
+ type: "heading#{heading + 1}",
12
+ content: {
13
+ text: 'This is the document title',
14
+ spans: []
15
+ }
12
16
  }
13
- }
14
- ]
15
- expected = "# This is the document title\n\n"
16
- doc = Kramdown::Document.new(prismic, input: :prismic)
17
- assert_equal expected, doc.to_kramdown
18
- end
19
-
20
- def test_parse_heading2
21
- prismic = [
22
- {
23
- type: "heading2",
24
- content: {
25
- text: "This is an h2 title",
26
- spans: []
27
- }
28
- }
29
- ]
30
- expected = "## This is an h2 title\n\n"
31
- doc = Kramdown::Document.new(prismic, input: :prismic)
32
- assert_equal expected, doc.to_kramdown
17
+ ]
18
+ expected = "#{'#' * (heading + 1)} This is the document title\n\n"
19
+ doc = Kramdown::Document.new(prismic, input: :prismic)
20
+ assert_equal expected, doc.to_kramdown
21
+ end
33
22
  end
34
23
 
35
24
  def test_parse_paragraph
36
25
  prismic = [
37
26
  {
38
- type: "paragraph",
27
+ type: 'paragraph',
39
28
  content: {
40
- text: "This is a paragraph",
29
+ text: 'This is a paragraph',
41
30
  spans: []
42
31
  }
43
32
  }
@@ -50,12 +39,12 @@ class KramdownPrismicParserTest < Minitest::Test
50
39
  def test_parse_paragraph_with_spans
51
40
  prismic = [
52
41
  {
53
- type: "paragraph",
42
+ type: 'paragraph',
54
43
  content: {
55
- text: "This is a paragraph",
44
+ text: 'This is a paragraph',
56
45
  spans: [
57
46
  {
58
- type: "em",
47
+ type: 'em',
59
48
  start: 0,
60
49
  end: 4
61
50
  }
@@ -71,17 +60,17 @@ class KramdownPrismicParserTest < Minitest::Test
71
60
  def test_parse_paragraph_with_multiple_spans
72
61
  prismic = [
73
62
  {
74
- type: "paragraph",
63
+ type: 'paragraph',
75
64
  content: {
76
- text: "This is a paragraph",
65
+ text: 'This is a paragraph',
77
66
  spans: [
78
67
  {
79
- type: "em",
68
+ type: 'em',
80
69
  start: 0,
81
70
  end: 4
82
71
  },
83
72
  {
84
- type: "strong",
73
+ type: 'strong',
85
74
  start: 5,
86
75
  end: 7
87
76
  }
@@ -97,16 +86,16 @@ class KramdownPrismicParserTest < Minitest::Test
97
86
  def test_parse_paragraph_with_link
98
87
  prismic = [
99
88
  {
100
- type: "paragraph",
89
+ type: 'paragraph',
101
90
  content: {
102
- text: "This is a paragraph",
91
+ text: 'This is a paragraph',
103
92
  spans: [
104
93
  {
105
- type: "hyperlink",
94
+ type: 'hyperlink',
106
95
  start: 0,
107
96
  end: 19,
108
97
  data: {
109
- url: "https://prismic.io"
98
+ url: 'https://prismic.io'
110
99
  }
111
100
  }
112
101
  ]
@@ -121,21 +110,21 @@ class KramdownPrismicParserTest < Minitest::Test
121
110
  def test_parse_paragraph_with_nested_spans
122
111
  prismic = [
123
112
  {
124
- type: "paragraph",
113
+ type: 'paragraph',
125
114
  content: {
126
- text: "This is a paragraph",
115
+ text: 'This is a paragraph',
127
116
  spans: [
128
117
  {
129
- type: "em",
118
+ type: 'em',
130
119
  start: 0,
131
120
  end: 4
132
121
  },
133
122
  {
134
- type: "hyperlink",
123
+ type: 'hyperlink',
135
124
  start: 0,
136
125
  end: 19,
137
126
  data: {
138
- url: "https://prismic.io"
127
+ url: 'https://prismic.io'
139
128
  }
140
129
  }
141
130
  ]
@@ -147,12 +136,120 @@ class KramdownPrismicParserTest < Minitest::Test
147
136
  assert_equal expected, doc.to_kramdown
148
137
  end
149
138
 
139
+ def test_parse_list_item
140
+ prismic = [
141
+ {
142
+ type: 'list-item',
143
+ content: {
144
+ text: 'Hello',
145
+ spans: []
146
+ }
147
+ },
148
+ {
149
+ type: 'list-item',
150
+ content: {
151
+ text: 'World',
152
+ spans: []
153
+ }
154
+ }
155
+ ]
156
+ expected = "* Hello\n* World\n\n"
157
+ doc = Kramdown::Document.new(prismic, input: :prismic)
158
+ assert_equal expected, doc.to_kramdown
159
+ end
160
+
161
+ def test_parse_list_item_and_spans
162
+ prismic = [
163
+ {
164
+ type: 'list-item',
165
+ content: {
166
+ text: 'Hello',
167
+ spans: [
168
+ {
169
+ type: 'em',
170
+ start: 0,
171
+ end: 5
172
+ }
173
+ ]
174
+ }
175
+ },
176
+ {
177
+ type: 'list-item',
178
+ content: {
179
+ text: 'World',
180
+ spans: []
181
+ }
182
+ }
183
+ ]
184
+ expected = "* *Hello*\n* World\n\n"
185
+ doc = Kramdown::Document.new(prismic, input: :prismic)
186
+ assert_equal expected, doc.to_kramdown
187
+ end
188
+
189
+ def test_parse_o_list_item
190
+ prismic = [
191
+ {
192
+ type: 'o-list-item',
193
+ content: {
194
+ text: 'Hello',
195
+ spans: []
196
+ }
197
+ },
198
+ {
199
+ type: 'o-list-item',
200
+ content: {
201
+ text: 'World',
202
+ spans: []
203
+ }
204
+ }
205
+ ]
206
+ expected = "1. Hello\n2. World\n\n"
207
+ doc = Kramdown::Document.new(prismic, input: :prismic)
208
+ assert_equal expected, doc.to_kramdown
209
+ end
210
+
211
+ def test_parse_o_list_item_and_list_item
212
+ prismic = [
213
+ {
214
+ type: 'o-list-item',
215
+ content: {
216
+ text: 'Hello',
217
+ spans: []
218
+ }
219
+ },
220
+ {
221
+ type: 'o-list-item',
222
+ content: {
223
+ text: 'World',
224
+ spans: []
225
+ }
226
+ },
227
+ {
228
+ type: 'list-item',
229
+ content: {
230
+ text: 'Test',
231
+ spans: []
232
+ }
233
+ },
234
+ {
235
+ type: 'list-item',
236
+ content: {
237
+ text: 'roger',
238
+ spans: []
239
+ }
240
+ }
241
+ ]
242
+ expected = "1. Hello\n2. World\n\n* Test\n* roger\n\n"
243
+ doc = Kramdown::Document.new(prismic, input: :prismic)
244
+ assert_equal expected, doc.to_kramdown
245
+ end
246
+
150
247
  def test_parse_image
151
248
  prismic = [
152
249
  {
153
- type: "image",
250
+ type: 'image',
154
251
  content: {
155
- text: "",
252
+ text: '',
156
253
  spans: []
157
254
  },
158
255
  data: {
@@ -168,10 +265,34 @@ class KramdownPrismicParserTest < Minitest::Test
168
265
  assert_equal expected, doc.to_kramdown
169
266
  end
170
267
 
268
+ def test_parse_img_with_link
269
+ prismic = [
270
+ {
271
+ type: 'image',
272
+ content: {
273
+ text: '',
274
+ spans: []
275
+ },
276
+ data: {
277
+ origin: {
278
+ url: '/img.png'
279
+ },
280
+ alt: 'alt text',
281
+ linkTo: {
282
+ url: 'https://example.net/'
283
+ }
284
+ }
285
+ }
286
+ ]
287
+ expected = "[![alt text](/img.png)][1]\n\n\n\n[1]: https://example.net/\n"
288
+ doc = Kramdown::Document.new(prismic, input: :prismic)
289
+ assert_equal expected, doc.to_kramdown
290
+ end
291
+
171
292
  def test_parse_preformatted
172
293
  prismic = [
173
294
  {
174
- type: "preformatted",
295
+ type: 'preformatted',
175
296
  content: {
176
297
  text: "This is a pre block\n",
177
298
  spans: []
@@ -186,13 +307,13 @@ class KramdownPrismicParserTest < Minitest::Test
186
307
  def test_parse_embed
187
308
  prismic = [
188
309
  {
189
- type: "embed",
310
+ type: 'embed',
190
311
  data: {
191
- type: "video",
192
- embed_url: "https://www.youtube.com/watch?v=y6y_4_b6RS8"
312
+ type: 'video',
313
+ embed_url: 'https://www.youtube.com/watch?v=y6y_4_b6RS8'
193
314
  },
194
315
  content: {
195
- text: "",
316
+ text: '',
196
317
  spans: []
197
318
  }
198
319
  }
metadata CHANGED
@@ -1,29 +1,35 @@
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.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - François de Metz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-10 00:00:00.000000000 Z
11
+ date: 2021-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '1.0'
22
+ version: '3'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1'
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: '1.0'
32
+ version: '3'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: minitest
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,30 +50,38 @@ dependencies:
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '12.0'
53
+ version: '13.0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '12.0'
55
- description: A Kramdown converter to convert documents into prismic rich text format.
60
+ version: '13.0'
61
+ description: A Kramdown converter to convert documents into prismic rich text format
62
+ and the other way around.
56
63
  email: francois@2metz.fr
57
- executables: []
64
+ executables:
65
+ - markdown2prismic
66
+ - html2prismic
67
+ - prismic2markdown
58
68
  extensions: []
59
69
  extra_rdoc_files: []
60
70
  files:
61
71
  - ".github/workflows/ci.yml"
62
72
  - ".gitignore"
63
- - ".travis.yml"
64
- - Changelog.md
73
+ - CHANGELOG.md
65
74
  - Gemfile
66
75
  - Gemfile.lock
67
76
  - LICENSE
68
77
  - README.md
69
78
  - Rakefile
79
+ - bin/html2prismic
80
+ - bin/markdown2prismic
81
+ - bin/prismic2markdown
70
82
  - kramdown-prismic.gemspec
83
+ - kramdown1.gemfile
84
+ - kramdown2.gemfile
71
85
  - lib/kramdown-prismic.rb
72
86
  - lib/kramdown-prismic/version.rb
73
87
  - lib/kramdown/converter/prismic.rb
@@ -96,7 +110,8 @@ requirements: []
96
110
  rubygems_version: 3.0.3
97
111
  signing_key:
98
112
  specification_version: 4
99
- summary: A Kramdown converter to convert documents into prismic rich text format.
113
+ summary: A Kramdown converter to convert documents into prismic rich text format and
114
+ the other way around.
100
115
  test_files:
101
116
  - test/converter_test.rb
102
117
  - test/parser_test.rb
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2
4
- - 2.3
5
- - 2.4
6
- script: bundle exec rake test
data/Changelog.md DELETED
@@ -1,22 +0,0 @@
1
- # Changelog
2
-
3
- ## Version 0.2.1
4
-
5
- - Parse embed elements
6
- - Convert inline code
7
-
8
- ## Version 0.2.0
9
-
10
- - Add parser to convert prismic to markdown
11
-
12
- ## Version 0.1.2
13
-
14
- - fix output with empty paragraph
15
-
16
- ## Version 0.1.1
17
-
18
- - Fix json of the image
19
-
20
- ## Version 0.1.0
21
-
22
- - Initial version