kramdown-prismic 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +18 -0
- data/.travis.yml +6 -0
- data/Changelog.md +22 -0
- data/Gemfile.lock +3 -3
- data/LICENSE +1 -0
- data/README.md +86 -15
- data/lib/kramdown-prismic.rb +1 -0
- data/lib/kramdown-prismic/version.rb +1 -1
- data/lib/kramdown/converter/prismic.rb +9 -1
- data/lib/kramdown/parser/prismic.rb +101 -0
- data/test/{kramdown-prismic_test.rb → converter_test.rb} +44 -33
- data/test/parser_test.rb +204 -0
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bb835641c9e7f2e9e600e0307e3bfd6e9eb46e5d83ae257c505c659c20865931
|
4
|
+
data.tar.gz: cba5da2b2d81fff052b24d7921872ec8e9607b726bdbe210ff516b6cf7b6810a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b4e02f18a5dbf5c51f46cc729c8dd2018d1eec8809790e0492ee22f7886627e5bc77d20dabde755f44883f1c062cd7a7dda33ba8acbe9c4dac165218f23ca70
|
7
|
+
data.tar.gz: 5428075b5c8eac073a1729feac6803a378ac55ba330540c46c230f78b5e965caeb95b26ea60be9f059611d182cb0f6c764c2817f9b03c53b1dcde03ec923d86b
|
@@ -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/.travis.yml
ADDED
data/Changelog.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## Version 0.2.1
|
4
|
+
|
5
|
+
- Parse embed elements
|
6
|
+
- Convert inline code
|
7
|
+
|
8
|
+
## Version 0.2.0
|
9
|
+
|
10
|
+
- Add parser to convert prismic to markdown
|
11
|
+
|
12
|
+
## Version 0.1.2
|
13
|
+
|
14
|
+
- fix output with empty paragraph
|
15
|
+
|
16
|
+
## Version 0.1.1
|
17
|
+
|
18
|
+
- Fix json of the image
|
19
|
+
|
20
|
+
## Version 0.1.0
|
21
|
+
|
22
|
+
- Initial version
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kramdown-prismic (0.1
|
4
|
+
kramdown-prismic (0.2.1)
|
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
12
|
rake (12.2.1)
|
13
13
|
|
@@ -20,4 +20,4 @@ DEPENDENCIES
|
|
20
20
|
rake (~> 12.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/lib/kramdown-prismic.rb
CHANGED
@@ -59,6 +59,7 @@ module Kramdown
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def convert_p(element)
|
62
|
+
return nil if element.children.size == 0
|
62
63
|
{
|
63
64
|
type: "paragraph",
|
64
65
|
content: extract_content(element)
|
@@ -114,7 +115,9 @@ module Kramdown
|
|
114
115
|
spans: []
|
115
116
|
},
|
116
117
|
data: {
|
117
|
-
|
118
|
+
origin: {
|
119
|
+
url: element.attr["src"]
|
120
|
+
},
|
118
121
|
alt: element.attr["alt"]
|
119
122
|
}
|
120
123
|
}
|
@@ -209,6 +212,11 @@ module Kramdown
|
|
209
212
|
memo[:text] += "\n"
|
210
213
|
end
|
211
214
|
|
215
|
+
def extract_span_codespan(element, memo)
|
216
|
+
warning('translating inline code is not supported')
|
217
|
+
memo[:text] += element.value
|
218
|
+
end
|
219
|
+
|
212
220
|
def extract_span_html_element(element, memo)
|
213
221
|
warning('translating html elements is not supported')
|
214
222
|
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: {
|
@@ -323,7 +319,9 @@ class KramdownPrismicTest < Minitest::Test
|
|
323
319
|
spans: []
|
324
320
|
},
|
325
321
|
data: {
|
326
|
-
|
322
|
+
origin: {
|
323
|
+
url: '/img.png'
|
324
|
+
},
|
327
325
|
alt: 'alt text'
|
328
326
|
}
|
329
327
|
}
|
@@ -336,13 +334,6 @@ class KramdownPrismicTest < Minitest::Test
|
|
336
334
|
|
337
335
|
def test_convert_double_img
|
338
336
|
expected = [
|
339
|
-
{
|
340
|
-
type: "paragraph",
|
341
|
-
content: {
|
342
|
-
text: "",
|
343
|
-
spans: []
|
344
|
-
}
|
345
|
-
},
|
346
337
|
{
|
347
338
|
type: "image",
|
348
339
|
content: {
|
@@ -350,7 +341,9 @@ class KramdownPrismicTest < Minitest::Test
|
|
350
341
|
spans: []
|
351
342
|
},
|
352
343
|
data: {
|
353
|
-
|
344
|
+
origin: {
|
345
|
+
url: '/img.png'
|
346
|
+
},
|
354
347
|
alt: ''
|
355
348
|
}
|
356
349
|
},
|
@@ -361,7 +354,9 @@ class KramdownPrismicTest < Minitest::Test
|
|
361
354
|
spans: []
|
362
355
|
},
|
363
356
|
data: {
|
364
|
-
|
357
|
+
origin: {
|
358
|
+
url: '/img2.png'
|
359
|
+
},
|
365
360
|
alt: ''
|
366
361
|
}
|
367
362
|
}
|
@@ -422,6 +417,22 @@ class KramdownPrismicTest < Minitest::Test
|
|
422
417
|
assert_equal expected, Kramdown::Document.new(markdown, input: :kramdown).to_prismic
|
423
418
|
end
|
424
419
|
|
420
|
+
def test_convert_inline_code
|
421
|
+
expected = [
|
422
|
+
{
|
423
|
+
type: "paragraph",
|
424
|
+
content: {
|
425
|
+
text: "Hello code",
|
426
|
+
spans: []
|
427
|
+
}
|
428
|
+
}
|
429
|
+
]
|
430
|
+
markdown = "Hello `code`"
|
431
|
+
doc = Kramdown::Document.new(markdown)
|
432
|
+
assert_equal expected, doc.to_prismic
|
433
|
+
assert_equal 1, doc.warnings.size
|
434
|
+
end
|
435
|
+
|
425
436
|
def test_convert_br
|
426
437
|
expected = [
|
427
438
|
{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 = "\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.1
|
4
|
+
version: 0.2.1
|
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
|
@@ -58,7 +58,10 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
+
- ".github/workflows/ci.yml"
|
61
62
|
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Changelog.md
|
62
65
|
- Gemfile
|
63
66
|
- Gemfile.lock
|
64
67
|
- LICENSE
|
@@ -68,7 +71,9 @@ files:
|
|
68
71
|
- lib/kramdown-prismic.rb
|
69
72
|
- lib/kramdown-prismic/version.rb
|
70
73
|
- lib/kramdown/converter/prismic.rb
|
71
|
-
-
|
74
|
+
- lib/kramdown/parser/prismic.rb
|
75
|
+
- test/converter_test.rb
|
76
|
+
- test/parser_test.rb
|
72
77
|
homepage: https://github.com/stormz/kramdown-prismic
|
73
78
|
licenses:
|
74
79
|
- MIT
|
@@ -88,10 +93,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
93
|
- !ruby/object:Gem::Version
|
89
94
|
version: '0'
|
90
95
|
requirements: []
|
91
|
-
|
92
|
-
rubygems_version: 2.6.11
|
96
|
+
rubygems_version: 3.0.3
|
93
97
|
signing_key:
|
94
98
|
specification_version: 4
|
95
99
|
summary: A Kramdown converter to convert documents into prismic rich text format.
|
96
100
|
test_files:
|
97
|
-
- test/
|
101
|
+
- test/converter_test.rb
|
102
|
+
- test/parser_test.rb
|