kramdown-prismic 0.2.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +23 -2
- data/CHANGELOG.md +45 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +5 -3
- data/README.md +20 -3
- data/Rakefile +3 -2
- data/bin/html2prismic +6 -0
- data/bin/markdown2prismic +6 -0
- data/bin/prismic2markdown +8 -0
- data/kramdown-prismic.gemspec +12 -8
- data/kramdown1.gemfile +6 -0
- data/kramdown2.gemfile +6 -0
- data/lib/kramdown-prismic.rb +2 -0
- data/lib/kramdown-prismic/version.rb +3 -1
- data/lib/kramdown/converter/prismic.rb +68 -44
- data/lib/kramdown/parser/prismic.rb +60 -29
- data/test/converter_test.rb +159 -112
- data/test/parser_test.rb +173 -52
- metadata +26 -11
- data/.travis.yml +0 -6
- data/Changelog.md +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba6d3ad52704c02e2ec102cc69ca216f02c464ba6cde85c2f28024c66448a985
|
4
|
+
data.tar.gz: 64fdd7184a0184c10b72acb00d2109f1b3512fc53392327a5f537d091d5796ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea6f89410664900030c17478ed4cce6fb6a499974ef775f421fd1b720e7f28e123526eb1893889f42d8964928a1c2139387f2dae408a3ea19dffc50805430918
|
7
|
+
data.tar.gz: 95c6df198bfdacb61f24606575d4fd5d517b1285750a4dd463f15cc0416513759aec67183eb3820c64c221d5154acbb826e0a74b7e9f797ddfff7cbb2bbae165
|
data/.github/workflows/ci.yml
CHANGED
@@ -2,12 +2,33 @@ name: CI
|
|
2
2
|
|
3
3
|
on: [push, pull_request]
|
4
4
|
jobs:
|
5
|
-
test:
|
5
|
+
test-kramdown2:
|
6
6
|
strategy:
|
7
7
|
fail-fast: false
|
8
8
|
matrix:
|
9
9
|
os: [ubuntu-latest]
|
10
|
-
ruby: [2.
|
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
|
11
32
|
runs-on: ${{ matrix.os }}
|
12
33
|
steps:
|
13
34
|
- uses: actions/checkout@v2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## Version 0.3.3
|
4
|
+
|
5
|
+
- Renable converting xml comments
|
6
|
+
|
7
|
+
## Version 0.3.2
|
8
|
+
|
9
|
+
- Parse ordered and unordered lists
|
10
|
+
- Parse image with link
|
11
|
+
|
12
|
+
## Version 0.3.1
|
13
|
+
|
14
|
+
- Add binaries `html2primisc`, `markdown2prismic` and `primisc2markdown`.
|
15
|
+
- Add parsed embed support
|
16
|
+
|
17
|
+
## Version 0.3.0
|
18
|
+
|
19
|
+
- Relax the kramdown dependency to allows the version 2.
|
20
|
+
- XML elements support have been removed.
|
21
|
+
|
22
|
+
## Version 0.2.2
|
23
|
+
|
24
|
+
- Convert links with only an image inside. See #1.
|
25
|
+
|
26
|
+
## Version 0.2.1
|
27
|
+
|
28
|
+
- Parse embed elements
|
29
|
+
- Convert inline code
|
30
|
+
|
31
|
+
## Version 0.2.0
|
32
|
+
|
33
|
+
- Add parser to convert prismic to markdown
|
34
|
+
|
35
|
+
## Version 0.1.2
|
36
|
+
|
37
|
+
- fix output with empty paragraph
|
38
|
+
|
39
|
+
## Version 0.1.1
|
40
|
+
|
41
|
+
- Fix json of the image
|
42
|
+
|
43
|
+
## Version 0.1.0
|
44
|
+
|
45
|
+
- Initial version
|
data/Gemfile
CHANGED
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.3)
|
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
13
|
rake (13.0.6)
|
14
|
+
rexml (3.2.5)
|
13
15
|
|
14
16
|
PLATFORMS
|
15
17
|
ruby
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# Kramdown Prismic
|
2
2
|
|
3
|
-
A [Kramdown][] parser and converter to convert documents into [prismic][] rich text format and
|
3
|
+
A [Kramdown][] parser and converter to convert documents into [prismic][] rich text format and the other way around.
|
4
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.
|
5
|
+
A useful usage is to convert markdown documents to prismic for [import purpose][prismic-import]. Then you can even convert prismic format back to markdown.
|
6
6
|
|
7
7
|
## Status
|
8
8
|
|
9
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
10
|
|
11
|
-
The parser part is quite new and not feature complete
|
11
|
+
The parser part is quite new and not feature complete.
|
12
12
|
|
13
13
|
## Install
|
14
14
|
|
@@ -18,6 +18,22 @@ gem 'kramdown-prismic', '~> 0.1'
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
### With executables
|
22
|
+
|
23
|
+
*markdown2prismic*:
|
24
|
+
|
25
|
+
markdown2prismic $'# My Title\n\nHello world'
|
26
|
+
|
27
|
+
*html2prismic*:
|
28
|
+
|
29
|
+
html2prismic '<h1>My Title</h1><p>Hello world</p>'
|
30
|
+
|
31
|
+
*prismic2markdown*:
|
32
|
+
|
33
|
+
prismic2markdown '[{"type":"heading1","content":{"text":"My Title","spans":[]}},{"type":"paragraph","content":{"text":"Test","spans":[]}}]'
|
34
|
+
|
35
|
+
### As a library
|
36
|
+
|
21
37
|
**Convert kramdown documents to Prismic**
|
22
38
|
|
23
39
|
```ruby
|
@@ -123,3 +139,4 @@ MIT
|
|
123
139
|
|
124
140
|
[Kramdown]: https://kramdown.gettalong.org/
|
125
141
|
[prismic]: https://prismic.io/
|
142
|
+
[prismic-import]: https://prismic.io/docs/core-concepts/how-to-import-content
|
data/Rakefile
CHANGED
data/bin/html2prismic
ADDED
data/kramdown-prismic.gemspec
CHANGED
@@ -1,21 +1,25 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('lib/kramdown-prismic/version', __dir__)
|
3
4
|
|
4
5
|
Gem::Specification.new do |s|
|
5
6
|
s.name = 'kramdown-prismic'
|
6
7
|
s.version = KramdownPrismic::VERSION
|
7
|
-
s.summary =
|
8
|
-
s.description =
|
9
|
-
s.authors = [
|
8
|
+
s.summary = 'A Kramdown converter to convert documents into prismic rich text format and the other way around.'
|
9
|
+
s.description = 'A Kramdown converter to convert documents into prismic rich text format and the other way around.'
|
10
|
+
s.authors = ['François de Metz']
|
10
11
|
s.email = 'francois@2metz.fr'
|
11
12
|
|
13
|
+
s.executables << 'markdown2prismic'
|
14
|
+
s.executables << 'html2prismic'
|
15
|
+
s.executables << 'prismic2markdown'
|
12
16
|
s.files = `git ls-files`.split("\n")
|
13
17
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
14
18
|
|
15
19
|
s.homepage = 'https://github.com/stormz/kramdown-prismic'
|
16
20
|
s.license = 'MIT'
|
17
21
|
|
18
|
-
s.add_dependency
|
19
|
-
s.add_development_dependency
|
20
|
-
s.add_development_dependency
|
22
|
+
s.add_dependency 'kramdown', '>= 1', '< 3'
|
23
|
+
s.add_development_dependency 'minitest', '~> 5.0'
|
24
|
+
s.add_development_dependency 'rake', '~> 13.0'
|
21
25
|
end
|
data/kramdown1.gemfile
ADDED
data/kramdown2.gemfile
ADDED
data/lib/kramdown-prismic.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'kramdown/converter/base'
|
2
4
|
|
3
5
|
module Kramdown
|
4
6
|
module Converter
|
5
7
|
class Prismic < Base
|
6
8
|
def convert(root)
|
7
|
-
cleanup_ast(root).map
|
9
|
+
cleanup_ast(root).map do |child|
|
8
10
|
convert_element(child)
|
9
|
-
|
11
|
+
end.compact.flatten
|
10
12
|
end
|
11
13
|
|
12
14
|
private
|
@@ -21,22 +23,23 @@ module Kramdown
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def remove_blanks(root)
|
24
|
-
root.children = root.children.
|
26
|
+
root.children = root.children.each_with_object([]) do |child, memo|
|
25
27
|
unless child.type == :blank
|
26
28
|
remove_blanks(child)
|
27
29
|
memo << child
|
28
30
|
end
|
29
|
-
memo
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
34
|
def extract_non_nestable_elements(child, elements)
|
34
|
-
child.children = child.children.
|
35
|
-
if element.type == :a && element.children.size
|
35
|
+
child.children = child.children.each_with_object([]) do |element, memo|
|
36
|
+
if element.type == :a && element.children.size == 1 && element.children.first.type == :img
|
36
37
|
elements << element
|
37
38
|
elsif element.type == :img
|
38
39
|
elements << element
|
39
|
-
|
40
|
+
if child.children.size > 1
|
41
|
+
warning('images inside content will be moved to the top level and may be rendered differently')
|
42
|
+
end
|
40
43
|
elsif element.type == :ul
|
41
44
|
warning('nested list moved to the top level')
|
42
45
|
elements << element
|
@@ -45,7 +48,6 @@ module Kramdown
|
|
45
48
|
memo << element
|
46
49
|
extract_non_nestable_elements(element, elements)
|
47
50
|
end
|
48
|
-
memo
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -61,9 +63,10 @@ module Kramdown
|
|
61
63
|
end
|
62
64
|
|
63
65
|
def convert_p(element)
|
64
|
-
return nil if element.children.size
|
66
|
+
return nil if element.children.size.zero?
|
67
|
+
|
65
68
|
{
|
66
|
-
type:
|
69
|
+
type: 'paragraph',
|
67
70
|
content: extract_content(element)
|
68
71
|
}
|
69
72
|
end
|
@@ -106,8 +109,7 @@ module Kramdown
|
|
106
109
|
}
|
107
110
|
end
|
108
111
|
|
109
|
-
def convert_hr(element)
|
110
|
-
end
|
112
|
+
def convert_hr(element); end
|
111
113
|
|
112
114
|
def convert_img(element)
|
113
115
|
{
|
@@ -118,9 +120,9 @@ module Kramdown
|
|
118
120
|
},
|
119
121
|
data: {
|
120
122
|
origin: {
|
121
|
-
url: element.attr[
|
123
|
+
url: element.attr['src']
|
122
124
|
},
|
123
|
-
alt: element.attr[
|
125
|
+
alt: element.attr['alt']
|
124
126
|
}
|
125
127
|
}
|
126
128
|
end
|
@@ -147,49 +149,67 @@ module Kramdown
|
|
147
149
|
end
|
148
150
|
|
149
151
|
def convert_html_element(element)
|
150
|
-
|
151
|
-
|
152
|
+
if element.value == 'iframe'
|
153
|
+
{
|
154
|
+
content: {
|
155
|
+
spans: [],
|
156
|
+
text: ''
|
157
|
+
},
|
158
|
+
type: 'embed',
|
159
|
+
data: {
|
160
|
+
embed_url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
161
|
+
type: 'link'
|
162
|
+
}
|
163
|
+
}
|
164
|
+
else
|
165
|
+
warning('translating html elements is not supported')
|
166
|
+
nil
|
167
|
+
end
|
152
168
|
end
|
153
169
|
|
154
|
-
def convert_table(
|
170
|
+
def convert_table(_element)
|
155
171
|
warning('translating table is not supported')
|
156
172
|
nil
|
157
173
|
end
|
158
174
|
|
159
|
-
def convert_dl(
|
175
|
+
def convert_dl(_element)
|
160
176
|
warning('translating dl is not supported')
|
161
177
|
nil
|
162
178
|
end
|
163
179
|
|
164
|
-
def convert_math(
|
180
|
+
def convert_math(_element)
|
165
181
|
warning('translating math is not supported')
|
166
182
|
nil
|
167
183
|
end
|
168
184
|
|
169
|
-
def convert_comment(
|
185
|
+
def convert_comment(_element)
|
170
186
|
warning('translating comment is not supported')
|
171
187
|
nil
|
172
188
|
end
|
173
189
|
|
174
|
-
def convert_xml_comment(
|
175
|
-
warning('translating
|
190
|
+
def convert_xml_comment(_element)
|
191
|
+
warning('translating xml comment is not supported')
|
176
192
|
nil
|
177
193
|
end
|
178
194
|
|
179
|
-
def
|
180
|
-
warning('translating
|
195
|
+
def convert_raw(_element)
|
196
|
+
warning('translating raw is not supported')
|
181
197
|
nil
|
182
198
|
end
|
183
199
|
|
184
|
-
def
|
185
|
-
|
186
|
-
|
200
|
+
def convert_text(element)
|
201
|
+
{
|
202
|
+
type: 'paragraph',
|
203
|
+
content: {
|
204
|
+
text: element.value,
|
205
|
+
spans: []
|
206
|
+
}
|
207
|
+
}
|
187
208
|
end
|
188
209
|
|
189
|
-
def extract_content(element, memo={text: '', spans: []})
|
190
|
-
element.children.
|
210
|
+
def extract_content(element, memo = { text: '', spans: [] })
|
211
|
+
element.children.each_with_object(memo) do |child, memo2|
|
191
212
|
send("extract_span_#{child.type}", child, memo2)
|
192
|
-
memo2
|
193
213
|
end
|
194
214
|
end
|
195
215
|
|
@@ -210,7 +230,7 @@ module Kramdown
|
|
210
230
|
insert_span(element, memo, {
|
211
231
|
type: 'hyperlink',
|
212
232
|
data: {
|
213
|
-
url: element.attr[
|
233
|
+
url: element.attr['href']
|
214
234
|
}
|
215
235
|
})
|
216
236
|
end
|
@@ -231,7 +251,7 @@ module Kramdown
|
|
231
251
|
extract_content(element, memo)
|
232
252
|
end
|
233
253
|
|
234
|
-
def extract_span_br(
|
254
|
+
def extract_span_br(_element, memo)
|
235
255
|
memo[:text] += "\n"
|
236
256
|
end
|
237
257
|
|
@@ -240,11 +260,11 @@ module Kramdown
|
|
240
260
|
memo[:text] += element.value
|
241
261
|
end
|
242
262
|
|
243
|
-
def extract_span_html_element(
|
263
|
+
def extract_span_html_element(_element, _memo)
|
244
264
|
warning('translating html elements is not supported')
|
245
265
|
end
|
246
266
|
|
247
|
-
def extract_span_footnote(
|
267
|
+
def extract_span_footnote(_element, _memo)
|
248
268
|
warning('translating footnote is not supported')
|
249
269
|
end
|
250
270
|
|
@@ -253,17 +273,21 @@ module Kramdown
|
|
253
273
|
memo[:text] += element.value
|
254
274
|
end
|
255
275
|
|
276
|
+
def extract_span_xml_comment(element, memo)
|
277
|
+
warning('translating xml comment is not supported')
|
278
|
+
end
|
279
|
+
|
256
280
|
TYPOGRAPHIC_SYMS = {
|
257
|
-
mdash: [
|
258
|
-
ndash: [
|
259
|
-
hellip: [
|
260
|
-
laquo_space: [
|
261
|
-
raquo_space: [
|
262
|
-
laquo: [
|
263
|
-
raquo: [
|
264
|
-
}
|
281
|
+
mdash: [Utils::Entities.entity('mdash')],
|
282
|
+
ndash: [Utils::Entities.entity('ndash')],
|
283
|
+
hellip: [Utils::Entities.entity('hellip')],
|
284
|
+
laquo_space: [Utils::Entities.entity('laquo'), Utils::Entities.entity('nbsp')],
|
285
|
+
raquo_space: [Utils::Entities.entity('nbsp'), Utils::Entities.entity('raquo')],
|
286
|
+
laquo: [Utils::Entities.entity('laquo')],
|
287
|
+
raquo: [Utils::Entities.entity('raquo')]
|
288
|
+
}.freeze
|
265
289
|
def extract_span_typographic_sym(element, memo)
|
266
|
-
value = TYPOGRAPHIC_SYMS[element.value].map
|
290
|
+
value = TYPOGRAPHIC_SYMS[element.value].map(&:char).join('')
|
267
291
|
memo[:text] += value
|
268
292
|
end
|
269
293
|
|
@@ -272,7 +296,7 @@ module Kramdown
|
|
272
296
|
end
|
273
297
|
|
274
298
|
def extract_span_smart_quote(element, memo)
|
275
|
-
memo[:text] +=
|
299
|
+
memo[:text] += Utils::Entities.entity(element.value.to_s).char
|
276
300
|
end
|
277
301
|
end
|
278
302
|
end
|