kramdown-prismic 0.3.3 → 0.3.7

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: ba6d3ad52704c02e2ec102cc69ca216f02c464ba6cde85c2f28024c66448a985
4
- data.tar.gz: 64fdd7184a0184c10b72acb00d2109f1b3512fc53392327a5f537d091d5796ce
3
+ metadata.gz: c409891cb5fb66652154697c053d2f4898c2bdbdb40f90a42df53eb2c41994f2
4
+ data.tar.gz: aa59f8c4ea6b262abbadea2a810e91901a3bb719bf28dd94206b17d2f46a5204
5
5
  SHA512:
6
- metadata.gz: ea6f89410664900030c17478ed4cce6fb6a499974ef775f421fd1b720e7f28e123526eb1893889f42d8964928a1c2139387f2dae408a3ea19dffc50805430918
7
- data.tar.gz: 95c6df198bfdacb61f24606575d4fd5d517b1285750a4dd463f15cc0416513759aec67183eb3820c64c221d5154acbb826e0a74b7e9f797ddfff7cbb2bbae165
6
+ metadata.gz: 7da022135525388a0fb64b091804e65cef0e1307e7ff2cfb0203f3c007fc736393d600dd3119441073fcb73fed956ad45b015d90d4b720ecfacc8851d7132a4e
7
+ data.tar.gz: 7fbf4b233127d8bba128bcad4624ca13008f1a0dbc6e8c8a7121ac87c8fd72e11f90b046a738cb516965da42ef9c228fcab13fee2bbbc931e98ebbc5a3871701
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 0.3.7
4
+
5
+ - Fix converting nested headers
6
+
7
+ ## Version 0.3.6
8
+
9
+ - Fix converting nested numbered list.
10
+
11
+ ## Version 0.3.5
12
+
13
+ - Convert `br` element when converting HTML documents.
14
+
15
+ ## Version 0.3.4
16
+
17
+ - Convert `strong` and `em` elements when converting HTML documents.
18
+
3
19
  ## Version 0.3.3
4
20
 
5
21
  - Renable converting xml comments
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kramdown-prismic (0.3.3)
4
+ kramdown-prismic (0.3.7)
5
5
  kramdown (>= 1, < 3)
6
6
 
7
7
  GEM
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,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)
@@ -110,6 +114,7 @@ module Kramdown
110
114
  end
111
115
 
112
116
  def convert_hr(element); end
117
+ def convert_br(element); end
113
118
 
114
119
  def convert_img(element)
115
120
  {
@@ -148,6 +153,23 @@ module Kramdown
148
153
  }
149
154
  end
150
155
 
156
+ def convert_strong(element)
157
+ convert_sub_html_element(element, 'strong')
158
+ end
159
+
160
+ def convert_em(element)
161
+ convert_sub_html_element(element, 'em')
162
+ end
163
+
164
+ def convert_sub_html_element(element, type)
165
+ content = extract_content(element)
166
+ content[:spans].push({ type: type, start: 0, end: content[:text].size })
167
+ {
168
+ type: 'paragraph',
169
+ content: content
170
+ }
171
+ end
172
+
151
173
  def convert_html_element(element)
152
174
  if element.value == 'iframe'
153
175
  {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KramdownPrismic
4
- VERSION = '0.3.3'
4
+ VERSION = '0.3.7'
5
5
  end
@@ -132,6 +132,26 @@ class KramdownPrismicConverterTest < Minitest::Test
132
132
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
133
133
  end
134
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
+
135
155
  def test_convert_paragraph_with_em
136
156
  expected = [
137
157
  {
@@ -152,6 +172,26 @@ class KramdownPrismicConverterTest < Minitest::Test
152
172
  assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
153
173
  end
154
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
+
155
195
  def test_convert_list_o
156
196
  expected = [
157
197
  {
@@ -229,6 +269,29 @@ class KramdownPrismicConverterTest < Minitest::Test
229
269
  assert_equal 1, doc.warnings.size
230
270
  end
231
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
+
232
295
  def test_convert_nested_nested_ul
233
296
  expected = [
234
297
  {
@@ -259,6 +322,29 @@ class KramdownPrismicConverterTest < Minitest::Test
259
322
  assert_equal 2, doc.warnings.size
260
323
  end
261
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
+
262
348
  def test_convert_preformatted
263
349
  expected = [
264
350
  {
@@ -475,6 +561,20 @@ class KramdownPrismicConverterTest < Minitest::Test
475
561
  assert_equal expected, Kramdown::Document.new(html, input: :html).to_prismic
476
562
  end
477
563
 
564
+ def test_convert_br_in_root_element
565
+ expected = [
566
+ {
567
+ type: 'paragraph',
568
+ content: {
569
+ text: "Test\n",
570
+ spans: []
571
+ }
572
+ }
573
+ ]
574
+ html = '<br><p>Test<br></p>'
575
+ assert_equal expected, Kramdown::Document.new(html, input: :html).to_prismic
576
+ end
577
+
478
578
  def test_convert_html_with_no_tags
479
579
  expected = [
480
580
  {
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.3
4
+ version: 0.3.7
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-08-20 00:00:00.000000000 Z
11
+ date: 2021-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown