prawndown-ext 0.1.12 → 0.1.14
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 +4 -4
- data/lib/prawndown/parser.rb +13 -7
- data/lib/prawndown/version.rb +1 -1
- data/lib/prawndown-ext.rb +47 -37
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e81c1189fb2fec119b406c1f56d8fbc18470b77eab3fbe6457fa97bcea2f187d
|
|
4
|
+
data.tar.gz: 8334d33e581d317302353c26b15d1bd58bdf8d955acb9713584e763264de27ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 04e7eafb5f0ef9d0c0b01053a7c89a9a1a5ec899d8c8cecc8ba4a450494d0818ee7a474d17f264b84cd5c3190f2850e599143ec8d2bd4f10b28664ee1a4bfb2a
|
|
7
|
+
data.tar.gz: f97af900e4fc8e2b464b9c3edafa7c41bcd270d0fdf72676d584b38842cfe67acd624f1324371c21f5aacc2070e96e58a4762d60490d0219985cdc24805e12aa
|
data/lib/prawndown/parser.rb
CHANGED
|
@@ -15,6 +15,12 @@ module PrawndownExt
|
|
|
15
15
|
]
|
|
16
16
|
|
|
17
17
|
DEFAULT_OPTIONS = {
|
|
18
|
+
"header1_line_space" => 5,
|
|
19
|
+
"header2_line_space" => 5,
|
|
20
|
+
"header3_line_space" => 5,
|
|
21
|
+
"header4_line_space" => 5,
|
|
22
|
+
"header5_line_space" => 5,
|
|
23
|
+
"header6_line_space" => 5,
|
|
18
24
|
"header1_size" => 28,
|
|
19
25
|
"header2_size" => 24,
|
|
20
26
|
"header3_size" => 20,
|
|
@@ -23,13 +29,13 @@ module PrawndownExt
|
|
|
23
29
|
"header6_size" => 14,
|
|
24
30
|
"quote_size" => 14,
|
|
25
31
|
"quote_font_spacing" => nil,
|
|
26
|
-
"quote_font" =>
|
|
27
|
-
"header1_font" =>
|
|
28
|
-
"header2_font" =>
|
|
29
|
-
"header3_font" =>
|
|
30
|
-
"header4_font" =>
|
|
31
|
-
"header5_font" =>
|
|
32
|
-
"header6_font" =>
|
|
32
|
+
"quote_font" => "quote",
|
|
33
|
+
"header1_font" => "header1",
|
|
34
|
+
"header2_font" => "header2",
|
|
35
|
+
"header3_font" => "header3",
|
|
36
|
+
"header4_font" => "header4",
|
|
37
|
+
"header5_font" => "header5",
|
|
38
|
+
"header6_font" => "header6",
|
|
33
39
|
"quote_margin" => 20,
|
|
34
40
|
"header1_margin" => 4,
|
|
35
41
|
"header2_margin" => 4,
|
data/lib/prawndown/version.rb
CHANGED
data/lib/prawndown-ext.rb
CHANGED
|
@@ -33,14 +33,19 @@ module PrawndownExt
|
|
|
33
33
|
options[args["command"] + "_line_spacing"] = 0
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
if !options.key?("
|
|
37
|
-
args["
|
|
36
|
+
if !options.key?(args["command"] + "_horizontal_margin")
|
|
37
|
+
options[args["command"] + "_horizontal_margin"] = 0
|
|
38
38
|
end
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
|
|
40
|
+
if !options.key?(args["command"] + "_vertical_margin")
|
|
41
|
+
options[args["command"] + "_vertical_margin"] = 0
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
margin = (options[args["command"] + "_horizontal_margin"] * 0.5).floor
|
|
45
|
+
half_margin = (options[args["command"] + "_vertical_margin"] * 0.5).floor
|
|
41
46
|
|
|
42
47
|
pdf.pad half_margin do
|
|
43
|
-
pdf.indent
|
|
48
|
+
pdf.indent margin, margin do
|
|
44
49
|
pdf.text args["text"], inline_format: true, leading: options[args["command"] + "_line_spacing"].to_f
|
|
45
50
|
end
|
|
46
51
|
end
|
|
@@ -86,19 +91,25 @@ module PrawndownExt
|
|
|
86
91
|
if File.extname(file) != ".gif"
|
|
87
92
|
if !(height.nil? && width.nil?)
|
|
88
93
|
|
|
89
|
-
if
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
if !options.key?("image_pad")
|
|
95
|
+
options["image_pad"] = 0
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
pdf.pad options["image_pad"] do
|
|
99
|
+
if height.nil? && !width.nil?
|
|
100
|
+
pdf.image(file,
|
|
101
|
+
width: [pdf.bounds.width, width].min,
|
|
102
|
+
position: :center)
|
|
103
|
+
elsif !height.nil? && width.nil?
|
|
104
|
+
pdf.image(file,
|
|
105
|
+
height: height,
|
|
106
|
+
position: :center)
|
|
107
|
+
else
|
|
108
|
+
pdf.image(file,
|
|
109
|
+
width: [pdf.bounds.width, width].min,
|
|
110
|
+
height: height,
|
|
111
|
+
position: :center)
|
|
112
|
+
end
|
|
102
113
|
end
|
|
103
114
|
end
|
|
104
115
|
end
|
|
@@ -125,30 +136,30 @@ module PrawndownExt
|
|
|
125
136
|
end
|
|
126
137
|
|
|
127
138
|
end
|
|
128
|
-
|
|
139
|
+
|
|
129
140
|
def unescape_text text
|
|
130
141
|
text = text.gsub('\\"', '"')
|
|
131
142
|
end
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
143
|
+
|
|
144
|
+
# Renders Markdown in the current document
|
|
145
|
+
#
|
|
146
|
+
# It supports header 1-6, bold text, italic text, strikethrough and links
|
|
147
|
+
# It supports the same options as +Prawn::Document#text+
|
|
148
|
+
#
|
|
149
|
+
# Prawn::Document.generate('markdown.pdf') do
|
|
150
|
+
# markdown '# Welcome to Prawndown!'
|
|
151
|
+
# markdown '**Important:** We _hope_ you enjoy your stay!'
|
|
152
|
+
# end
|
|
153
|
+
def markdown(string, options: {})
|
|
154
|
+
|
|
144
155
|
if !options.key?("default_line_spacing")
|
|
145
156
|
options["default_line_spacing"] = 0
|
|
146
157
|
end
|
|
147
158
|
|
|
148
|
-
|
|
159
|
+
processed = PrawndownExt::Parser.new(string, options).to_prawn
|
|
149
160
|
|
|
150
161
|
processed.each do |output|
|
|
151
|
-
|
|
162
|
+
|
|
152
163
|
begin
|
|
153
164
|
object = JSON.parse(output.strip)
|
|
154
165
|
|
|
@@ -156,10 +167,9 @@ module PrawndownExt
|
|
|
156
167
|
rescue
|
|
157
168
|
text unescape_text(output), inline_format: true, leading: options["default_line_spacing"].to_f
|
|
158
169
|
end
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
170
|
+
|
|
171
|
+
end
|
|
172
|
+
end
|
|
163
173
|
end
|
|
164
174
|
end
|
|
165
175
|
|