kramdown-prismic 0.0.6 → 0.1.0

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: c8f60ad20cbfb6c159e57a59ea79acf3123ba6a3
4
- data.tar.gz: 28bd2d6a6faf005cbc406ea2c4381369b5499d10
3
+ metadata.gz: 6b30034b89cbc5bbfe5613435382d48f332000ac
4
+ data.tar.gz: d546c799b441b0c7802221f668da8b573d48f9be
5
5
  SHA512:
6
- metadata.gz: d5726fb2ec12cf1c292691b0e92dff4065f42f29bbdf2c7d101a7959faaf5dfb2f823b17133fdb689a31cac08e96b043724e78270f8f9d517bd27e195f593531
7
- data.tar.gz: 72a178508efc47257ea3c21970ee3524f307ccfb58df87f7b889caced19b8e442f746de9d7af5433f58aaacd5d65af22fabdf170ff1ba860edc1a05d6edd4e81
6
+ metadata.gz: 31b0d991eb6a2dedb3b7ad156bdf0782437fe59049b4a5444ec48f4fb269504d203ed5fcfdc79e8c77eaef73462dff4e9e85ad4f5abaf03fd84848a5f2adc012
7
+ data.tar.gz: 56cb4219036f891f893dc12e1ec1e98d0bb1f80bee1ae7168c8b780644e049273f894e278cb6771f76ec327fd0b5797b5a6dc2f72c46dbec776972e30d79cf2d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kramdown-prismic (0.0.5)
4
+ kramdown-prismic (0.1.0)
5
5
  kramdown (~> 1.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -4,27 +4,9 @@ A Kramdown converter to convert documents into prismic rich text format.
4
4
 
5
5
  ## Status
6
6
 
7
- *Very early*, still a proof of concept.
7
+ Most of the content is translated. See the table below to see the difference:
8
8
 
9
- TODO:
10
-
11
- - [x] heading1
12
- - [x] heading2
13
- - [x] heading3
14
- - [x] heading4
15
- - [x] heading5
16
- - [x] heading6
17
- - [x] paragraph
18
- - [x] preformatted
19
- - [x] strong
20
- - [x] em
21
- - [x] hyperlink
22
- - [x] o-list-item
23
- - [x] list-item
24
- - [x] Image
25
- - [ ] Embed
26
-
27
- ## Difference between markdown and rich text
9
+ ### Difference between markdown and rich text
28
10
 
29
11
  | Markdown | Prismic |
30
12
  |------------------|----------------------------|
@@ -32,31 +14,32 @@ TODO:
32
14
  | hr | nothing |
33
15
  | img | moved to the top level |
34
16
  | nested list | moved to the top level |
35
- | br | |
36
- | dl | |
37
- | dt | |
38
- | dd | |
39
- | table | |
40
- | thead | |
41
- | tobdy | |
42
- | tfoot | |
43
- | tr | |
44
- | td | |
45
- | math | |
46
- | footnote | |
17
+ | dl | not supported |
18
+ | dt | not supported |
19
+ | dd | not supported |
20
+ | table | not supported |
21
+ | thead | not supported |
22
+ | tobdy | not supported |
23
+ | tfoot | not supported |
24
+ | tr | not supported |
25
+ | td | not supported |
26
+ | math | not supported |
27
+ | footnote | not supported |
47
28
  | entity | Transformed to unicode |
48
- | typographic_sym | |
49
- | smart_quote | |
50
- | abbreviation | |
29
+ | typographic_sym | Transformed to unicode |
30
+ | smart_quote | Transformed to unicode |
31
+ | abbreviation | not supported |
51
32
  | html_element | not supported |
52
- | xml_comment | |
53
- | xml_pi | |
54
- | comment | |
55
- | raw | |
33
+ | xml_comment | not supported |
34
+ | xml_pi | not supported |
35
+ | comment | not supported |
36
+ | raw | not supported |
56
37
 
57
38
  ## Install
58
39
 
59
- Not yet available on rubygems
40
+ ```ruby
41
+ gem 'kramdown-prismic', '~> 0.1'
42
+ ```
60
43
 
61
44
  ## Usage
62
45
 
@@ -1,3 +1,3 @@
1
1
  module KramdownPrismic
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -34,6 +34,7 @@ module Kramdown
34
34
  child.children = child.children.inject([]) do |memo, element|
35
35
  if element.type == :img
36
36
  elements << element
37
+ warning('images inside content will be moved to the top level and may be rendered differently') if child.children.size > 1
37
38
  elsif element.type == :ul
38
39
  warning('nested list moved to the top level')
39
40
  elements << element
@@ -113,7 +114,8 @@ module Kramdown
113
114
  spans: []
114
115
  },
115
116
  data: {
116
- url: element.attr["src"]
117
+ url: element.attr["src"],
118
+ alt: element.attr["alt"]
117
119
  }
118
120
  }
119
121
  end
@@ -123,6 +125,41 @@ module Kramdown
123
125
  nil
124
126
  end
125
127
 
128
+ def convert_table(element)
129
+ warning('translating table is not supported')
130
+ nil
131
+ end
132
+
133
+ def convert_dl(element)
134
+ warning('translating dl is not supported')
135
+ nil
136
+ end
137
+
138
+ def convert_math(element)
139
+ warning('translating math is not supported')
140
+ nil
141
+ end
142
+
143
+ def convert_comment(element)
144
+ warning('translating comment is not supported')
145
+ nil
146
+ end
147
+
148
+ def convert_xml_comment(element)
149
+ warning('translating xml_comment is not supported')
150
+ nil
151
+ end
152
+
153
+ def convert_xml_pi(element)
154
+ warning('translating xml_pi is not supported')
155
+ nil
156
+ end
157
+
158
+ def convert_raw(element)
159
+ warning('translating raw is not supported')
160
+ nil
161
+ end
162
+
126
163
  def extract_content(element, memo={text: '', spans: []})
127
164
  element.children.inject(memo) do |memo2, child|
128
165
  send("extract_span_#{child.type}", child, memo2)
@@ -176,12 +213,35 @@ module Kramdown
176
213
  warning('translating html elements is not supported')
177
214
  end
178
215
 
216
+ def extract_span_footnote(element, memo)
217
+ warning('translating footnote is not supported')
218
+ end
219
+
220
+ def extract_span_abbreviation(element, memo)
221
+ warning('translating abbreviation is not supported')
222
+ memo[:text] += element.value
223
+ end
224
+
225
+ TYPOGRAPHIC_SYMS = {
226
+ mdash: [::Kramdown::Utils::Entities.entity('mdash')],
227
+ ndash: [::Kramdown::Utils::Entities.entity('ndash')],
228
+ hellip: [::Kramdown::Utils::Entities.entity('hellip')],
229
+ laquo_space: [::Kramdown::Utils::Entities.entity('laquo'), ::Kramdown::Utils::Entities.entity('nbsp')],
230
+ raquo_space: [::Kramdown::Utils::Entities.entity('nbsp'), ::Kramdown::Utils::Entities.entity('raquo')],
231
+ laquo: [::Kramdown::Utils::Entities.entity('laquo')],
232
+ raquo: [::Kramdown::Utils::Entities.entity('raquo')]
233
+ }
234
+ def extract_span_typographic_sym(element, memo)
235
+ value = TYPOGRAPHIC_SYMS[element.value].map {|e| e.char }.join('')
236
+ memo[:text] += value
237
+ end
238
+
179
239
  def extract_span_entity(element, memo)
180
- memo[:text] += unicode_char(element.value.code_point)
240
+ memo[:text] += element.value.char
181
241
  end
182
242
 
183
- def unicode_char(codepoint)
184
- Utils::Entities::Entity.new(codepoint, '').char
243
+ def extract_span_smart_quote(element, memo)
244
+ memo[:text] += ::Kramdown::Utils::Entities.entity(element.value.to_s).char
185
245
  end
186
246
  end
187
247
  end
@@ -323,12 +323,15 @@ class KramdownPrismicTest < Minitest::Test
323
323
  spans: []
324
324
  },
325
325
  data: {
326
- url: '/img.png'
326
+ url: '/img.png',
327
+ alt: 'alt text'
327
328
  }
328
329
  }
329
330
  ]
330
- markdown = "![](/img.png)"
331
- assert_equal expected, Kramdown::Document.new(markdown).to_prismic
331
+ markdown = "![alt text](/img.png)"
332
+ doc = Kramdown::Document.new(markdown)
333
+ assert_equal expected, doc.to_prismic
334
+ assert_equal 0, doc.warnings.size
332
335
  end
333
336
 
334
337
  def test_convert_double_img
@@ -347,7 +350,8 @@ class KramdownPrismicTest < Minitest::Test
347
350
  spans: []
348
351
  },
349
352
  data: {
350
- url: '/img.png'
353
+ url: '/img.png',
354
+ alt: ''
351
355
  }
352
356
  },
353
357
  {
@@ -357,25 +361,65 @@ class KramdownPrismicTest < Minitest::Test
357
361
  spans: []
358
362
  },
359
363
  data: {
360
- url: '/img2.png'
364
+ url: '/img2.png',
365
+ alt: ''
361
366
  }
362
367
  }
363
368
  ]
364
369
  markdown = "![](/img.png)![](/img2.png)"
365
- assert_equal expected, Kramdown::Document.new(markdown).to_prismic
370
+ doc = Kramdown::Document.new(markdown)
371
+ assert_equal expected, doc.to_prismic
372
+ assert_equal 2, doc.warnings.size
366
373
  end
367
374
 
368
375
  def test_convert_entity
376
+ expected = [
377
+ {
378
+ type: "paragraph",
379
+ content: {
380
+ text: "\u00a0",
381
+ spans: []
382
+ }
383
+ }
384
+ ]
385
+ markdown = "&nbsp;"
386
+ assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
387
+ end
388
+
389
+ [['mdash' , ' ---', ' —'],
390
+ ['ndash' , ' --', ' –'],
391
+ ['hellip' , ' ...', ' …'],
392
+ ['laquo' , ' <<', ' «'],
393
+ ['raquo' , '>>', '»'],
394
+ ['laquo_space' , ' << T', ' « T'],
395
+ ['raquo_space' , ' >>', ' »']
396
+ ].each do |symbol|
397
+ define_method "test_convert_typographic_symbols_#{symbol[0]}" do
398
+ expected = [
399
+ {
400
+ type: "paragraph",
401
+ content: {
402
+ text: "Hello#{symbol[2]}",
403
+ spans: []
404
+ }
405
+ }
406
+ ]
407
+ markdown = "Hello#{symbol[1]}"
408
+ assert_equal expected, Kramdown::Document.new(markdown, input: :kramdown).to_prismic
409
+ end
410
+ end
411
+
412
+ def test_convert_smart_quote
369
413
  expected = [
370
414
  {type: "paragraph",
371
415
  content: {
372
- text: "\u00a0",
416
+ text: "Test\u2019",
373
417
  spans: []
374
418
  }
375
419
  }
376
420
  ]
377
- markdown = "&nbsp;"
378
- assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
421
+ markdown = "Test'"
422
+ assert_equal expected, Kramdown::Document.new(markdown, input: :kramdown).to_prismic
379
423
  end
380
424
 
381
425
  def test_convert_br
@@ -401,11 +445,12 @@ class KramdownPrismicTest < Minitest::Test
401
445
 
402
446
  def test_convert_span_html
403
447
  expected = [
404
- {type: "paragraph",
405
- content: {
406
- text: "",
407
- spans: []
408
- }
448
+ {
449
+ type: "paragraph",
450
+ content: {
451
+ text: "",
452
+ spans: []
453
+ }
409
454
  }
410
455
  ]
411
456
  html = "<br>"
@@ -413,4 +458,90 @@ class KramdownPrismicTest < Minitest::Test
413
458
  assert_equal expected, doc.to_prismic
414
459
  assert_equal 1, doc.warnings.size
415
460
  end
461
+
462
+ def test_convert_table
463
+ expected = []
464
+ markdown = "| First cell|Second cell|Third cell|"
465
+ doc = Kramdown::Document.new(markdown, input: :kramdown)
466
+ assert_equal expected, doc.to_prismic
467
+ assert_equal 1, doc.warnings.size
468
+ end
469
+
470
+ def test_convert_definition
471
+ expected = []
472
+ markdown = "kramdown\n: A Markdown-superset converter"
473
+ doc = Kramdown::Document.new(markdown, input: :kramdown)
474
+ assert_equal expected, doc.to_prismic
475
+ assert_equal 1, doc.warnings.size
476
+ end
477
+
478
+ def test_convert_math
479
+ expected = []
480
+ markdown = "$$ 5 + 5 $$"
481
+ doc = Kramdown::Document.new(markdown, input: :kramdown)
482
+ assert_equal expected, doc.to_prismic
483
+ assert_equal 1, doc.warnings.size
484
+ end
485
+
486
+ def test_convert_footnote
487
+ expected = [
488
+ {
489
+ type: "paragraph",
490
+ content: {
491
+ text: "test",
492
+ spans: []
493
+ }
494
+ }]
495
+ markdown = "test[^1]\n\n[^1]: test"
496
+ doc = Kramdown::Document.new(markdown, input: :kramdown)
497
+ assert_equal expected, doc.to_prismic
498
+ assert_equal 1, doc.warnings.size
499
+ end
500
+
501
+ def test_convert_abbreviation
502
+ expected = [
503
+ {
504
+ type: "paragraph",
505
+ content: {
506
+ text: "HTML",
507
+ spans: []
508
+ }
509
+ }]
510
+ markdown = "HTML\n\n*[HTML]: test"
511
+ doc = Kramdown::Document.new(markdown, input: :kramdown)
512
+ assert_equal expected, doc.to_prismic
513
+ assert_equal 1, doc.warnings.size
514
+ end
515
+
516
+ def test_convert_comment
517
+ expected = []
518
+ markdown = "{::comment}\nComment\n{:/comment}"
519
+ doc = Kramdown::Document.new(markdown, input: :kramdown)
520
+ assert_equal expected, doc.to_prismic
521
+ assert_equal 1, doc.warnings.size
522
+ end
523
+
524
+ def test_convert_xml_comment
525
+ expected = []
526
+ markdown = "<!-- a *comment* -->"
527
+ doc = Kramdown::Document.new(markdown, input: :kramdown)
528
+ assert_equal expected, doc.to_prismic
529
+ assert_equal 1, doc.warnings.size
530
+ end
531
+
532
+ def test_convert_xml_pi
533
+ expected = []
534
+ markdown = "<? a processing `instruction`?>"
535
+ doc = Kramdown::Document.new(markdown, input: :kramdown)
536
+ assert_equal expected, doc.to_prismic
537
+ assert_equal 1, doc.warnings.size
538
+ end
539
+
540
+ def test_convert_raw
541
+ expected = []
542
+ markdown = "{::nomarkdown}\nComment\n{:/nomarkdown}"
543
+ doc = Kramdown::Document.new(markdown, input: :kramdown)
544
+ assert_equal expected, doc.to_prismic
545
+ assert_equal 1, doc.warnings.size
546
+ end
416
547
  end
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.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - François de Metz