kramdown-prismic 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +18 -0
- data/Changelog.md +26 -0
- data/Gemfile.lock +5 -5
- data/LICENSE +1 -0
- data/README.md +86 -15
- data/kramdown-prismic.gemspec +1 -1
- data/lib/kramdown-prismic.rb +1 -0
- data/lib/kramdown-prismic/version.rb +1 -1
- data/lib/kramdown/converter/prismic.rb +30 -1
- data/lib/kramdown/parser/prismic.rb +101 -0
- data/test/{kramdown-prismic_test.rb → converter_test.rb} +60 -30
- data/test/parser_test.rb +204 -0
- metadata +12 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3229f319815e16e39608a957bb9f596e623a6ef605be3955c46723de2aedbb98
|
4
|
+
data.tar.gz: '08f9b62d41e583e99d51373ddb875352abec6226f2a584c6f9d21b61c15ed26f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c3bf867920d85af049006027d70f156cca4c0863cd8c40784eb473121153652acc368906e1100fabdb90d36a04f73c9a966090c8a68e7d55fc8c55f0e3610e7
|
7
|
+
data.tar.gz: e4daf1cfe1886f809f0234d7a181b22e677be78401f06c4f4657d89a519e61b13d56ce1dcabcad11ed13bbe782f359c3214c5650da098b8b72c65fccdeb230b4
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
jobs:
|
5
|
+
test:
|
6
|
+
strategy:
|
7
|
+
fail-fast: false
|
8
|
+
matrix:
|
9
|
+
os: [ubuntu-latest]
|
10
|
+
ruby: [2.5, 2.6, 2.7]
|
11
|
+
runs-on: ${{ matrix.os }}
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: ${{ matrix.ruby }}
|
17
|
+
bundler-cache: true
|
18
|
+
- run: bundle exec rake test
|
data/Changelog.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## Version 0.2.2
|
4
|
+
|
5
|
+
- Convert links with only an image inside. See #1.
|
6
|
+
|
7
|
+
## Version 0.2.1
|
8
|
+
|
9
|
+
- Parse embed elements
|
10
|
+
- Convert inline code
|
11
|
+
|
12
|
+
## Version 0.2.0
|
13
|
+
|
14
|
+
- Add parser to convert prismic to markdown
|
15
|
+
|
16
|
+
## Version 0.1.2
|
17
|
+
|
18
|
+
- fix output with empty paragraph
|
19
|
+
|
20
|
+
## Version 0.1.1
|
21
|
+
|
22
|
+
- Fix json of the image
|
23
|
+
|
24
|
+
## Version 0.1.0
|
25
|
+
|
26
|
+
- Initial version
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kramdown-prismic (0.
|
4
|
+
kramdown-prismic (0.2.2)
|
5
5
|
kramdown (~> 1.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
kramdown (1.
|
10
|
+
kramdown (1.17.0)
|
11
11
|
minitest (5.10.3)
|
12
|
-
rake (
|
12
|
+
rake (13.0.6)
|
13
13
|
|
14
14
|
PLATFORMS
|
15
15
|
ruby
|
@@ -17,7 +17,7 @@ PLATFORMS
|
|
17
17
|
DEPENDENCIES
|
18
18
|
kramdown-prismic!
|
19
19
|
minitest (~> 5.0)
|
20
|
-
rake (~>
|
20
|
+
rake (~> 13.0)
|
21
21
|
|
22
22
|
BUNDLED WITH
|
23
|
-
1.
|
23
|
+
1.17.2
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,19 +1,94 @@
|
|
1
1
|
# Kramdown Prismic
|
2
2
|
|
3
|
-
A Kramdown converter to convert documents into prismic rich text format.
|
3
|
+
A [Kramdown][] parser and converter to convert documents into [prismic][] rich text format and back.
|
4
|
+
|
5
|
+
A useful usage is to convert markdown documents to prismic for import purpose. Then you can even convert prismic format back to markdown.
|
4
6
|
|
5
7
|
## Status
|
6
8
|
|
7
|
-
|
9
|
+
The converter part (kramdown to prismic) is working and fairly complete. See *Difference between markdown and rich text* below to know more about limitations.
|
10
|
+
|
11
|
+
The parser part is quite new and not feature complete (missing list item for instance).
|
12
|
+
|
13
|
+
## Install
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'kramdown-prismic', '~> 0.1'
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
**Convert kramdown documents to Prismic**
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'kramdown-prismic'
|
25
|
+
|
26
|
+
kramdown = '# Hello world'
|
27
|
+
Kramdown::Document.new(kramdown).to_prismic
|
28
|
+
```
|
29
|
+
|
30
|
+
**Convert markdown documents to Prismic**
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'kramdown-prismic'
|
34
|
+
|
35
|
+
markdown = '# Hello world'
|
36
|
+
Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
37
|
+
```
|
38
|
+
|
39
|
+
**Convert HTML documents to Prismic**
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'kramdown-prismic'
|
43
|
+
|
44
|
+
html = '<h1>Hello world</h1>'
|
45
|
+
Kramdown::Document.new(html, input: :html).to_prismic
|
46
|
+
```
|
47
|
+
|
48
|
+
**Convert Prismic to markdown**
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require 'kramdown-prismic'
|
52
|
+
prismic = [
|
53
|
+
{
|
54
|
+
type: "heading1",
|
55
|
+
content: {
|
56
|
+
text: "This is the document title",
|
57
|
+
spans: []
|
58
|
+
}
|
59
|
+
}
|
60
|
+
]
|
61
|
+
Kramdown::Document.new(prismic, input: :prismic).to_kramdown
|
62
|
+
```
|
63
|
+
|
64
|
+
### Lookup for warnings
|
65
|
+
|
66
|
+
If there is some elements that cannot be converted (see the status table), a warning will be emitted.
|
67
|
+
|
68
|
+
For instance, html elements in the markdown is not supported:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
require 'kramdown-prismic'
|
72
|
+
|
73
|
+
markdown = '<h1>Hello world</h1>'
|
74
|
+
result = Kramdown::Document.new(markdown, input: :markdown)
|
75
|
+
result.to_prismic
|
76
|
+
p result.warnings
|
77
|
+
```
|
8
78
|
|
9
79
|
### Difference between markdown and rich text
|
10
80
|
|
81
|
+
Some elements cannot be converted, due to some Prismic limitations. The table below explain the difference and limitations of the current converter:
|
82
|
+
|
11
83
|
| Markdown | Prismic |
|
12
84
|
|------------------|----------------------------|
|
13
|
-
|
|
85
|
+
| blockquote | converted to preformatted |
|
14
86
|
| hr | nothing |
|
15
87
|
| img | moved to the top level |
|
16
88
|
| nested list | moved to the top level |
|
89
|
+
| entity | converted to unicode |
|
90
|
+
| typographic_sym | converted to unicode |
|
91
|
+
| smart_quote | converted to unicode |
|
17
92
|
| dl | not supported |
|
18
93
|
| dt | not supported |
|
19
94
|
| dd | not supported |
|
@@ -25,9 +100,6 @@ Most of the content is translated. See the table below to see the difference:
|
|
25
100
|
| td | not supported |
|
26
101
|
| math | not supported |
|
27
102
|
| footnote | not supported |
|
28
|
-
| entity | Transformed to unicode |
|
29
|
-
| typographic_sym | Transformed to unicode |
|
30
|
-
| smart_quote | Transformed to unicode |
|
31
103
|
| abbreviation | not supported |
|
32
104
|
| html_element | not supported |
|
33
105
|
| xml_comment | not supported |
|
@@ -35,20 +107,19 @@ Most of the content is translated. See the table below to see the difference:
|
|
35
107
|
| comment | not supported |
|
36
108
|
| raw | not supported |
|
37
109
|
|
38
|
-
##
|
110
|
+
## Develop
|
39
111
|
|
40
|
-
|
41
|
-
gem 'kramdown-prismic', '~> 0.1'
|
42
|
-
```
|
112
|
+
Install dependencies:
|
43
113
|
|
44
|
-
|
114
|
+
bundle install
|
45
115
|
|
46
|
-
|
47
|
-
require 'kramdown-prismic'
|
116
|
+
Run tests:
|
48
117
|
|
49
|
-
|
50
|
-
```
|
118
|
+
bundle exec rake test
|
51
119
|
|
52
120
|
## License
|
53
121
|
|
54
122
|
MIT
|
123
|
+
|
124
|
+
[Kramdown]: https://kramdown.gettalong.org/
|
125
|
+
[prismic]: https://prismic.io/
|
data/kramdown-prismic.gemspec
CHANGED
data/lib/kramdown-prismic.rb
CHANGED
@@ -32,7 +32,9 @@ module Kramdown
|
|
32
32
|
|
33
33
|
def extract_non_nestable_elements(child, elements)
|
34
34
|
child.children = child.children.inject([]) do |memo, element|
|
35
|
-
if element.type == :img
|
35
|
+
if element.type == :a && element.children.size === 1 && element.children.first.type == :img
|
36
|
+
elements << element
|
37
|
+
elsif element.type == :img
|
36
38
|
elements << element
|
37
39
|
warning('images inside content will be moved to the top level and may be rendered differently') if child.children.size > 1
|
38
40
|
elsif element.type == :ul
|
@@ -59,6 +61,7 @@ module Kramdown
|
|
59
61
|
end
|
60
62
|
|
61
63
|
def convert_p(element)
|
64
|
+
return nil if element.children.size == 0
|
62
65
|
{
|
63
66
|
type: "paragraph",
|
64
67
|
content: extract_content(element)
|
@@ -122,6 +125,27 @@ module Kramdown
|
|
122
125
|
}
|
123
126
|
end
|
124
127
|
|
128
|
+
# This can only apply when an link with an image inside has been detected
|
129
|
+
def convert_a(element)
|
130
|
+
image = element.children.first
|
131
|
+
{
|
132
|
+
type: 'image',
|
133
|
+
content: {
|
134
|
+
text: '',
|
135
|
+
spans: []
|
136
|
+
},
|
137
|
+
data: {
|
138
|
+
origin: {
|
139
|
+
url: image.attr['src']
|
140
|
+
},
|
141
|
+
alt: image.attr['alt'],
|
142
|
+
linkTo: {
|
143
|
+
url: element.attr['href']
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}
|
147
|
+
end
|
148
|
+
|
125
149
|
def convert_html_element(element)
|
126
150
|
warning('translating html elements is not supported')
|
127
151
|
nil
|
@@ -211,6 +235,11 @@ module Kramdown
|
|
211
235
|
memo[:text] += "\n"
|
212
236
|
end
|
213
237
|
|
238
|
+
def extract_span_codespan(element, memo)
|
239
|
+
warning('translating inline code is not supported')
|
240
|
+
memo[:text] += element.value
|
241
|
+
end
|
242
|
+
|
214
243
|
def extract_span_html_element(element, memo)
|
215
244
|
warning('translating html elements is not supported')
|
216
245
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Kramdown
|
2
|
+
module Parser
|
3
|
+
class Prismic < Base
|
4
|
+
def parse
|
5
|
+
@root.options[:encoding] = 'UTF-8'
|
6
|
+
@root.children = @source.map do |block|
|
7
|
+
type = block[:type]
|
8
|
+
if type.match(/heading/)
|
9
|
+
type = 'heading'
|
10
|
+
end
|
11
|
+
element = send("parse_#{type}", block)
|
12
|
+
parse_spans(element, block)
|
13
|
+
element
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def parse_heading(block)
|
20
|
+
level = block[:type].match(/heading([1-6])/)[1].to_i
|
21
|
+
Kramdown::Element.new(:header, nil, nil, {level: level, raw_text: ''})
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse_paragraph(block)
|
25
|
+
Kramdown::Element.new(:p)
|
26
|
+
end
|
27
|
+
|
28
|
+
def parse_image(block)
|
29
|
+
p = Kramdown::Element.new(:p)
|
30
|
+
img = Kramdown::Element.new(:img, nil, {"src" => block[:data][:origin][:url], "alt" => block[:data][:alt]})
|
31
|
+
p.children << img
|
32
|
+
p
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse_preformatted(block)
|
36
|
+
Kramdown::Element.new(:blockquote)
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_embed(block)
|
40
|
+
Kramdown::Element.new(:html_element, 'iframe', { src: block[:data][:embed_url] })
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse_spans(element, block)
|
44
|
+
stack = []
|
45
|
+
|
46
|
+
(block[:content][:text].size + 1).times do |index|
|
47
|
+
|
48
|
+
starting_spans = find_starting_spans_for(block, index)
|
49
|
+
ending_spans = find_ending_spans_for(block, index)
|
50
|
+
|
51
|
+
ending_spans.each do |ending_span|
|
52
|
+
el = stack.pop
|
53
|
+
if stack.empty?
|
54
|
+
element.children << el
|
55
|
+
else
|
56
|
+
stack[-1].children << el
|
57
|
+
end
|
58
|
+
end
|
59
|
+
starting_spans.each do |starting_span|
|
60
|
+
stack << if starting_span[:type] == "hyperlink"
|
61
|
+
Element.new(:a, nil, {'href' => starting_span[:data][:url]})
|
62
|
+
else
|
63
|
+
Element.new(starting_span[:type].to_sym)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
char = block[:content][:text][index]
|
68
|
+
next if char.nil?
|
69
|
+
current_text = if stack.empty?
|
70
|
+
element.children.last
|
71
|
+
else
|
72
|
+
stack[-1].children.last
|
73
|
+
end
|
74
|
+
if current_text.nil? || current_text.type != :text
|
75
|
+
current_text = Element.new(:text, "")
|
76
|
+
if stack.empty?
|
77
|
+
element.children << current_text
|
78
|
+
else
|
79
|
+
stack[-1].children << current_text
|
80
|
+
end
|
81
|
+
end
|
82
|
+
current_text.value += char
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def find_starting_spans_for(block, index)
|
87
|
+
block[:content][:spans].find_all do |span|
|
88
|
+
span[:start] == index
|
89
|
+
end.sort_by do |span|
|
90
|
+
-span[:end]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def find_ending_spans_for(block, index)
|
95
|
+
block[:content][:spans].find_all do |span|
|
96
|
+
span[:end] == index
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -1,32 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require 'minitest/autorun'
|
2
3
|
require 'kramdown-prismic'
|
3
4
|
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
class KramdownPrismicConverterTest < Minitest::Test
|
6
|
+
6.times do |heading|
|
7
|
+
define_method "test_convert_heading_#{heading}" do
|
8
|
+
expected = [
|
9
|
+
{
|
10
|
+
type: "heading#{heading + 1}",
|
11
|
+
content: {
|
12
|
+
text: "This is the document title",
|
13
|
+
spans: []
|
14
|
+
}
|
12
15
|
}
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
]
|
17
|
+
markdown = "#{"#" * (heading + 1)} This is the document title"
|
18
|
+
assert_equal expected, Kramdown::Document.new(markdown, input: :kramdown).to_prismic
|
19
|
+
end
|
17
20
|
end
|
18
21
|
|
19
|
-
def
|
22
|
+
def test_convert_heading7
|
20
23
|
expected = [
|
21
24
|
{
|
22
|
-
type: "
|
25
|
+
type: "heading6",
|
23
26
|
content: {
|
24
|
-
text: "This is
|
27
|
+
text: "# This is the document title",
|
25
28
|
spans: []
|
26
29
|
}
|
27
30
|
}
|
28
31
|
]
|
29
|
-
markdown = "
|
32
|
+
markdown = "####### This is the document title"
|
30
33
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
31
34
|
end
|
32
35
|
|
@@ -309,13 +312,6 @@ class KramdownPrismicTest < Minitest::Test
|
|
309
312
|
|
310
313
|
def test_convert_img
|
311
314
|
expected = [
|
312
|
-
{
|
313
|
-
type: "paragraph",
|
314
|
-
content: {
|
315
|
-
text: "",
|
316
|
-
spans: []
|
317
|
-
}
|
318
|
-
},
|
319
315
|
{
|
320
316
|
type: "image",
|
321
317
|
content: {
|
@@ -338,13 +334,6 @@ class KramdownPrismicTest < Minitest::Test
|
|
338
334
|
|
339
335
|
def test_convert_double_img
|
340
336
|
expected = [
|
341
|
-
{
|
342
|
-
type: "paragraph",
|
343
|
-
content: {
|
344
|
-
text: "",
|
345
|
-
spans: []
|
346
|
-
}
|
347
|
-
},
|
348
337
|
{
|
349
338
|
type: "image",
|
350
339
|
content: {
|
@@ -378,6 +367,31 @@ class KramdownPrismicTest < Minitest::Test
|
|
378
367
|
assert_equal 2, doc.warnings.size
|
379
368
|
end
|
380
369
|
|
370
|
+
def test_convert_img_with_link
|
371
|
+
expected = [
|
372
|
+
{
|
373
|
+
type: "image",
|
374
|
+
content: {
|
375
|
+
text: "",
|
376
|
+
spans: []
|
377
|
+
},
|
378
|
+
data: {
|
379
|
+
origin: {
|
380
|
+
url: '/img.png'
|
381
|
+
},
|
382
|
+
alt: 'alt text',
|
383
|
+
linkTo: {
|
384
|
+
url: "https://example.net/"
|
385
|
+
}
|
386
|
+
}
|
387
|
+
}
|
388
|
+
]
|
389
|
+
markdown = "[![alt text](/img.png)](https://example.net/)"
|
390
|
+
doc = Kramdown::Document.new(markdown)
|
391
|
+
assert_equal expected, doc.to_prismic
|
392
|
+
assert_equal 0, doc.warnings.size
|
393
|
+
end
|
394
|
+
|
381
395
|
def test_convert_entity
|
382
396
|
expected = [
|
383
397
|
{
|
@@ -428,6 +442,22 @@ class KramdownPrismicTest < Minitest::Test
|
|
428
442
|
assert_equal expected, Kramdown::Document.new(markdown, input: :kramdown).to_prismic
|
429
443
|
end
|
430
444
|
|
445
|
+
def test_convert_inline_code
|
446
|
+
expected = [
|
447
|
+
{
|
448
|
+
type: "paragraph",
|
449
|
+
content: {
|
450
|
+
text: "Hello code",
|
451
|
+
spans: []
|
452
|
+
}
|
453
|
+
}
|
454
|
+
]
|
455
|
+
markdown = "Hello `code`"
|
456
|
+
doc = Kramdown::Document.new(markdown)
|
457
|
+
assert_equal expected, doc.to_prismic
|
458
|
+
assert_equal 1, doc.warnings.size
|
459
|
+
end
|
460
|
+
|
431
461
|
def test_convert_br
|
432
462
|
expected = [
|
433
463
|
{type: "paragraph",
|
data/test/parser_test.rb
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'kramdown-prismic'
|
3
|
+
|
4
|
+
class KramdownPrismicParserTest < Minitest::Test
|
5
|
+
def test_parse_heading
|
6
|
+
prismic = [
|
7
|
+
{
|
8
|
+
type: "heading1",
|
9
|
+
content: {
|
10
|
+
text: "This is the document title",
|
11
|
+
spans: []
|
12
|
+
}
|
13
|
+
}
|
14
|
+
]
|
15
|
+
expected = "# This is the document title\n\n"
|
16
|
+
doc = Kramdown::Document.new(prismic, input: :prismic)
|
17
|
+
assert_equal expected, doc.to_kramdown
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_parse_heading2
|
21
|
+
prismic = [
|
22
|
+
{
|
23
|
+
type: "heading2",
|
24
|
+
content: {
|
25
|
+
text: "This is an h2 title",
|
26
|
+
spans: []
|
27
|
+
}
|
28
|
+
}
|
29
|
+
]
|
30
|
+
expected = "## This is an h2 title\n\n"
|
31
|
+
doc = Kramdown::Document.new(prismic, input: :prismic)
|
32
|
+
assert_equal expected, doc.to_kramdown
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_parse_paragraph
|
36
|
+
prismic = [
|
37
|
+
{
|
38
|
+
type: "paragraph",
|
39
|
+
content: {
|
40
|
+
text: "This is a paragraph",
|
41
|
+
spans: []
|
42
|
+
}
|
43
|
+
}
|
44
|
+
]
|
45
|
+
expected = "This is a paragraph\n\n"
|
46
|
+
doc = Kramdown::Document.new(prismic, input: :prismic)
|
47
|
+
assert_equal expected, doc.to_kramdown
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_parse_paragraph_with_spans
|
51
|
+
prismic = [
|
52
|
+
{
|
53
|
+
type: "paragraph",
|
54
|
+
content: {
|
55
|
+
text: "This is a paragraph",
|
56
|
+
spans: [
|
57
|
+
{
|
58
|
+
type: "em",
|
59
|
+
start: 0,
|
60
|
+
end: 4
|
61
|
+
}
|
62
|
+
]
|
63
|
+
}
|
64
|
+
}
|
65
|
+
]
|
66
|
+
expected = "*This* is a paragraph\n\n"
|
67
|
+
doc = Kramdown::Document.new(prismic, input: :prismic)
|
68
|
+
assert_equal expected, doc.to_kramdown
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_parse_paragraph_with_multiple_spans
|
72
|
+
prismic = [
|
73
|
+
{
|
74
|
+
type: "paragraph",
|
75
|
+
content: {
|
76
|
+
text: "This is a paragraph",
|
77
|
+
spans: [
|
78
|
+
{
|
79
|
+
type: "em",
|
80
|
+
start: 0,
|
81
|
+
end: 4
|
82
|
+
},
|
83
|
+
{
|
84
|
+
type: "strong",
|
85
|
+
start: 5,
|
86
|
+
end: 7
|
87
|
+
}
|
88
|
+
]
|
89
|
+
}
|
90
|
+
}
|
91
|
+
]
|
92
|
+
expected = "*This* **is** a paragraph\n\n"
|
93
|
+
doc = Kramdown::Document.new(prismic, input: :prismic)
|
94
|
+
assert_equal expected, doc.to_kramdown
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_parse_paragraph_with_link
|
98
|
+
prismic = [
|
99
|
+
{
|
100
|
+
type: "paragraph",
|
101
|
+
content: {
|
102
|
+
text: "This is a paragraph",
|
103
|
+
spans: [
|
104
|
+
{
|
105
|
+
type: "hyperlink",
|
106
|
+
start: 0,
|
107
|
+
end: 19,
|
108
|
+
data: {
|
109
|
+
url: "https://prismic.io"
|
110
|
+
}
|
111
|
+
}
|
112
|
+
]
|
113
|
+
}
|
114
|
+
}
|
115
|
+
]
|
116
|
+
expected = "[This is a paragraph][1]\n\n\n\n[1]: https://prismic.io\n"
|
117
|
+
doc = Kramdown::Document.new(prismic, input: :prismic)
|
118
|
+
assert_equal expected, doc.to_kramdown
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_parse_paragraph_with_nested_spans
|
122
|
+
prismic = [
|
123
|
+
{
|
124
|
+
type: "paragraph",
|
125
|
+
content: {
|
126
|
+
text: "This is a paragraph",
|
127
|
+
spans: [
|
128
|
+
{
|
129
|
+
type: "em",
|
130
|
+
start: 0,
|
131
|
+
end: 4
|
132
|
+
},
|
133
|
+
{
|
134
|
+
type: "hyperlink",
|
135
|
+
start: 0,
|
136
|
+
end: 19,
|
137
|
+
data: {
|
138
|
+
url: "https://prismic.io"
|
139
|
+
}
|
140
|
+
}
|
141
|
+
]
|
142
|
+
}
|
143
|
+
}
|
144
|
+
]
|
145
|
+
expected = "[*This* is a paragraph][1]\n\n\n\n[1]: https://prismic.io\n"
|
146
|
+
doc = Kramdown::Document.new(prismic, input: :prismic)
|
147
|
+
assert_equal expected, doc.to_kramdown
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_parse_image
|
151
|
+
prismic = [
|
152
|
+
{
|
153
|
+
type: "image",
|
154
|
+
content: {
|
155
|
+
text: "",
|
156
|
+
spans: []
|
157
|
+
},
|
158
|
+
data: {
|
159
|
+
origin: {
|
160
|
+
url: '/img.png'
|
161
|
+
},
|
162
|
+
alt: 'alt text'
|
163
|
+
}
|
164
|
+
}
|
165
|
+
]
|
166
|
+
expected = "![alt text](/img.png)\n\n"
|
167
|
+
doc = Kramdown::Document.new(prismic, input: :prismic)
|
168
|
+
assert_equal expected, doc.to_kramdown
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_parse_preformatted
|
172
|
+
prismic = [
|
173
|
+
{
|
174
|
+
type: "preformatted",
|
175
|
+
content: {
|
176
|
+
text: "This is a pre block\n",
|
177
|
+
spans: []
|
178
|
+
}
|
179
|
+
}
|
180
|
+
]
|
181
|
+
expected = "> This is a pre block \n\n"
|
182
|
+
doc = Kramdown::Document.new(prismic, input: :prismic)
|
183
|
+
assert_equal expected, doc.to_kramdown
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_parse_embed
|
187
|
+
prismic = [
|
188
|
+
{
|
189
|
+
type: "embed",
|
190
|
+
data: {
|
191
|
+
type: "video",
|
192
|
+
embed_url: "https://www.youtube.com/watch?v=y6y_4_b6RS8"
|
193
|
+
},
|
194
|
+
content: {
|
195
|
+
text: "",
|
196
|
+
spans: []
|
197
|
+
}
|
198
|
+
}
|
199
|
+
]
|
200
|
+
expected = "<iframe src=\"https://www.youtube.com/watch?v=y6y_4_b6RS8\"></iframe>\n"
|
201
|
+
doc = Kramdown::Document.new(prismic, input: :prismic)
|
202
|
+
assert_equal expected, doc.to_kramdown
|
203
|
+
end
|
204
|
+
end
|
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.
|
4
|
+
version: 0.2.2
|
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: 2021-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -44,22 +44,24 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
description: A Kramdown converter to convert documents into prismic rich text format.
|
56
56
|
email: francois@2metz.fr
|
57
57
|
executables: []
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
+
- ".github/workflows/ci.yml"
|
61
62
|
- ".gitignore"
|
62
63
|
- ".travis.yml"
|
64
|
+
- Changelog.md
|
63
65
|
- Gemfile
|
64
66
|
- Gemfile.lock
|
65
67
|
- LICENSE
|
@@ -69,7 +71,9 @@ files:
|
|
69
71
|
- lib/kramdown-prismic.rb
|
70
72
|
- lib/kramdown-prismic/version.rb
|
71
73
|
- lib/kramdown/converter/prismic.rb
|
72
|
-
-
|
74
|
+
- lib/kramdown/parser/prismic.rb
|
75
|
+
- test/converter_test.rb
|
76
|
+
- test/parser_test.rb
|
73
77
|
homepage: https://github.com/stormz/kramdown-prismic
|
74
78
|
licenses:
|
75
79
|
- MIT
|
@@ -89,10 +93,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
93
|
- !ruby/object:Gem::Version
|
90
94
|
version: '0'
|
91
95
|
requirements: []
|
92
|
-
|
93
|
-
rubygems_version: 2.6.11
|
96
|
+
rubygems_version: 3.0.3
|
94
97
|
signing_key:
|
95
98
|
specification_version: 4
|
96
99
|
summary: A Kramdown converter to convert documents into prismic rich text format.
|
97
100
|
test_files:
|
98
|
-
- test/
|
101
|
+
- test/converter_test.rb
|
102
|
+
- test/parser_test.rb
|