kramdown-prismic 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: ae42e32a63e34a7692e2f6dd7af5ec86638bb253
4
- data.tar.gz: 0eecb39a28de782cb45e5dba7dbceed5d07b356a
3
+ metadata.gz: 5465bc67c1f2cc29208888f196e1a2eb3b67abf6
4
+ data.tar.gz: 421a8ce16fea41e776293fa57bdaf39ea3f029a8
5
5
  SHA512:
6
- metadata.gz: c231aed1d32708a75cc1812595970aa470b3d5d185916a414484a624c6ec7d1051299690201629b551ca47e53e6449f94ede6b4c0f31e0315fc88553635c692b
7
- data.tar.gz: 2564bfd26fb1a5aa616610f6f4dfd6ecd2523c7ec191f5c179afbf5cdaf1f9f8f92b15ad7abfaabe141239875478f03a21687ece16bdc3a681751123323c4cc3
6
+ metadata.gz: bd90c77232680328ee30a3a08a3b7b434cf69255de143dfa40c4ff0e44beb4c5345b5c65dca726771596b5697eeb9dbca3bab17253d77d456133e2e34a18ed85
7
+ data.tar.gz: b75ef505d3fb1f7b4cb389cf7a026b45babb98b0322ee6d626b4a81da06b17206db48fde683b916affc4e64fc24ef6cd07802ec531f7ceba8f93b9cbd41ba5c6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kramdown-prismic (0.0.2)
4
+ kramdown-prismic (0.0.3)
5
5
  kramdown (~> 1.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -21,7 +21,7 @@ TODO:
21
21
  - [x] hyperlink
22
22
  - [x] o-list-item
23
23
  - [x] list-item
24
- - [ ] Image
24
+ - [x] Image
25
25
  - [ ] Embed
26
26
 
27
27
  ## Difference between markdown and rich text
@@ -30,10 +30,12 @@ TODO:
30
30
  |------------------|----------------------------|
31
31
  | Blockquote | translated to preformatted |
32
32
  | hr | nothing |
33
- | img | moved to to level |
33
+ | img | moved to the top level |
34
+ | nested list | moved to the top level |
35
+ | br | |
34
36
  | dl | |
35
37
  | dt | |
36
- | dl | |
38
+ | dd | |
37
39
  | table | |
38
40
  | thead | |
39
41
  | tobdy | |
@@ -42,11 +44,11 @@ TODO:
42
44
  | td | |
43
45
  | math | |
44
46
  | footnote | |
45
- | entity | |
47
+ | entity | Transformed to unicode |
46
48
  | typographic_sym | |
47
49
  | smart_quote | |
48
50
  | abbreviation | |
49
- | html_element | |
51
+ | html_element | not supported |
50
52
  | xml_comment | |
51
53
  | xml_pi | |
52
54
  | comment | |
@@ -1,3 +1,3 @@
1
1
  module KramdownPrismic
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -4,27 +4,42 @@ module Kramdown
4
4
  module Converter
5
5
  class Prismic < Base
6
6
  def convert(root)
7
- move_img_to_top_level(root).map { |child|
7
+ cleanup_ast(root).map { |child|
8
8
  convert_element(child)
9
9
  }.compact.flatten
10
10
  end
11
11
 
12
12
  private
13
13
 
14
- def move_img_to_top_level(root)
14
+ def cleanup_ast(root)
15
+ remove_blanks(root)
15
16
  root.children.map do |child|
16
- imgs = find_imgs(child)
17
- [child, imgs]
17
+ elements = extract_non_nestable_elements(child)
18
+ [child, elements]
18
19
  end.flatten.compact
19
20
  end
20
21
 
21
- def find_imgs(child)
22
+ 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
27
+ remove_blanks(child)
28
+ end
29
+ end
30
+ end
31
+
32
+ def extract_non_nestable_elements(child)
22
33
  child.children.map do |element|
23
34
  if element.type == :img
24
35
  child.children.slice!(child.children.find_index(element))
25
36
  element
37
+ elsif element.type == :ul
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)]
26
41
  else
27
- find_imgs(element)
42
+ extract_non_nestable_elements(element)
28
43
  end
29
44
  end
30
45
  end
@@ -33,9 +48,6 @@ module Kramdown
33
48
  send("convert_#{element.type}", element)
34
49
  end
35
50
 
36
- def convert_blank(element)
37
- end
38
-
39
51
  def convert_header(element)
40
52
  {
41
53
  type: "heading#{element.options[:level]}",
@@ -149,6 +161,14 @@ module Kramdown
149
161
  extract_content(element, memo)
150
162
  end
151
163
 
164
+ def extract_span_br(element, memo)
165
+ memo[:text] += "\n"
166
+ end
167
+
168
+ def extract_span_html_element(element, memo)
169
+ warning('translating html elements is not supported')
170
+ end
171
+
152
172
  def extract_span_entity(element, memo)
153
173
  memo[:text] += unicode_char(element.value.code_point)
154
174
  end
@@ -201,6 +201,59 @@ class KramdownPrismicTest < Minitest::Test
201
201
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
202
202
  end
203
203
 
204
+ def test_convert_nested_ul
205
+ expected = [
206
+ {
207
+ type: "list-item",
208
+ content: {
209
+ text: "item1\n",
210
+ spans: []
211
+ }
212
+ },
213
+ {
214
+ type: "list-item",
215
+ content: {
216
+ text: "item2",
217
+ spans: []
218
+ }
219
+ }
220
+ ]
221
+ markdown = "- item1\n - item2"
222
+ doc = Kramdown::Document.new(markdown, input: :markdown)
223
+ assert_equal expected, doc.to_prismic
224
+ assert_equal 1, doc.warnings.size
225
+ end
226
+
227
+ def test_convert_nested_nested_ul
228
+ expected = [
229
+ {
230
+ type: "list-item",
231
+ content: {
232
+ text: "item1\n",
233
+ spans: []
234
+ }
235
+ },
236
+ {
237
+ type: "list-item",
238
+ content: {
239
+ text: "item2\n",
240
+ spans: []
241
+ }
242
+ },
243
+ {
244
+ type: "list-item",
245
+ content: {
246
+ text: "item3",
247
+ spans: []
248
+ }
249
+ }
250
+ ]
251
+ markdown = "- item1\n - item2\n - item3"
252
+ doc = Kramdown::Document.new(markdown, input: :markdown)
253
+ assert_equal expected, doc.to_prismic
254
+ assert_equal 2, doc.warnings.size
255
+ end
256
+
204
257
  def test_convert_preformatted
205
258
  expected = [
206
259
  {
@@ -235,6 +288,19 @@ class KramdownPrismicTest < Minitest::Test
235
288
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
236
289
  end
237
290
 
291
+ def test_convert_span_blank
292
+ expected = [
293
+ {type: "o-list-item",
294
+ content: {
295
+ text: "Testtest",
296
+ spans: []
297
+ }
298
+ }
299
+ ]
300
+ markdown = "1. Test\n\n test"
301
+ assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
302
+ end
303
+
238
304
  def test_convert_hr
239
305
  expected = []
240
306
  markdown = "---"
@@ -277,4 +343,32 @@ class KramdownPrismicTest < Minitest::Test
277
343
  markdown = "&nbsp;"
278
344
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
279
345
  end
346
+
347
+ def test_convert_br
348
+ expected = [
349
+ {type: "paragraph",
350
+ content: {
351
+ text: "Test\n",
352
+ spans: []
353
+ }
354
+ }
355
+ ]
356
+ html = "<p>Test<br></p>"
357
+ assert_equal expected, Kramdown::Document.new(html, input: :html).to_prismic
358
+ end
359
+
360
+ def test_convert_span_html
361
+ expected = [
362
+ {type: "paragraph",
363
+ content: {
364
+ text: "",
365
+ spans: []
366
+ }
367
+ }
368
+ ]
369
+ html = "<br>"
370
+ doc = Kramdown::Document.new(html, input: :markdown)
371
+ assert_equal expected, doc.to_prismic
372
+ assert_equal 1, doc.warnings.size
373
+ end
280
374
  end
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.0.3
4
+ version: 0.0.4
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: 2017-10-29 00:00:00.000000000 Z
11
+ date: 2017-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown