kramdown-prismic 0.1.2 → 0.3.0
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 +39 -0
- data/Changelog.md +18 -0
- data/Gemfile.lock +8 -6
- data/LICENSE +1 -0
- data/README.md +86 -15
- data/kramdown-prismic.gemspec +4 -4
- data/kramdown1.gemfile +4 -0
- data/kramdown2.gemfile +4 -0
- data/lib/kramdown-prismic.rb +1 -0
- data/lib/kramdown-prismic/version.rb +1 -1
- data/lib/kramdown/converter/prismic.rb +29 -11
- data/lib/kramdown/parser/prismic.rb +101 -0
- data/test/{kramdown-prismic_test.rb → converter_test.rb} +60 -32
- data/test/parser_test.rb +204 -0
- metadata +27 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5375492a7419784a19fee9021699380d7106184167742f73f693502aeee28767
|
4
|
+
data.tar.gz: 378f78feb7e48a07c5177a7ae98556fb918a6b6258201227a5cfd415dc73d23c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b90f2f0df8505ef0403704d0db3c32aa3003589e5bd958827ed270347e477b7b87f464626781fa0049b43bf5372f6fd501e4d476b83a61d8bd4d0c399f020bcf
|
7
|
+
data.tar.gz: 87d4c10f8ccd35b29ee9fc0b030a604490f35354bb86809bf18c8dfcfe79c3ae62199aa3f2b7195290be38febe09c76a7d9df74734845c9e0b0ebde41602661c
|
@@ -0,0 +1,39 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
jobs:
|
5
|
+
test-kramdown2:
|
6
|
+
strategy:
|
7
|
+
fail-fast: false
|
8
|
+
matrix:
|
9
|
+
os: [ubuntu-latest]
|
10
|
+
ruby: [2.6, 2.7, "3.0"]
|
11
|
+
gemfile: [ kramdown2 ]
|
12
|
+
env:
|
13
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}.gemfile
|
14
|
+
runs-on: ${{ matrix.os }}
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby }}
|
20
|
+
bundler-cache: true
|
21
|
+
- run: bundle exec rake test
|
22
|
+
|
23
|
+
test-kramdown1:
|
24
|
+
strategy:
|
25
|
+
fail-fast: false
|
26
|
+
matrix:
|
27
|
+
os: [ubuntu-latest]
|
28
|
+
ruby: [2.6, 2.7]
|
29
|
+
gemfile: [ kramdown1 ]
|
30
|
+
env:
|
31
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}.gemfile
|
32
|
+
runs-on: ${{ matrix.os }}
|
33
|
+
steps:
|
34
|
+
- uses: actions/checkout@v2
|
35
|
+
- uses: ruby/setup-ruby@v1
|
36
|
+
with:
|
37
|
+
ruby-version: ${{ matrix.ruby }}
|
38
|
+
bundler-cache: true
|
39
|
+
- run: bundle exec rake test
|
data/Changelog.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Version 0.3.0
|
4
|
+
|
5
|
+
- Relax the kramdown dependency to allows the version 2.
|
6
|
+
- XML elements support have been removed.
|
7
|
+
|
8
|
+
## Version 0.2.2
|
9
|
+
|
10
|
+
- Convert links with only an image inside. See #1.
|
11
|
+
|
12
|
+
## Version 0.2.1
|
13
|
+
|
14
|
+
- Parse embed elements
|
15
|
+
- Convert inline code
|
16
|
+
|
17
|
+
## Version 0.2.0
|
18
|
+
|
19
|
+
- Add parser to convert prismic to markdown
|
20
|
+
|
3
21
|
## Version 0.1.2
|
4
22
|
|
5
23
|
- fix output with empty paragraph
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kramdown-prismic (0.
|
5
|
-
kramdown (
|
4
|
+
kramdown-prismic (0.3.0)
|
5
|
+
kramdown (>= 1, < 3)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
kramdown (
|
10
|
+
kramdown (2.3.1)
|
11
|
+
rexml
|
11
12
|
minitest (5.10.3)
|
12
|
-
rake (
|
13
|
+
rake (13.0.6)
|
14
|
+
rexml (3.2.5)
|
13
15
|
|
14
16
|
PLATFORMS
|
15
17
|
ruby
|
@@ -17,7 +19,7 @@ PLATFORMS
|
|
17
19
|
DEPENDENCIES
|
18
20
|
kramdown-prismic!
|
19
21
|
minitest (~> 5.0)
|
20
|
-
rake (~>
|
22
|
+
rake (~> 13.0)
|
21
23
|
|
22
24
|
BUNDLED WITH
|
23
|
-
1.
|
25
|
+
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
@@ -4,8 +4,8 @@ require File.expand_path('../lib/kramdown-prismic/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'kramdown-prismic'
|
6
6
|
s.version = KramdownPrismic::VERSION
|
7
|
-
s.summary = "A Kramdown converter to convert documents into prismic rich text format."
|
8
|
-
s.description = "A Kramdown converter to convert documents into prismic rich text format."
|
7
|
+
s.summary = "A Kramdown converter to convert documents into prismic rich text format and the other way around."
|
8
|
+
s.description = "A Kramdown converter to convert documents into prismic rich text format and the other way around."
|
9
9
|
s.authors = ["François de Metz"]
|
10
10
|
s.email = 'francois@2metz.fr'
|
11
11
|
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.homepage = 'https://github.com/stormz/kramdown-prismic'
|
16
16
|
s.license = 'MIT'
|
17
17
|
|
18
|
-
s.add_dependency "kramdown", "
|
18
|
+
s.add_dependency "kramdown", ">= 1", "< 3"
|
19
19
|
s.add_development_dependency "minitest", "~> 5.0"
|
20
|
-
s.add_development_dependency "rake", "~>
|
20
|
+
s.add_development_dependency "rake", "~> 13.0"
|
21
21
|
end
|
data/kramdown1.gemfile
ADDED
data/kramdown2.gemfile
ADDED
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
|
@@ -123,6 +125,27 @@ module Kramdown
|
|
123
125
|
}
|
124
126
|
end
|
125
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
|
+
|
126
149
|
def convert_html_element(element)
|
127
150
|
warning('translating html elements is not supported')
|
128
151
|
nil
|
@@ -148,16 +171,6 @@ module Kramdown
|
|
148
171
|
nil
|
149
172
|
end
|
150
173
|
|
151
|
-
def convert_xml_comment(element)
|
152
|
-
warning('translating xml_comment is not supported')
|
153
|
-
nil
|
154
|
-
end
|
155
|
-
|
156
|
-
def convert_xml_pi(element)
|
157
|
-
warning('translating xml_pi is not supported')
|
158
|
-
nil
|
159
|
-
end
|
160
|
-
|
161
174
|
def convert_raw(element)
|
162
175
|
warning('translating raw is not supported')
|
163
176
|
nil
|
@@ -212,6 +225,11 @@ module Kramdown
|
|
212
225
|
memo[:text] += "\n"
|
213
226
|
end
|
214
227
|
|
228
|
+
def extract_span_codespan(element, memo)
|
229
|
+
warning('translating inline code is not supported')
|
230
|
+
memo[:text] += element.value
|
231
|
+
end
|
232
|
+
|
215
233
|
def extract_span_html_element(element, memo)
|
216
234
|
warning('translating html elements is not supported')
|
217
235
|
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
|
|
@@ -364,6 +367,31 @@ class KramdownPrismicTest < Minitest::Test
|
|
364
367
|
assert_equal 2, doc.warnings.size
|
365
368
|
end
|
366
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 = "[](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
|
+
|
367
395
|
def test_convert_entity
|
368
396
|
expected = [
|
369
397
|
{
|
@@ -414,6 +442,22 @@ class KramdownPrismicTest < Minitest::Test
|
|
414
442
|
assert_equal expected, Kramdown::Document.new(markdown, input: :kramdown).to_prismic
|
415
443
|
end
|
416
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
|
+
|
417
461
|
def test_convert_br
|
418
462
|
expected = [
|
419
463
|
{type: "paragraph",
|
@@ -513,22 +557,6 @@ class KramdownPrismicTest < Minitest::Test
|
|
513
557
|
assert_equal 1, doc.warnings.size
|
514
558
|
end
|
515
559
|
|
516
|
-
def test_convert_xml_comment
|
517
|
-
expected = []
|
518
|
-
markdown = "<!-- a *comment* -->"
|
519
|
-
doc = Kramdown::Document.new(markdown, input: :kramdown)
|
520
|
-
assert_equal expected, doc.to_prismic
|
521
|
-
assert_equal 1, doc.warnings.size
|
522
|
-
end
|
523
|
-
|
524
|
-
def test_convert_xml_pi
|
525
|
-
expected = []
|
526
|
-
markdown = "<? a processing `instruction`?>"
|
527
|
-
doc = Kramdown::Document.new(markdown, input: :kramdown)
|
528
|
-
assert_equal expected, doc.to_prismic
|
529
|
-
assert_equal 1, doc.warnings.size
|
530
|
-
end
|
531
|
-
|
532
560
|
def test_convert_raw
|
533
561
|
expected = []
|
534
562
|
markdown = "{::nomarkdown}\nComment\n{:/nomarkdown}"
|
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,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kramdown-prismic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
22
|
+
version: '3'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
32
|
+
version: '3'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: minitest
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,20 +50,22 @@ dependencies:
|
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '13.0'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
description: A Kramdown converter to convert documents into prismic rich text format
|
60
|
+
version: '13.0'
|
61
|
+
description: A Kramdown converter to convert documents into prismic rich text format
|
62
|
+
and the other way around.
|
56
63
|
email: francois@2metz.fr
|
57
64
|
executables: []
|
58
65
|
extensions: []
|
59
66
|
extra_rdoc_files: []
|
60
67
|
files:
|
68
|
+
- ".github/workflows/ci.yml"
|
61
69
|
- ".gitignore"
|
62
70
|
- ".travis.yml"
|
63
71
|
- Changelog.md
|
@@ -67,10 +75,14 @@ files:
|
|
67
75
|
- README.md
|
68
76
|
- Rakefile
|
69
77
|
- kramdown-prismic.gemspec
|
78
|
+
- kramdown1.gemfile
|
79
|
+
- kramdown2.gemfile
|
70
80
|
- lib/kramdown-prismic.rb
|
71
81
|
- lib/kramdown-prismic/version.rb
|
72
82
|
- lib/kramdown/converter/prismic.rb
|
73
|
-
-
|
83
|
+
- lib/kramdown/parser/prismic.rb
|
84
|
+
- test/converter_test.rb
|
85
|
+
- test/parser_test.rb
|
74
86
|
homepage: https://github.com/stormz/kramdown-prismic
|
75
87
|
licenses:
|
76
88
|
- MIT
|
@@ -90,10 +102,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
102
|
- !ruby/object:Gem::Version
|
91
103
|
version: '0'
|
92
104
|
requirements: []
|
93
|
-
|
94
|
-
rubygems_version: 2.6.11
|
105
|
+
rubygems_version: 3.0.3
|
95
106
|
signing_key:
|
96
107
|
specification_version: 4
|
97
|
-
summary: A Kramdown converter to convert documents into prismic rich text format
|
108
|
+
summary: A Kramdown converter to convert documents into prismic rich text format and
|
109
|
+
the other way around.
|
98
110
|
test_files:
|
99
|
-
- test/
|
111
|
+
- test/converter_test.rb
|
112
|
+
- test/parser_test.rb
|