kramdown-prismic 0.3.5 → 0.3.8

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: fe3e038c22a918d48b71b44a5b4910910bd8b47bf18516244510ba3e2ddc5602
4
- data.tar.gz: 6d0280c72a7efee6a1edc6b15c06068c014c1eb21c3950fbc9768a8f0942ca92
3
+ metadata.gz: b7a99099eccb44fd82519a9894193733e143af6fbe445a88db2f805cb44fd58d
4
+ data.tar.gz: 68f3628a12418f3b49db676257266100c54a8a5962e88c5a5dd38bae7ac33ec5
5
5
  SHA512:
6
- metadata.gz: 99c4e82d82ae1d57b66747991976660aff280a52f346b7d459f80b3d8b86d6829eaf2bc966b6387cd4aec1fb2fbf7819db8c40e57da28f9a2c583cb1482965e7
7
- data.tar.gz: c7c91856d596c6f4441e333f00830facddcf744ab588bccd02f25e2ad749b700b6fcae7aeb3181c7261b3f1bce0e21f07dfa2fa504de9f8e5c9bc8a41d21be37
6
+ metadata.gz: 6c98ec156b50ac771e18415a770068c2a84911d34fe2b2fe083c7eab4a3f0e311d0aad0a71ed625e4a4d85da49fb6f9cb612f317a2a87814dbca93505cb2a977
7
+ data.tar.gz: 65f6a3250e46ec0e6d256fa42cebd6feb5036ca4564ee5d3ff172bf911a7b520119451fec8bde608108f57d79850b3a7a7619adc29a4119b61553ba91d59d08a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 0.3.8
4
+
5
+ - Convert nested html_elements when converting from HTML.
6
+
7
+ ## Version 0.3.7
8
+
9
+ - Fix converting nested headers
10
+
11
+ ## Version 0.3.6
12
+
13
+ - Fix converting nested numbered list.
14
+
3
15
  ## Version 0.3.5
4
16
 
5
17
  - Convert `br` element when converting HTML documents.
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kramdown-prismic (0.3.5)
4
+ kramdown-prismic (0.3.8)
5
5
  kramdown (>= 1, < 3)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- kramdown (2.3.1)
10
+ kramdown (2.3.2)
11
11
  rexml
12
12
  minitest (5.10.3)
13
13
  rake (13.0.6)
@@ -40,10 +40,14 @@ module Kramdown
40
40
  if child.children.size > 1
41
41
  warning('images inside content will be moved to the top level and may be rendered differently')
42
42
  end
43
- elsif element.type == :ul
43
+ elsif [:ul, :ol].include?(element.type)
44
44
  warning('nested list moved to the top level')
45
45
  elements << element
46
46
  extract_non_nestable_elements(element, elements)
47
+ elsif element.type == :header
48
+ warning('header moved to the top level')
49
+ elements << element
50
+ extract_non_nestable_elements(element, elements)
47
51
  else
48
52
  memo << element
49
53
  extract_non_nestable_elements(element, elements)
@@ -278,8 +282,12 @@ module Kramdown
278
282
  memo[:text] += element.value
279
283
  end
280
284
 
281
- def extract_span_html_element(_element, _memo)
282
- warning('translating html elements is not supported')
285
+ def extract_span_html_element(element, memo)
286
+ if respond_to?("extract_span_#{element.value}", true)
287
+ send("extract_span_#{element.value}", element, memo)
288
+ else
289
+ warning("translating html element '#{element.value}' is not supported")
290
+ end
283
291
  end
284
292
 
285
293
  def extract_span_footnote(_element, _memo)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KramdownPrismic
4
- VERSION = '0.3.5'
4
+ VERSION = '0.3.8'
5
5
  end
@@ -269,6 +269,29 @@ class KramdownPrismicConverterTest < Minitest::Test
269
269
  assert_equal 1, doc.warnings.size
270
270
  end
271
271
 
272
+ def test_convert_nested_ol
273
+ expected = [
274
+ {
275
+ type: 'list-item',
276
+ content: {
277
+ text: "item1\n",
278
+ spans: []
279
+ }
280
+ },
281
+ {
282
+ type: 'o-list-item',
283
+ content: {
284
+ text: 'item2',
285
+ spans: []
286
+ }
287
+ }
288
+ ]
289
+ markdown = "- item1\n 1. item2"
290
+ doc = Kramdown::Document.new(markdown, input: :markdown)
291
+ assert_equal expected, doc.to_prismic
292
+ assert_equal 1, doc.warnings.size
293
+ end
294
+
272
295
  def test_convert_nested_nested_ul
273
296
  expected = [
274
297
  {
@@ -299,6 +322,29 @@ class KramdownPrismicConverterTest < Minitest::Test
299
322
  assert_equal 2, doc.warnings.size
300
323
  end
301
324
 
325
+ def test_convert_heading_in_list
326
+ expected = [
327
+ {
328
+ type: 'list-item',
329
+ content: {
330
+ text: "",
331
+ spans: []
332
+ }
333
+ },
334
+ {
335
+ type: 'heading4',
336
+ content: {
337
+ text: 'Title',
338
+ spans: []
339
+ }
340
+ }
341
+ ]
342
+ html = "<ul><li><h4>Title</h4></li></ul>"
343
+ doc = Kramdown::Document.new(html, input: :html)
344
+ assert_equal expected, doc.to_prismic
345
+ assert_equal 1, doc.warnings.size
346
+ end
347
+
302
348
  def test_convert_preformatted
303
349
  expected = [
304
350
  {
@@ -530,11 +576,16 @@ class KramdownPrismicConverterTest < Minitest::Test
530
576
  end
531
577
 
532
578
  def test_convert_html_with_no_tags
579
+ expected_text = if Gem::Version.new(Kramdown::VERSION) >= Gem::Version.new("2.3.2")
580
+ "Test "
581
+ else
582
+ "Test\n"
583
+ end
533
584
  expected = [
534
585
  {
535
586
  type: 'paragraph',
536
587
  content: {
537
- text: "Test\n",
588
+ text: expected_text,
538
589
  spans: []
539
590
  }
540
591
  }
@@ -570,12 +621,34 @@ class KramdownPrismicConverterTest < Minitest::Test
570
621
  assert_equal 1, doc.warnings.size
571
622
  end
572
623
 
573
- def test_convert_span_html
624
+ def test_convert_span_html_strong
574
625
  expected = [
575
626
  {
576
627
  type: 'paragraph',
577
628
  content: {
578
- text: '',
629
+ text: 'This is a paragraph',
630
+ spans: [
631
+ {
632
+ type: 'strong',
633
+ start: 10,
634
+ end: 20
635
+ }
636
+ ]
637
+ }
638
+ }
639
+ ]
640
+ html = '<p>This is a <strong> paragraph</strong></p>'
641
+ doc = Kramdown::Document.new(html, input: :html)
642
+ assert_equal expected, doc.to_prismic
643
+ assert_equal 0, doc.warnings.size
644
+ end
645
+
646
+ def test_convert_span_html_br
647
+ expected = [
648
+ {
649
+ type: 'paragraph',
650
+ content: {
651
+ text: "\n",
579
652
  spans: []
580
653
  }
581
654
  }
@@ -583,7 +656,24 @@ class KramdownPrismicConverterTest < Minitest::Test
583
656
  html = '<br>'
584
657
  doc = Kramdown::Document.new(html, input: :markdown)
585
658
  assert_equal expected, doc.to_prismic
659
+ assert_equal 0, doc.warnings.size
660
+ end
661
+
662
+ def test_convert_span_html_unknown
663
+ expected = [
664
+ {
665
+ type: 'paragraph',
666
+ content: {
667
+ text: 'This is a ',
668
+ spans: []
669
+ }
670
+ }
671
+ ]
672
+ html = '<p>This is a <details>detail</details></p>'
673
+ doc = Kramdown::Document.new(html, input: :html)
674
+ assert_equal expected, doc.to_prismic
586
675
  assert_equal 1, doc.warnings.size
676
+ assert_equal "translating html element 'details' is not supported", doc.warnings.first
587
677
  end
588
678
 
589
679
  def test_convert_table
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.5
4
+ version: 0.3.8
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-10-04 00:00:00.000000000 Z
11
+ date: 2022-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubygems_version: 3.1.4
110
+ rubygems_version: 3.0.3
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: A Kramdown converter to convert documents into prismic rich text format and