kramdown-prismic 0.3.2 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/kramdown/converter/prismic.rb +28 -1
- data/lib/kramdown-prismic/version.rb +1 -1
- data/test/converter_test.rb +102 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f68acd9978784949a29e81dc9109f155a5aaa3fbe278142a48b5ea0d667f327b
|
4
|
+
data.tar.gz: eabfc7d18d6ad918f14645d8988d818f27dee74d885ac2e5d22241f633fbc43b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f98e7ec71902a5b7314a978ccae442d2eda5922e69a8217cc6fefcb78c33c19db41244901e50c8fa31517ee468ca62625ffaff987ef683e81532d9cdd2cafe1d
|
7
|
+
data.tar.gz: 7246ec24dd0a0d96b0f736c9f08e0d4c7a8477af0d920091091c8cfee817fb350aeace1175bc33dc7776770c3737fe96054baed3299733c9be4d75af1a3dbf13
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Version 0.3.6
|
4
|
+
|
5
|
+
- Fix converting nested numbered list.
|
6
|
+
|
7
|
+
## Version 0.3.5
|
8
|
+
|
9
|
+
- Convert `br` element when converting HTML documents.
|
10
|
+
|
11
|
+
## Version 0.3.4
|
12
|
+
|
13
|
+
- Convert `strong` and `em` elements when converting HTML documents.
|
14
|
+
|
15
|
+
## Version 0.3.3
|
16
|
+
|
17
|
+
- Renable converting xml comments
|
18
|
+
|
3
19
|
## Version 0.3.2
|
4
20
|
|
5
21
|
- Parse ordered and unordered lists
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Kramdown Prismic
|
1
|
+
# Kramdown Prismic ![build](https://img.shields.io/github/workflow/status/stormz/kramdown-prismic/CI) [![gem](https://img.shields.io/gem/v/kramdown-prismic)](https://rubygems.org/gems/kramdown-prismic)
|
2
2
|
|
3
3
|
A [Kramdown][] parser and converter to convert documents into [prismic][] rich text format and the other way around.
|
4
4
|
|
@@ -40,7 +40,7 @@ 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
|
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)
|
@@ -110,6 +110,7 @@ module Kramdown
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def convert_hr(element); end
|
113
|
+
def convert_br(element); end
|
113
114
|
|
114
115
|
def convert_img(element)
|
115
116
|
{
|
@@ -148,6 +149,23 @@ module Kramdown
|
|
148
149
|
}
|
149
150
|
end
|
150
151
|
|
152
|
+
def convert_strong(element)
|
153
|
+
convert_sub_html_element(element, 'strong')
|
154
|
+
end
|
155
|
+
|
156
|
+
def convert_em(element)
|
157
|
+
convert_sub_html_element(element, 'em')
|
158
|
+
end
|
159
|
+
|
160
|
+
def convert_sub_html_element(element, type)
|
161
|
+
content = extract_content(element)
|
162
|
+
content[:spans].push({ type: type, start: 0, end: content[:text].size })
|
163
|
+
{
|
164
|
+
type: 'paragraph',
|
165
|
+
content: content
|
166
|
+
}
|
167
|
+
end
|
168
|
+
|
151
169
|
def convert_html_element(element)
|
152
170
|
if element.value == 'iframe'
|
153
171
|
{
|
@@ -187,6 +205,11 @@ module Kramdown
|
|
187
205
|
nil
|
188
206
|
end
|
189
207
|
|
208
|
+
def convert_xml_comment(_element)
|
209
|
+
warning('translating xml comment is not supported')
|
210
|
+
nil
|
211
|
+
end
|
212
|
+
|
190
213
|
def convert_raw(_element)
|
191
214
|
warning('translating raw is not supported')
|
192
215
|
nil
|
@@ -268,6 +291,10 @@ module Kramdown
|
|
268
291
|
memo[:text] += element.value
|
269
292
|
end
|
270
293
|
|
294
|
+
def extract_span_xml_comment(element, memo)
|
295
|
+
warning('translating xml comment is not supported')
|
296
|
+
end
|
297
|
+
|
271
298
|
TYPOGRAPHIC_SYMS = {
|
272
299
|
mdash: [Utils::Entities.entity('mdash')],
|
273
300
|
ndash: [Utils::Entities.entity('ndash')],
|
data/test/converter_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'minitest/autorun'
|
@@ -131,6 +132,26 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
131
132
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
132
133
|
end
|
133
134
|
|
135
|
+
def test_convert_html_strong
|
136
|
+
expected = [
|
137
|
+
{
|
138
|
+
type: 'paragraph',
|
139
|
+
content: {
|
140
|
+
text: 'This is a paragraph',
|
141
|
+
spans: [
|
142
|
+
{
|
143
|
+
type: 'strong',
|
144
|
+
start: 0,
|
145
|
+
end: 19
|
146
|
+
}
|
147
|
+
]
|
148
|
+
}
|
149
|
+
}
|
150
|
+
]
|
151
|
+
markdown = '<strong>This is a paragraph</strong>'
|
152
|
+
assert_equal expected, Kramdown::Document.new(markdown, input: :html).to_prismic
|
153
|
+
end
|
154
|
+
|
134
155
|
def test_convert_paragraph_with_em
|
135
156
|
expected = [
|
136
157
|
{
|
@@ -151,6 +172,26 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
151
172
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
152
173
|
end
|
153
174
|
|
175
|
+
def test_convert_html_em
|
176
|
+
expected = [
|
177
|
+
{
|
178
|
+
type: 'paragraph',
|
179
|
+
content: {
|
180
|
+
text: 'This',
|
181
|
+
spans: [
|
182
|
+
{
|
183
|
+
type: 'em',
|
184
|
+
start: 0,
|
185
|
+
end: 4
|
186
|
+
}
|
187
|
+
]
|
188
|
+
}
|
189
|
+
}
|
190
|
+
]
|
191
|
+
markdown = '<em>This</em>'
|
192
|
+
assert_equal expected, Kramdown::Document.new(markdown, input: :html).to_prismic
|
193
|
+
end
|
194
|
+
|
154
195
|
def test_convert_list_o
|
155
196
|
expected = [
|
156
197
|
{
|
@@ -228,6 +269,29 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
228
269
|
assert_equal 1, doc.warnings.size
|
229
270
|
end
|
230
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
|
+
|
231
295
|
def test_convert_nested_nested_ul
|
232
296
|
expected = [
|
233
297
|
{
|
@@ -474,6 +538,20 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
474
538
|
assert_equal expected, Kramdown::Document.new(html, input: :html).to_prismic
|
475
539
|
end
|
476
540
|
|
541
|
+
def test_convert_br_in_root_element
|
542
|
+
expected = [
|
543
|
+
{
|
544
|
+
type: 'paragraph',
|
545
|
+
content: {
|
546
|
+
text: "Test\n",
|
547
|
+
spans: []
|
548
|
+
}
|
549
|
+
}
|
550
|
+
]
|
551
|
+
html = '<br><p>Test<br></p>'
|
552
|
+
assert_equal expected, Kramdown::Document.new(html, input: :html).to_prismic
|
553
|
+
end
|
554
|
+
|
477
555
|
def test_convert_html_with_no_tags
|
478
556
|
expected = [
|
479
557
|
{
|
@@ -587,6 +665,30 @@ class KramdownPrismicConverterTest < Minitest::Test
|
|
587
665
|
assert_equal 1, doc.warnings.size
|
588
666
|
end
|
589
667
|
|
668
|
+
def test_convert_xml_comment
|
669
|
+
expected = []
|
670
|
+
markdown = "<!-- Main -->"
|
671
|
+
doc = Kramdown::Document.new(markdown, input: :kramdown)
|
672
|
+
assert_equal expected, doc.to_prismic
|
673
|
+
assert_equal 1, doc.warnings.size
|
674
|
+
end
|
675
|
+
|
676
|
+
def test_convert_span_xml_comment
|
677
|
+
expected = [
|
678
|
+
{
|
679
|
+
type: 'paragraph',
|
680
|
+
content: {
|
681
|
+
text: 'test test',
|
682
|
+
spans: []
|
683
|
+
}
|
684
|
+
}
|
685
|
+
]
|
686
|
+
markdown = "test <!-- Main --> test"
|
687
|
+
doc = Kramdown::Document.new(markdown, input: :kramdown)
|
688
|
+
assert_equal expected, doc.to_prismic
|
689
|
+
assert_equal 1, doc.warnings.size
|
690
|
+
end
|
691
|
+
|
590
692
|
def test_convert_comment
|
591
693
|
expected = []
|
592
694
|
markdown = "{::comment}\nComment\n{:/comment}"
|
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.6
|
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-
|
11
|
+
date: 2021-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|