kramdown-prismic 0.3.6 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +2 -2
- data/lib/kramdown/converter/prismic.rb +13 -3
- data/lib/kramdown-prismic/version.rb +1 -1
- data/test/converter_test.rb +85 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76a75c9530dc6b9336112a445b9fc4cd811e17059e4677c2094c1b22b585fa06
|
4
|
+
data.tar.gz: 77315988401b9fc306026b3d6a1b9d184b2a92a579fddd2871ba27dbc4000292
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 576fc16369c963b6a1215e834dd72e88231177773cd2e62cfba973f4ae59288a508965db55759b214aebab1a0239c0b8d067b9e4a95a861ef7be6c002b3434d3
|
7
|
+
data.tar.gz: c6cd045fa16db194a3f6e3e78fc8cf2c86029e68e8a3b6194140c4f9c08f9db12f92ce0c1abd9b4ef391fc57112a34daac0166b6f5e14378178f7ab852466431
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Version 0.3.9
|
4
|
+
|
5
|
+
- Convert the target attribute on links
|
6
|
+
|
7
|
+
## Version 0.3.8
|
8
|
+
|
9
|
+
- Convert nested html_elements when converting from HTML.
|
10
|
+
|
11
|
+
## Version 0.3.7
|
12
|
+
|
13
|
+
- Fix converting nested headers
|
14
|
+
|
3
15
|
## Version 0.3.6
|
4
16
|
|
5
17
|
- Fix converting nested numbered list.
|
data/Gemfile.lock
CHANGED
@@ -44,6 +44,10 @@ module Kramdown
|
|
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)
|
@@ -245,10 +249,12 @@ module Kramdown
|
|
245
249
|
end
|
246
250
|
|
247
251
|
def extract_span_a(element, memo)
|
252
|
+
target = element.attr['target']
|
248
253
|
insert_span(element, memo, {
|
249
254
|
type: 'hyperlink',
|
250
255
|
data: {
|
251
|
-
url: element.attr['href']
|
256
|
+
url: element.attr['href'],
|
257
|
+
**(target ? { target: target } : {}),
|
252
258
|
}
|
253
259
|
})
|
254
260
|
end
|
@@ -278,8 +284,12 @@ module Kramdown
|
|
278
284
|
memo[:text] += element.value
|
279
285
|
end
|
280
286
|
|
281
|
-
def extract_span_html_element(
|
282
|
-
|
287
|
+
def extract_span_html_element(element, memo)
|
288
|
+
if respond_to?("extract_span_#{element.value}", true)
|
289
|
+
send("extract_span_#{element.value}", element, memo)
|
290
|
+
else
|
291
|
+
warning("translating html element '#{element.value}' is not supported")
|
292
|
+
end
|
283
293
|
end
|
284
294
|
|
285
295
|
def extract_span_footnote(_element, _memo)
|
data/test/converter_test.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require 'minitest/autorun'
|
@@ -322,6 +321,29 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
322
321
|
assert_equal 2, doc.warnings.size
|
323
322
|
end
|
324
323
|
|
324
|
+
def test_convert_heading_in_list
|
325
|
+
expected = [
|
326
|
+
{
|
327
|
+
type: 'list-item',
|
328
|
+
content: {
|
329
|
+
text: "",
|
330
|
+
spans: []
|
331
|
+
}
|
332
|
+
},
|
333
|
+
{
|
334
|
+
type: 'heading4',
|
335
|
+
content: {
|
336
|
+
text: 'Title',
|
337
|
+
spans: []
|
338
|
+
}
|
339
|
+
}
|
340
|
+
]
|
341
|
+
html = "<ul><li><h4>Title</h4></li></ul>"
|
342
|
+
doc = Kramdown::Document.new(html, input: :html)
|
343
|
+
assert_equal expected, doc.to_prismic
|
344
|
+
assert_equal 1, doc.warnings.size
|
345
|
+
end
|
346
|
+
|
325
347
|
def test_convert_preformatted
|
326
348
|
expected = [
|
327
349
|
{
|
@@ -553,11 +575,16 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
553
575
|
end
|
554
576
|
|
555
577
|
def test_convert_html_with_no_tags
|
578
|
+
expected_text = if Gem::Version.new(Kramdown::VERSION) >= Gem::Version.new("2.3.2")
|
579
|
+
"Test "
|
580
|
+
else
|
581
|
+
"Test\n"
|
582
|
+
end
|
556
583
|
expected = [
|
557
584
|
{
|
558
585
|
type: 'paragraph',
|
559
586
|
content: {
|
560
|
-
text:
|
587
|
+
text: expected_text,
|
561
588
|
spans: []
|
562
589
|
}
|
563
590
|
}
|
@@ -585,6 +612,21 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
585
612
|
assert_equal expected, doc.to_prismic
|
586
613
|
end
|
587
614
|
|
615
|
+
def test_convert_link
|
616
|
+
expected = [
|
617
|
+
{
|
618
|
+
type: 'paragraph',
|
619
|
+
content: {
|
620
|
+
text: 'Test',
|
621
|
+
spans: [{type: 'hyperlink', data: {url: 'http://example.net', target: '_blank'}, start: 0, end: 4}]
|
622
|
+
}
|
623
|
+
}
|
624
|
+
]
|
625
|
+
html = '<a href="http://example.net" target="_blank">Test</a>'
|
626
|
+
doc = Kramdown::Document.new(html, input: :markdown)
|
627
|
+
assert_equal expected, doc.to_prismic
|
628
|
+
end
|
629
|
+
|
588
630
|
def test_convert_html
|
589
631
|
expected = []
|
590
632
|
html = '<div></div>'
|
@@ -593,12 +635,34 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
593
635
|
assert_equal 1, doc.warnings.size
|
594
636
|
end
|
595
637
|
|
596
|
-
def
|
638
|
+
def test_convert_span_html_strong
|
597
639
|
expected = [
|
598
640
|
{
|
599
641
|
type: 'paragraph',
|
600
642
|
content: {
|
601
|
-
text: '',
|
643
|
+
text: 'This is a paragraph',
|
644
|
+
spans: [
|
645
|
+
{
|
646
|
+
type: 'strong',
|
647
|
+
start: 10,
|
648
|
+
end: 20
|
649
|
+
}
|
650
|
+
]
|
651
|
+
}
|
652
|
+
}
|
653
|
+
]
|
654
|
+
html = '<p>This is a <strong> paragraph</strong></p>'
|
655
|
+
doc = Kramdown::Document.new(html, input: :html)
|
656
|
+
assert_equal expected, doc.to_prismic
|
657
|
+
assert_equal 0, doc.warnings.size
|
658
|
+
end
|
659
|
+
|
660
|
+
def test_convert_span_html_br
|
661
|
+
expected = [
|
662
|
+
{
|
663
|
+
type: 'paragraph',
|
664
|
+
content: {
|
665
|
+
text: "\n",
|
602
666
|
spans: []
|
603
667
|
}
|
604
668
|
}
|
@@ -606,7 +670,24 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
606
670
|
html = '<br>'
|
607
671
|
doc = Kramdown::Document.new(html, input: :markdown)
|
608
672
|
assert_equal expected, doc.to_prismic
|
673
|
+
assert_equal 0, doc.warnings.size
|
674
|
+
end
|
675
|
+
|
676
|
+
def test_convert_span_html_unknown
|
677
|
+
expected = [
|
678
|
+
{
|
679
|
+
type: 'paragraph',
|
680
|
+
content: {
|
681
|
+
text: 'This is a ',
|
682
|
+
spans: []
|
683
|
+
}
|
684
|
+
}
|
685
|
+
]
|
686
|
+
html = '<p>This is a <details>detail</details></p>'
|
687
|
+
doc = Kramdown::Document.new(html, input: :html)
|
688
|
+
assert_equal expected, doc.to_prismic
|
609
689
|
assert_equal 1, doc.warnings.size
|
690
|
+
assert_equal "translating html element 'details' is not supported", doc.warnings.first
|
610
691
|
end
|
611
692
|
|
612
693
|
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.
|
4
|
+
version: 0.3.9
|
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:
|
11
|
+
date: 2022-05-08 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.
|
110
|
+
rubygems_version: 3.1.4
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: A Kramdown converter to convert documents into prismic rich text format and
|