kramdown-prismic 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -5
- data/lib/kramdown/converter/prismic.rb +32 -1
- data/lib/kramdown-prismic/version.rb +1 -1
- data/test/kramdown-prismic_test.rb +24 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f359eb669c8df2396663e3178ea8b6f50be0df3e
|
4
|
+
data.tar.gz: 9b554b3ee7712f1f031dfef0e4ff50d3e28a40e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7824f29f541ece46868bdfaf577e152072de425619e92a721c974c9bfc01da7bb8f254362c0a05ed3a4ac826e0a29ecaf6979fffef56df68cc35b9485e05b3f4
|
7
|
+
data.tar.gz: 4136cd39ff0b11f6c5bfe7357d9a63a3b7d173f12006317d83d70fd42b8ac2ed90e82f11677f5e423936faf3e14de5d0aaaaed35f04b90fe7a870e2f076b9970
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ TODO:
|
|
15
15
|
- [x] heading5
|
16
16
|
- [x] heading6
|
17
17
|
- [x] paragraph
|
18
|
-
- [
|
18
|
+
- [x] preformatted
|
19
19
|
- [x] strong
|
20
20
|
- [x] em
|
21
21
|
- [x] hyperlink
|
@@ -26,10 +26,31 @@ TODO:
|
|
26
26
|
|
27
27
|
## Difference between markdown and rich text
|
28
28
|
|
29
|
-
| Markdown
|
30
|
-
|
31
|
-
| Blockquote
|
32
|
-
| hr
|
29
|
+
| Markdown | Prismic |
|
30
|
+
|------------------|----------------------------|
|
31
|
+
| Blockquote | translated to preformatted |
|
32
|
+
| hr | nothing |
|
33
|
+
| img | moved to to level |
|
34
|
+
| dl | |
|
35
|
+
| dt | |
|
36
|
+
| dl | |
|
37
|
+
| table | |
|
38
|
+
| thead | |
|
39
|
+
| tobdy | |
|
40
|
+
| tfoot | |
|
41
|
+
| tr | |
|
42
|
+
| td | |
|
43
|
+
| math | |
|
44
|
+
| footnote | |
|
45
|
+
| entity | |
|
46
|
+
| typographic_sym | |
|
47
|
+
| smart_quote | |
|
48
|
+
| abbreviation | |
|
49
|
+
| html_element | |
|
50
|
+
| xml_comment | |
|
51
|
+
| xml_pi | |
|
52
|
+
| comment | |
|
53
|
+
| raw | |
|
33
54
|
|
34
55
|
## Install
|
35
56
|
|
@@ -4,13 +4,31 @@ module Kramdown
|
|
4
4
|
module Converter
|
5
5
|
class Prismic < Base
|
6
6
|
def convert(root)
|
7
|
-
root.
|
7
|
+
move_img_to_top_level(root).map { |child|
|
8
8
|
convert_element(child)
|
9
9
|
}.compact.flatten
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
+
def move_img_to_top_level(root)
|
15
|
+
root.children.map do |child|
|
16
|
+
imgs = find_imgs(child)
|
17
|
+
[child, imgs]
|
18
|
+
end.flatten.compact
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_imgs(child)
|
22
|
+
child.children.map do |element|
|
23
|
+
if element.type == :img
|
24
|
+
child.children.slice!(child.children.find_index(element))
|
25
|
+
element
|
26
|
+
else
|
27
|
+
find_imgs(element)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
14
32
|
def convert_element(element)
|
15
33
|
send("convert_#{element.type}", element)
|
16
34
|
end
|
@@ -73,6 +91,19 @@ module Kramdown
|
|
73
91
|
def convert_hr(element)
|
74
92
|
end
|
75
93
|
|
94
|
+
def convert_img(element)
|
95
|
+
{
|
96
|
+
type: 'image',
|
97
|
+
content: {
|
98
|
+
text: '',
|
99
|
+
spans: []
|
100
|
+
},
|
101
|
+
data: {
|
102
|
+
url: element.attr["src"]
|
103
|
+
}
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
76
107
|
def extract_content(element, memo={text: '', spans: []})
|
77
108
|
element.children.inject(memo) do |memo2, child|
|
78
109
|
send("extract_span_#{child.type}", child, memo2)
|
@@ -240,4 +240,28 @@ class KramdownPrismicTest < Minitest::Test
|
|
240
240
|
markdown = "---"
|
241
241
|
assert_equal expected, Kramdown::Document.new(markdown, input: :markdown).to_prismic
|
242
242
|
end
|
243
|
+
|
244
|
+
def test_convert_img
|
245
|
+
expected = [
|
246
|
+
{
|
247
|
+
type: "paragraph",
|
248
|
+
content: {
|
249
|
+
text: "",
|
250
|
+
spans: []
|
251
|
+
}
|
252
|
+
},
|
253
|
+
{
|
254
|
+
type: "image",
|
255
|
+
content: {
|
256
|
+
text: "",
|
257
|
+
spans: []
|
258
|
+
},
|
259
|
+
data: {
|
260
|
+
url: '/img.png'
|
261
|
+
}
|
262
|
+
}
|
263
|
+
]
|
264
|
+
markdown = "![](/img.png)"
|
265
|
+
assert_equal expected, Kramdown::Document.new(markdown).to_prismic
|
266
|
+
end
|
243
267
|
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.0.
|
4
|
+
version: 0.0.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: 2017-10-
|
11
|
+
date: 2017-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|