kramdown-prismic 0.3.0 → 0.3.1

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
  SHA256:
3
- metadata.gz: 5375492a7419784a19fee9021699380d7106184167742f73f693502aeee28767
4
- data.tar.gz: 378f78feb7e48a07c5177a7ae98556fb918a6b6258201227a5cfd415dc73d23c
3
+ metadata.gz: e34361d43f02e8ee666fb78685a040128617accc25d44221ed0f98e45fcc7eae
4
+ data.tar.gz: 58ceb9f450d5d719b3698dcc37d417d27f6ecff3a8873812426a086bb6296695
5
5
  SHA512:
6
- metadata.gz: b90f2f0df8505ef0403704d0db3c32aa3003589e5bd958827ed270347e477b7b87f464626781fa0049b43bf5372f6fd501e4d476b83a61d8bd4d0c399f020bcf
7
- data.tar.gz: 87d4c10f8ccd35b29ee9fc0b030a604490f35354bb86809bf18c8dfcfe79c3ae62199aa3f2b7195290be38febe09c76a7d9df74734845c9e0b0ebde41602661c
6
+ metadata.gz: fdd15d2fe0bb82ab3528f818579efe067f82274727c4f59ec262e899ca44224aa18b3c766f73f7c82396a8d803c93d9d92cfd864c4c24587a2743297cc60e0e1
7
+ data.tar.gz: 4cc36e4dbba12aaad5318267b268773a7010481959f9a4df4ddafaa3fc912cb9bb8830f4ac7fc8709e0c7b38c6ba2fc6a84a3436754c5d044ec4a7ab5be4646e
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 0.3.1
4
+
5
+ - Add binaries `html2primisc`, `markdown2prismic` and `primisc2markdown`.
6
+ - Add parsed embed support
7
+
3
8
  ## Version 0.3.0
4
9
 
5
10
  - Relax the kramdown dependency to allows the version 2.
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Kramdown Prismic
2
2
 
3
- A [Kramdown][] parser and converter to convert documents into [prismic][] rich text format and back.
3
+ A [Kramdown][] parser and converter to convert documents into [prismic][] rich text format and the other way around.
4
4
 
5
- A useful usage is to convert markdown documents to prismic for import purpose. Then you can even convert prismic format back to markdown.
5
+ A useful usage is to convert markdown documents to prismic for [import purpose][prismic-import]. Then you can even convert prismic format back to markdown.
6
6
 
7
7
  ## Status
8
8
 
@@ -18,6 +18,22 @@ gem 'kramdown-prismic', '~> 0.1'
18
18
 
19
19
  ## Usage
20
20
 
21
+ ### With executables
22
+
23
+ *markdown2prismic*:
24
+
25
+ markdown2prismic $'# My Title\n\nHello world'
26
+
27
+ *html2prismic*:
28
+
29
+ html2prismic '<h1>My Title</h1><p>Hello world</p>'
30
+
31
+ *prismic2markdown*:
32
+
33
+ prismic2markdown '[{"type":"heading1","content":{"text":"My Title","spans":[]}},{"type":"paragraph","content":{"text":"Test","spans":[]}}]'
34
+
35
+ ### As a library
36
+
21
37
  **Convert kramdown documents to Prismic**
22
38
 
23
39
  ```ruby
@@ -123,3 +139,4 @@ MIT
123
139
 
124
140
  [Kramdown]: https://kramdown.gettalong.org/
125
141
  [prismic]: https://prismic.io/
142
+ [prismic-import]: https://prismic.io/docs/core-concepts/how-to-import-content
data/Rakefile CHANGED
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake/testtask'
2
4
 
3
5
  Rake::TestTask.new do |t|
4
- t.libs << "test"
6
+ t.libs << 'test'
5
7
  t.test_files = FileList['test/*_test.rb']
6
8
  t.verbose = true
7
9
  end
8
-
data/bin/html2prismic ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'kramdown-prismic'
4
+ require 'json'
5
+
6
+ print Kramdown::Document.new(ARGV[0], input: :html).to_prismic.to_json.to_s
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'kramdown-prismic'
4
+ require 'json'
5
+
6
+ print Kramdown::Document.new(ARGV[0], input: :markdown).to_prismic.to_json.to_s
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'kramdown-prismic'
4
+ require 'json'
5
+
6
+ source = JSON.parse(ARGV[0], symbolize_names: true)
7
+
8
+ print Kramdown::Document.new(source, input: :prismic).to_kramdown
@@ -1,21 +1,25 @@
1
- # encoding: utf-8
2
- require File.expand_path('../lib/kramdown-prismic/version', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/kramdown-prismic/version', __dir__)
3
4
 
4
5
  Gem::Specification.new do |s|
5
6
  s.name = 'kramdown-prismic'
6
7
  s.version = KramdownPrismic::VERSION
7
- s.summary = "A Kramdown converter to convert documents into prismic rich text format and the other way around."
8
- s.description = "A Kramdown converter to convert documents into prismic rich text format and the other way around."
9
- s.authors = ["François de Metz"]
8
+ s.summary = 'A Kramdown converter to convert documents into prismic rich text format and the other way around.'
9
+ s.description = 'A Kramdown converter to convert documents into prismic rich text format and the other way around.'
10
+ s.authors = ['François de Metz']
10
11
  s.email = 'francois@2metz.fr'
11
12
 
13
+ s.executables << 'markdown2prismic'
14
+ s.executables << 'html2prismic'
15
+ s.executables << 'prismic2markdown'
12
16
  s.files = `git ls-files`.split("\n")
13
17
  s.test_files = `git ls-files -- test/*`.split("\n")
14
18
 
15
19
  s.homepage = 'https://github.com/stormz/kramdown-prismic'
16
20
  s.license = 'MIT'
17
21
 
18
- s.add_dependency "kramdown", ">= 1", "< 3"
19
- s.add_development_dependency "minitest", "~> 5.0"
20
- s.add_development_dependency "rake", "~> 13.0"
22
+ s.add_dependency 'kramdown', '>= 1', '< 3'
23
+ s.add_development_dependency 'minitest', '~> 5.0'
24
+ s.add_development_dependency 'rake', '~> 13.0'
21
25
  end
data/kramdown1.gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/kramdown2.gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'kramdown'
2
4
 
3
5
  require 'kramdown/parser/prismic'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module KramdownPrismic
2
- VERSION = "0.3.0"
4
+ VERSION = '0.3.1'
3
5
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'kramdown/converter/base'
2
4
 
3
5
  module Kramdown
4
6
  module Converter
5
7
  class Prismic < Base
6
8
  def convert(root)
7
- cleanup_ast(root).map { |child|
9
+ cleanup_ast(root).map do |child|
8
10
  convert_element(child)
9
- }.compact.flatten
11
+ end.compact.flatten
10
12
  end
11
13
 
12
14
  private
@@ -21,22 +23,23 @@ module Kramdown
21
23
  end
22
24
 
23
25
  def remove_blanks(root)
24
- root.children = root.children.inject([]) do |memo, child|
26
+ root.children = root.children.each_with_object([]) do |child, memo|
25
27
  unless child.type == :blank
26
28
  remove_blanks(child)
27
29
  memo << child
28
30
  end
29
- memo
30
31
  end
31
32
  end
32
33
 
33
34
  def extract_non_nestable_elements(child, elements)
34
- child.children = child.children.inject([]) do |memo, element|
35
- if element.type == :a && element.children.size === 1 && element.children.first.type == :img
35
+ child.children = child.children.each_with_object([]) do |element, memo|
36
+ if element.type == :a && element.children.size == 1 && element.children.first.type == :img
36
37
  elements << element
37
38
  elsif element.type == :img
38
39
  elements << element
39
- warning('images inside content will be moved to the top level and may be rendered differently') if child.children.size > 1
40
+ if child.children.size > 1
41
+ warning('images inside content will be moved to the top level and may be rendered differently')
42
+ end
40
43
  elsif element.type == :ul
41
44
  warning('nested list moved to the top level')
42
45
  elements << element
@@ -45,7 +48,6 @@ module Kramdown
45
48
  memo << element
46
49
  extract_non_nestable_elements(element, elements)
47
50
  end
48
- memo
49
51
  end
50
52
  end
51
53
 
@@ -61,9 +63,10 @@ module Kramdown
61
63
  end
62
64
 
63
65
  def convert_p(element)
64
- return nil if element.children.size == 0
66
+ return nil if element.children.size.zero?
67
+
65
68
  {
66
- type: "paragraph",
69
+ type: 'paragraph',
67
70
  content: extract_content(element)
68
71
  }
69
72
  end
@@ -106,8 +109,7 @@ module Kramdown
106
109
  }
107
110
  end
108
111
 
109
- def convert_hr(element)
110
- end
112
+ def convert_hr(element); end
111
113
 
112
114
  def convert_img(element)
113
115
  {
@@ -118,9 +120,9 @@ module Kramdown
118
120
  },
119
121
  data: {
120
122
  origin: {
121
- url: element.attr["src"]
123
+ url: element.attr['src']
122
124
  },
123
- alt: element.attr["alt"]
125
+ alt: element.attr['alt']
124
126
  }
125
127
  }
126
128
  end
@@ -147,39 +149,62 @@ module Kramdown
147
149
  end
148
150
 
149
151
  def convert_html_element(element)
150
- warning('translating html elements is not supported')
151
- nil
152
+ if element.value == 'iframe'
153
+ {
154
+ content: {
155
+ spans: [],
156
+ text: ''
157
+ },
158
+ type: 'embed',
159
+ data: {
160
+ embed_url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
161
+ type: 'link'
162
+ }
163
+ }
164
+ else
165
+ warning('translating html elements is not supported')
166
+ nil
167
+ end
152
168
  end
153
169
 
154
- def convert_table(element)
170
+ def convert_table(_element)
155
171
  warning('translating table is not supported')
156
172
  nil
157
173
  end
158
174
 
159
- def convert_dl(element)
175
+ def convert_dl(_element)
160
176
  warning('translating dl is not supported')
161
177
  nil
162
178
  end
163
179
 
164
- def convert_math(element)
180
+ def convert_math(_element)
165
181
  warning('translating math is not supported')
166
182
  nil
167
183
  end
168
184
 
169
- def convert_comment(element)
185
+ def convert_comment(_element)
170
186
  warning('translating comment is not supported')
171
187
  nil
172
188
  end
173
189
 
174
- def convert_raw(element)
190
+ def convert_raw(_element)
175
191
  warning('translating raw is not supported')
176
192
  nil
177
193
  end
178
194
 
179
- def extract_content(element, memo={text: '', spans: []})
180
- element.children.inject(memo) do |memo2, child|
195
+ def convert_text(element)
196
+ {
197
+ type: 'paragraph',
198
+ content: {
199
+ text: element.value,
200
+ spans: []
201
+ }
202
+ }
203
+ end
204
+
205
+ def extract_content(element, memo = { text: '', spans: [] })
206
+ element.children.each_with_object(memo) do |child, memo2|
181
207
  send("extract_span_#{child.type}", child, memo2)
182
- memo2
183
208
  end
184
209
  end
185
210
 
@@ -200,7 +225,7 @@ module Kramdown
200
225
  insert_span(element, memo, {
201
226
  type: 'hyperlink',
202
227
  data: {
203
- url: element.attr["href"]
228
+ url: element.attr['href']
204
229
  }
205
230
  })
206
231
  end
@@ -221,7 +246,7 @@ module Kramdown
221
246
  extract_content(element, memo)
222
247
  end
223
248
 
224
- def extract_span_br(element, memo)
249
+ def extract_span_br(_element, memo)
225
250
  memo[:text] += "\n"
226
251
  end
227
252
 
@@ -230,11 +255,11 @@ module Kramdown
230
255
  memo[:text] += element.value
231
256
  end
232
257
 
233
- def extract_span_html_element(element, memo)
258
+ def extract_span_html_element(_element, _memo)
234
259
  warning('translating html elements is not supported')
235
260
  end
236
261
 
237
- def extract_span_footnote(element, memo)
262
+ def extract_span_footnote(_element, _memo)
238
263
  warning('translating footnote is not supported')
239
264
  end
240
265
 
@@ -251,9 +276,9 @@ module Kramdown
251
276
  raquo_space: [::Kramdown::Utils::Entities.entity('nbsp'), ::Kramdown::Utils::Entities.entity('raquo')],
252
277
  laquo: [::Kramdown::Utils::Entities.entity('laquo')],
253
278
  raquo: [::Kramdown::Utils::Entities.entity('raquo')]
254
- }
279
+ }.freeze
255
280
  def extract_span_typographic_sym(element, memo)
256
- value = TYPOGRAPHIC_SYMS[element.value].map {|e| e.char }.join('')
281
+ value = TYPOGRAPHIC_SYMS[element.value].map(&:char).join('')
257
282
  memo[:text] += value
258
283
  end
259
284
 
@@ -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,21 +18,21 @@ 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(block)
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, {"src" => block[:data][:origin][:url], "alt" => block[:data][:alt]})
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(block)
35
+ def parse_preformatted(_block)
36
36
  Kramdown::Element.new(:blockquote)
37
37
  end
38
38
 
@@ -44,11 +44,10 @@ module Kramdown
44
44
  stack = []
45
45
 
46
46
  (block[:content][:text].size + 1).times do |index|
47
-
48
47
  starting_spans = find_starting_spans_for(block, index)
49
48
  ending_spans = find_ending_spans_for(block, index)
50
49
 
51
- ending_spans.each do |ending_span|
50
+ ending_spans.each do |_ending_span|
52
51
  el = stack.pop
53
52
  if stack.empty?
54
53
  element.children << el
@@ -57,22 +56,23 @@ module Kramdown
57
56
  end
58
57
  end
59
58
  starting_spans.each do |starting_span|
60
- stack << if starting_span[:type] == "hyperlink"
61
- Element.new(:a, nil, {'href' => starting_span[:data][:url]})
62
- else
63
- Element.new(starting_span[:type].to_sym)
64
- end
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
65
64
  end
66
65
 
67
66
  char = block[:content][:text][index]
68
67
  next if char.nil?
68
+
69
69
  current_text = if stack.empty?
70
- element.children.last
71
- else
72
- stack[-1].children.last
73
- end
70
+ element.children.last
71
+ else
72
+ stack[-1].children.last
73
+ end
74
74
  if current_text.nil? || current_text.type != :text
75
- current_text = Element.new(:text, "")
75
+ current_text = Element.new(:text, '')
76
76
  if stack.empty?
77
77
  element.children << current_text
78
78
  else
@@ -1,4 +1,5 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'minitest/autorun'
3
4
  require 'kramdown-prismic'
4
5
 
@@ -9,12 +10,12 @@ class KramdownPrismicConverterTest < Minitest::Test
9
10
  {
10
11
  type: "heading#{heading + 1}",
11
12
  content: {
12
- text: "This is the document title",
13
+ text: 'This is the document title',
13
14
  spans: []
14
15
  }
15
16
  }
16
17
  ]
17
- markdown = "#{"#" * (heading + 1)} This is the document title"
18
+ markdown = "#{'#' * (heading + 1)} This is the document title"
18
19
  assert_equal expected, Kramdown::Document.new(markdown, input: :kramdown).to_prismic
19
20
  end
20
21
  end
@@ -22,26 +23,26 @@ class KramdownPrismicConverterTest < Minitest::Test
22
23
  def test_convert_heading7
23
24
  expected = [
24
25
  {
25
- type: "heading6",
26
+ type: 'heading6',
26
27
  content: {
27
- text: "# This is the document title",
28
+ text: '# This is the document title',
28
29
  spans: []
29
30
  }
30
31
  }
31
32
  ]
32
- markdown = "####### This is the document title"
33
+ markdown = '####### This is the document title'
33
34
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
34
35
  end
35
36
 
36
37
  def test_convert_heading_with_spans
37
38
  expected = [
38
39
  {
39
- type: "heading2",
40
+ type: 'heading2',
40
41
  content: {
41
- text: "This is a document title",
42
+ text: 'This is a document title',
42
43
  spans: [
43
44
  {
44
- type: "em",
45
+ type: 'em',
45
46
  start: 0,
46
47
  end: 4
47
48
  }
@@ -49,56 +50,56 @@ class KramdownPrismicConverterTest < Minitest::Test
49
50
  }
50
51
  }
51
52
  ]
52
- markdown = "## *This* is a document title"
53
+ markdown = '## *This* is a document title'
53
54
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
54
55
  end
55
56
 
56
57
  def test_convert_paragraph
57
58
  expected = [
58
59
  {
59
- type: "paragraph",
60
+ type: 'paragraph',
60
61
  content: {
61
- text: "This is a paragraph",
62
+ text: 'This is a paragraph',
62
63
  spans: []
63
64
  }
64
65
  }
65
66
  ]
66
- markdown = "This is a paragraph"
67
+ markdown = 'This is a paragraph'
67
68
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
68
69
  end
69
70
 
70
71
  def test_convert_paragraph_with_spans
71
72
  expected = [
72
73
  {
73
- type: "paragraph",
74
+ type: 'paragraph',
74
75
  content: {
75
- text: "This is a paragraph",
76
+ text: 'This is a paragraph',
76
77
  spans: [
77
78
  {
78
- type: "hyperlink",
79
+ type: 'hyperlink',
79
80
  start: 0,
80
81
  end: 19,
81
82
  data: {
82
- url: "https://prismic.io"
83
+ url: 'https://prismic.io'
83
84
  }
84
85
  }
85
86
  ]
86
87
  }
87
88
  }
88
89
  ]
89
- markdown = "[This is a paragraph](https://prismic.io)"
90
+ markdown = '[This is a paragraph](https://prismic.io)'
90
91
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
91
92
  end
92
93
 
93
94
  def test_convert_paragraph_with_strong
94
95
  expected = [
95
96
  {
96
- type: "paragraph",
97
+ type: 'paragraph',
97
98
  content: {
98
- text: "This is a paragraph",
99
+ text: 'This is a paragraph',
99
100
  spans: [
100
101
  {
101
- type: "strong",
102
+ type: 'strong',
102
103
  start: 0,
103
104
  end: 19
104
105
  }
@@ -106,19 +107,19 @@ class KramdownPrismicConverterTest < Minitest::Test
106
107
  }
107
108
  }
108
109
  ]
109
- markdown = "**This is a paragraph**"
110
+ markdown = '**This is a paragraph**'
110
111
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
111
112
  end
112
113
 
113
114
  def test_convert_paragraph_with_strong2
114
115
  expected = [
115
116
  {
116
- type: "paragraph",
117
+ type: 'paragraph',
117
118
  content: {
118
- text: "This is a paragraph",
119
+ text: 'This is a paragraph',
119
120
  spans: [
120
121
  {
121
- type: "strong",
122
+ type: 'strong',
122
123
  start: 0,
123
124
  end: 4
124
125
  }
@@ -126,19 +127,19 @@ class KramdownPrismicConverterTest < Minitest::Test
126
127
  }
127
128
  }
128
129
  ]
129
- markdown = "**This** is a paragraph"
130
+ markdown = '**This** is a paragraph'
130
131
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
131
132
  end
132
133
 
133
134
  def test_convert_paragraph_with_em
134
135
  expected = [
135
136
  {
136
- type: "paragraph",
137
+ type: 'paragraph',
137
138
  content: {
138
- text: "This is a paragraph",
139
+ text: 'This is a paragraph',
139
140
  spans: [
140
141
  {
141
- type: "em",
142
+ type: 'em',
142
143
  start: 0,
143
144
  end: 4
144
145
  }
@@ -146,19 +147,19 @@ class KramdownPrismicConverterTest < Minitest::Test
146
147
  }
147
148
  }
148
149
  ]
149
- markdown = "*This* is a paragraph"
150
+ markdown = '*This* is a paragraph'
150
151
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
151
152
  end
152
153
 
153
154
  def test_convert_list_o
154
155
  expected = [
155
156
  {
156
- type: "o-list-item",
157
+ type: 'o-list-item',
157
158
  content: {
158
- text: "This is a list item",
159
+ text: 'This is a list item',
159
160
  spans: [
160
161
  {
161
- type: "em",
162
+ type: 'em',
162
163
  start: 0,
163
164
  end: 4
164
165
  }
@@ -166,9 +167,9 @@ class KramdownPrismicConverterTest < Minitest::Test
166
167
  }
167
168
  },
168
169
  {
169
- type: "o-list-item",
170
+ type: 'o-list-item',
170
171
  content: {
171
- text: "This is a second list item",
172
+ text: 'This is a second list item',
172
173
  spans: []
173
174
  }
174
175
  }
@@ -180,12 +181,12 @@ class KramdownPrismicConverterTest < Minitest::Test
180
181
  def test_convert_list_u
181
182
  expected = [
182
183
  {
183
- type: "list-item",
184
+ type: 'list-item',
184
185
  content: {
185
- text: "This is a list item",
186
+ text: 'This is a list item',
186
187
  spans: [
187
188
  {
188
- type: "em",
189
+ type: 'em',
189
190
  start: 0,
190
191
  end: 4
191
192
  }
@@ -193,9 +194,9 @@ class KramdownPrismicConverterTest < Minitest::Test
193
194
  }
194
195
  },
195
196
  {
196
- type: "list-item",
197
+ type: 'list-item',
197
198
  content: {
198
- text: "This is a second list item",
199
+ text: 'This is a second list item',
199
200
  spans: []
200
201
  }
201
202
  }
@@ -207,16 +208,16 @@ class KramdownPrismicConverterTest < Minitest::Test
207
208
  def test_convert_nested_ul
208
209
  expected = [
209
210
  {
210
- type: "list-item",
211
+ type: 'list-item',
211
212
  content: {
212
213
  text: "item1\n",
213
214
  spans: []
214
215
  }
215
216
  },
216
217
  {
217
- type: "list-item",
218
+ type: 'list-item',
218
219
  content: {
219
- text: "item2",
220
+ text: 'item2',
220
221
  spans: []
221
222
  }
222
223
  }
@@ -230,23 +231,23 @@ class KramdownPrismicConverterTest < Minitest::Test
230
231
  def test_convert_nested_nested_ul
231
232
  expected = [
232
233
  {
233
- type: "list-item",
234
+ type: 'list-item',
234
235
  content: {
235
236
  text: "item1\n",
236
237
  spans: []
237
238
  }
238
239
  },
239
240
  {
240
- type: "list-item",
241
+ type: 'list-item',
241
242
  content: {
242
243
  text: "item2\n",
243
244
  spans: []
244
245
  }
245
246
  },
246
247
  {
247
- type: "list-item",
248
+ type: 'list-item',
248
249
  content: {
249
- text: "item3",
250
+ text: 'item3',
250
251
  spans: []
251
252
  }
252
253
  }
@@ -260,7 +261,7 @@ class KramdownPrismicConverterTest < Minitest::Test
260
261
  def test_convert_preformatted
261
262
  expected = [
262
263
  {
263
- type: "preformatted",
264
+ type: 'preformatted',
264
265
  content: {
265
266
  text: "This is a pre block\n",
266
267
  spans: []
@@ -274,9 +275,9 @@ class KramdownPrismicConverterTest < Minitest::Test
274
275
  def test_convert_blockquote
275
276
  expected = [
276
277
  {
277
- type: "preformatted",
278
+ type: 'preformatted',
278
279
  content: {
279
- text: "This is a blockquote",
280
+ text: 'This is a blockquote',
280
281
  spans: []
281
282
  }
282
283
  }
@@ -287,17 +288,18 @@ class KramdownPrismicConverterTest < Minitest::Test
287
288
 
288
289
  def test_convert_empty
289
290
  expected = []
290
- markdown = ""
291
+ markdown = ''
291
292
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
292
293
  end
293
294
 
294
295
  def test_convert_span_blank
295
296
  expected = [
296
- {type: "o-list-item",
297
- content: {
298
- text: "Testtest",
299
- spans: []
300
- }
297
+ {
298
+ type: 'o-list-item',
299
+ content: {
300
+ text: 'Testtest',
301
+ spans: []
302
+ }
301
303
  }
302
304
  ]
303
305
  markdown = "\n1. Test\n\n test\n"
@@ -306,16 +308,16 @@ class KramdownPrismicConverterTest < Minitest::Test
306
308
 
307
309
  def test_convert_hr
308
310
  expected = []
309
- markdown = "---"
311
+ markdown = '---'
310
312
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
311
313
  end
312
314
 
313
315
  def test_convert_img
314
316
  expected = [
315
317
  {
316
- type: "image",
318
+ type: 'image',
317
319
  content: {
318
- text: "",
320
+ text: '',
319
321
  spans: []
320
322
  },
321
323
  data: {
@@ -326,7 +328,7 @@ class KramdownPrismicConverterTest < Minitest::Test
326
328
  }
327
329
  }
328
330
  ]
329
- markdown = "![alt text](/img.png)"
331
+ markdown = '![alt text](/img.png)'
330
332
  doc = Kramdown::Document.new(markdown)
331
333
  assert_equal expected, doc.to_prismic
332
334
  assert_equal 0, doc.warnings.size
@@ -335,9 +337,9 @@ class KramdownPrismicConverterTest < Minitest::Test
335
337
  def test_convert_double_img
336
338
  expected = [
337
339
  {
338
- type: "image",
340
+ type: 'image',
339
341
  content: {
340
- text: "",
342
+ text: '',
341
343
  spans: []
342
344
  },
343
345
  data: {
@@ -348,9 +350,9 @@ class KramdownPrismicConverterTest < Minitest::Test
348
350
  }
349
351
  },
350
352
  {
351
- type: "image",
353
+ type: 'image',
352
354
  content: {
353
- text: "",
355
+ text: '',
354
356
  spans: []
355
357
  },
356
358
  data: {
@@ -361,7 +363,7 @@ class KramdownPrismicConverterTest < Minitest::Test
361
363
  }
362
364
  }
363
365
  ]
364
- markdown = "![](/img.png)![](/img2.png)"
366
+ markdown = '![](/img.png)![](/img2.png)'
365
367
  doc = Kramdown::Document.new(markdown)
366
368
  assert_equal expected, doc.to_prismic
367
369
  assert_equal 2, doc.warnings.size
@@ -370,9 +372,9 @@ class KramdownPrismicConverterTest < Minitest::Test
370
372
  def test_convert_img_with_link
371
373
  expected = [
372
374
  {
373
- type: "image",
375
+ type: 'image',
374
376
  content: {
375
- text: "",
377
+ text: '',
376
378
  spans: []
377
379
  },
378
380
  data: {
@@ -381,12 +383,12 @@ class KramdownPrismicConverterTest < Minitest::Test
381
383
  },
382
384
  alt: 'alt text',
383
385
  linkTo: {
384
- url: "https://example.net/"
386
+ url: 'https://example.net/'
385
387
  }
386
388
  }
387
389
  }
388
390
  ]
389
- markdown = "[![alt text](/img.png)](https://example.net/)"
391
+ markdown = '[![alt text](/img.png)](https://example.net/)'
390
392
  doc = Kramdown::Document.new(markdown)
391
393
  assert_equal expected, doc.to_prismic
392
394
  assert_equal 0, doc.warnings.size
@@ -395,29 +397,28 @@ class KramdownPrismicConverterTest < Minitest::Test
395
397
  def test_convert_entity
396
398
  expected = [
397
399
  {
398
- type: "paragraph",
400
+ type: 'paragraph',
399
401
  content: {
400
402
  text: "\u00a0",
401
403
  spans: []
402
404
  }
403
405
  }
404
406
  ]
405
- markdown = "&nbsp;"
407
+ markdown = '&nbsp;'
406
408
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
407
409
  end
408
410
 
409
- [['mdash' , ' ---', ' —'],
410
- ['ndash' , ' --', ' –'],
411
- ['hellip' , ' ...', ' …'],
412
- ['laquo' , ' <<', ' «'],
413
- ['raquo' , '>>', '»'],
414
- ['laquo_space' , ' << T', ' « T'],
415
- ['raquo_space' , ' >>', ' »']
416
- ].each do |symbol|
411
+ [['mdash', ' ---', ' —'],
412
+ ['ndash', ' --', ' –'],
413
+ ['hellip', ' ...', ' …'],
414
+ ['laquo', ' <<', ' «'],
415
+ ['raquo', '>>', '»'],
416
+ ['laquo_space', ' << T', ' « T'],
417
+ ['raquo_space', ' >>', ' »']].each do |symbol|
417
418
  define_method "test_convert_typographic_symbols_#{symbol[0]}" do
418
419
  expected = [
419
420
  {
420
- type: "paragraph",
421
+ type: 'paragraph',
421
422
  content: {
422
423
  text: "Hello#{symbol[2]}",
423
424
  spans: []
@@ -431,11 +432,12 @@ class KramdownPrismicConverterTest < Minitest::Test
431
432
 
432
433
  def test_convert_smart_quote
433
434
  expected = [
434
- {type: "paragraph",
435
- content: {
436
- text: "Test\u2019",
437
- spans: []
438
- }
435
+ {
436
+ type: 'paragraph',
437
+ content: {
438
+ text: "Test\u2019",
439
+ spans: []
440
+ }
439
441
  }
440
442
  ]
441
443
  markdown = "Test'"
@@ -445,14 +447,14 @@ class KramdownPrismicConverterTest < Minitest::Test
445
447
  def test_convert_inline_code
446
448
  expected = [
447
449
  {
448
- type: "paragraph",
450
+ type: 'paragraph',
449
451
  content: {
450
- text: "Hello code",
452
+ text: 'Hello code',
451
453
  spans: []
452
454
  }
453
455
  }
454
456
  ]
455
- markdown = "Hello `code`"
457
+ markdown = 'Hello `code`'
456
458
  doc = Kramdown::Document.new(markdown)
457
459
  assert_equal expected, doc.to_prismic
458
460
  assert_equal 1, doc.warnings.size
@@ -460,20 +462,54 @@ class KramdownPrismicConverterTest < Minitest::Test
460
462
 
461
463
  def test_convert_br
462
464
  expected = [
463
- {type: "paragraph",
464
- content: {
465
- text: "Test\n",
466
- spans: []
467
- }
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
+ }
468
485
  }
469
486
  ]
470
- html = "<p>Test<br></p>"
487
+ html = 'Test'
471
488
  assert_equal expected, Kramdown::Document.new(html, input: :html).to_prismic
472
489
  end
473
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
+
474
510
  def test_convert_html
475
511
  expected = []
476
- html = "<div></div>"
512
+ html = '<div></div>'
477
513
  doc = Kramdown::Document.new(html, input: :markdown)
478
514
  assert_equal expected, doc.to_prismic
479
515
  assert_equal 1, doc.warnings.size
@@ -482,14 +518,14 @@ class KramdownPrismicConverterTest < Minitest::Test
482
518
  def test_convert_span_html
483
519
  expected = [
484
520
  {
485
- type: "paragraph",
521
+ type: 'paragraph',
486
522
  content: {
487
- text: "",
523
+ text: '',
488
524
  spans: []
489
525
  }
490
526
  }
491
527
  ]
492
- html = "<br>"
528
+ html = '<br>'
493
529
  doc = Kramdown::Document.new(html, input: :markdown)
494
530
  assert_equal expected, doc.to_prismic
495
531
  assert_equal 1, doc.warnings.size
@@ -497,7 +533,7 @@ class KramdownPrismicConverterTest < Minitest::Test
497
533
 
498
534
  def test_convert_table
499
535
  expected = []
500
- markdown = "| First cell|Second cell|Third cell|"
536
+ markdown = '| First cell|Second cell|Third cell|'
501
537
  doc = Kramdown::Document.new(markdown, input: :kramdown)
502
538
  assert_equal expected, doc.to_prismic
503
539
  assert_equal 1, doc.warnings.size
@@ -513,7 +549,7 @@ class KramdownPrismicConverterTest < Minitest::Test
513
549
 
514
550
  def test_convert_math
515
551
  expected = []
516
- markdown = "$$ 5 + 5 $$"
552
+ markdown = '$$ 5 + 5 $$'
517
553
  doc = Kramdown::Document.new(markdown, input: :kramdown)
518
554
  assert_equal expected, doc.to_prismic
519
555
  assert_equal 1, doc.warnings.size
@@ -522,12 +558,13 @@ class KramdownPrismicConverterTest < Minitest::Test
522
558
  def test_convert_footnote
523
559
  expected = [
524
560
  {
525
- type: "paragraph",
561
+ type: 'paragraph',
526
562
  content: {
527
- text: "test",
563
+ text: 'test',
528
564
  spans: []
529
565
  }
530
- }]
566
+ }
567
+ ]
531
568
  markdown = "test[^1]\n\n[^1]: test"
532
569
  doc = Kramdown::Document.new(markdown, input: :kramdown)
533
570
  assert_equal expected, doc.to_prismic
@@ -537,12 +574,13 @@ class KramdownPrismicConverterTest < Minitest::Test
537
574
  def test_convert_abbreviation
538
575
  expected = [
539
576
  {
540
- type: "paragraph",
577
+ type: 'paragraph',
541
578
  content: {
542
- text: "HTML",
579
+ text: 'HTML',
543
580
  spans: []
544
581
  }
545
- }]
582
+ }
583
+ ]
546
584
  markdown = "HTML\n\n*[HTML]: test"
547
585
  doc = Kramdown::Document.new(markdown, input: :kramdown)
548
586
  assert_equal expected, doc.to_prismic
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: []
12
- }
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: []
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
+ }
27
16
  }
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
  ]
@@ -150,9 +139,9 @@ class KramdownPrismicParserTest < Minitest::Test
150
139
  def test_parse_image
151
140
  prismic = [
152
141
  {
153
- type: "image",
142
+ type: 'image',
154
143
  content: {
155
- text: "",
144
+ text: '',
156
145
  spans: []
157
146
  },
158
147
  data: {
@@ -171,7 +160,7 @@ class KramdownPrismicParserTest < Minitest::Test
171
160
  def test_parse_preformatted
172
161
  prismic = [
173
162
  {
174
- type: "preformatted",
163
+ type: 'preformatted',
175
164
  content: {
176
165
  text: "This is a pre block\n",
177
166
  spans: []
@@ -186,13 +175,13 @@ class KramdownPrismicParserTest < Minitest::Test
186
175
  def test_parse_embed
187
176
  prismic = [
188
177
  {
189
- type: "embed",
178
+ type: 'embed',
190
179
  data: {
191
- type: "video",
192
- embed_url: "https://www.youtube.com/watch?v=y6y_4_b6RS8"
180
+ type: 'video',
181
+ embed_url: 'https://www.youtube.com/watch?v=y6y_4_b6RS8'
193
182
  },
194
183
  content: {
195
- text: "",
184
+ text: '',
196
185
  spans: []
197
186
  }
198
187
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown-prismic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
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-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -61,19 +61,24 @@ dependencies:
61
61
  description: A Kramdown converter to convert documents into prismic rich text format
62
62
  and the other way around.
63
63
  email: francois@2metz.fr
64
- executables: []
64
+ executables:
65
+ - markdown2prismic
66
+ - html2prismic
67
+ - prismic2markdown
65
68
  extensions: []
66
69
  extra_rdoc_files: []
67
70
  files:
68
71
  - ".github/workflows/ci.yml"
69
72
  - ".gitignore"
70
- - ".travis.yml"
71
- - Changelog.md
73
+ - CHANGELOG.md
72
74
  - Gemfile
73
75
  - Gemfile.lock
74
76
  - LICENSE
75
77
  - README.md
76
78
  - Rakefile
79
+ - bin/html2prismic
80
+ - bin/markdown2prismic
81
+ - bin/prismic2markdown
77
82
  - kramdown-prismic.gemspec
78
83
  - kramdown1.gemfile
79
84
  - kramdown2.gemfile
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