prawn-markup 0.3.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -42
- data/lib/prawn/markup/builders/list_builder.rb +2 -1
- data/lib/prawn/markup/builders/nestable_builder.rb +5 -3
- data/lib/prawn/markup/processor/images.rb +6 -2
- data/lib/prawn/markup/processor.rb +5 -1
- data/lib/prawn/markup/version.rb +1 -1
- data/prawn-markup.gemspec +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bf5359f2a3cd6a08af1cb55a8f698a0ff16105d27a8de7c1e747f9f2ea521a1
|
4
|
+
data.tar.gz: 3bd829e28c2bc4bc079834a9b0a21eb7d93ce57cfd3d511f2e511f2c8bd0cd4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0e6c543856fb3fdd86e9d873b093faec9ac91049489512dc16cbc23fee6f77a33b7eff48d152fda4f0d4dd4d12374de05efed01a4e295cf1adccc42a7699280
|
7
|
+
data.tar.gz: b5a02c1fa07ad2b2326e981f41b551d7f57b033ac196e94798f9d3250ed9ba76dd889709b77838c0eb8feebb5d7034309a03548ce5b0773d8c04d4c61103d335
|
data/README.md
CHANGED
@@ -37,16 +37,16 @@ doc.markup('<p>Hello World</p><hr/><p>KTHXBYE</p>')
|
|
37
37
|
|
38
38
|
This gem parses the given HTML and layouts the following elements in a vertical order:
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
- Text blocks: `p`, `div`, `ol`, `ul`, `li`, `hr`, `br`
|
41
|
+
- Text semantics: `a`, `b`, `strong`, `i`, `em`, `u`, `s`, `del`, `sub`, `sup`, `color`
|
42
|
+
- Headings: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`
|
43
|
+
- Tables: `table`, `tr`, `td`, `th`
|
44
|
+
- Media: `img`, `iframe`
|
45
|
+
- Inputs: `type=checkbox`, `type=radio`
|
46
46
|
|
47
47
|
All other elements are ignored, their content is added to the parent element. With a few exceptions, no CSS is processed. One exception is the `width` property of `img`, `td` and `th`, which may contain values in `cm`, `mm`, `px`, `pt`, `%` or `auto`. Another exception is the `rgb` or `cmyk` properties of the Prawn-specific `color` tag.
|
48
48
|
|
49
|
-
If no explicit loader is given (see
|
49
|
+
If no explicit loader is given (see below), images are loaded from `http(s)` addresses or may be contained in the `src` attribute as base64 encoded data URIs. Prawn only supports `PNG` and `JPG`.
|
50
50
|
|
51
51
|
## Example
|
52
52
|
|
@@ -75,40 +75,40 @@ Tables and lists are rendered with [prawn-table](https://github.com/prawnpdf/pra
|
|
75
75
|
|
76
76
|
Beside these options handled by Prawn / prawn-table, the following values may be customized:
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
78
|
+
- `:text`
|
79
|
+
- `:preprocessor`: A proc/callable that is called each time before a chunk of text is rendered.
|
80
|
+
- `:margin_bottom`: Margin after each `<p>`, `<ol>`, `<ul>` or `<table>`. Defaults to about half a line.
|
81
|
+
- `:heading1-6`
|
82
|
+
- `:margin_top`: Margin before a heading. Default is 0.
|
83
|
+
- `:margin_bottom`: Margin after a heading. Default is 0.
|
84
|
+
- `:table`
|
85
|
+
- `:placeholder`
|
86
|
+
- `:too_large`: If the table content does not fit into the current bounding box, this text/callable is rendered instead. Defaults to '[table content too large]'.
|
87
|
+
- `:subtable_too_large`: If the content of a subtable cannot be fitted into the table, this text is rendered instead. Defaults to '[nested tables with automatic width are not supported]'.
|
88
|
+
- `:list`
|
89
|
+
- `:vertical_margin`: Margin at the top and the bottom of a list. Default is 5.
|
90
|
+
- `:bullet`
|
91
|
+
- `:char`: The text used as bullet in unordered lists. Default is '•'.
|
92
|
+
- `:margin`: Margin before the bullet. Default is 10.
|
93
|
+
- `:content`
|
94
|
+
- `:margin`: Margin between the bullet and the content. Default is 10.
|
95
|
+
- `:placeholder`
|
96
|
+
- `:too_large`: If the list content does not fit into the current bounding box, this text/callable is rendered instead. Defaults to '[list content too large]'.
|
97
|
+
- `:image`
|
98
|
+
- `:loader`: A callable that accepts the `src` attribute as an argument an returns a value understood by Prawn's `image` method (e.g. an `IO` object). If no loader is configured or if it returns `nil`, `http(s)` URLs and base64 encoded data URIs are loaded.
|
99
|
+
- `:placeholder`: If an image is not supported, this text/callable is rendered instead. Defaults to '[unsupported image]'.
|
100
|
+
- `:iframe`
|
101
|
+
- `:placeholder`: If the HTML contains IFrames, this text/callable is rendered instead.
|
102
|
+
A callable gets the URL of the IFrame as an argument. Defaults to ignore iframes.
|
103
|
+
- `:input`
|
104
|
+
- `:symbol_font`: A special font to print checkboxes and radios. Prawn's standard fonts do not support special unicode characters. Do not forget to update the document's `font_families`.
|
105
|
+
- `:symbol_font_size`: The size of the special font to print checkboxes and radios.
|
106
|
+
- `:checkbox`
|
107
|
+
- `:checked`: The char to print for a checked checkbox. Default is '☑'.
|
108
|
+
- `:unchecked`: The char to print for an unchecked checkbox. Default is '☐'.
|
109
|
+
- `:radio`
|
110
|
+
- `:checked`: The char to print for a checked radio. Default is '◉'.
|
111
|
+
- `:unchecked`: The char to print for an unchecked radio. Default is '○'.
|
112
112
|
|
113
113
|
## Development
|
114
114
|
|
@@ -128,4 +128,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
128
128
|
|
129
129
|
## Code of Conduct
|
130
130
|
|
131
|
-
Everyone interacting in the Prawn::Markup project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/puzzle/prawn-markup/blob/
|
131
|
+
Everyone interacting in the Prawn::Markup project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/puzzle/prawn-markup/blob/main/CODE_OF_CONDUCT.md).
|
@@ -110,9 +110,10 @@ module Prawn
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def bullet_text_width
|
113
|
+
largest_string = bullet('0' * list.items.size.digits.size)
|
113
114
|
font = bullet_font
|
115
|
+
encoded = font.normalize_encoding(largest_string)
|
114
116
|
font_size = column_cell_style(:bullet)[:size] || pdf.font_size
|
115
|
-
encoded = font.normalize_encoding(bullet(list.items.size))
|
116
117
|
font.compute_width_of(encoded, size: font_size)
|
117
118
|
end
|
118
119
|
|
@@ -34,10 +34,12 @@ module Prawn
|
|
34
34
|
hash.dup.tap do |image_hash|
|
35
35
|
image_hash.delete(:width)
|
36
36
|
image_hash[:image_width] = SizeConverter.new(max_width).parse(hash[:width])
|
37
|
-
|
38
|
-
|
39
|
-
image_hash[:fit] = [max_width, 999_999]
|
37
|
+
natural_width, _height = natural_image_dimensions(image_hash)
|
38
|
+
if max_width && (max_width < natural_width)
|
39
|
+
image_hash[:fit] = [max_width, 999_999]
|
40
40
|
end
|
41
|
+
rescue Prawn::Errors::UnsupportedImageType
|
42
|
+
image_hash.clear
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
@@ -57,10 +57,14 @@ module Prawn
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def load_image(src)
|
60
|
+
custom_load_image(src) ||
|
61
|
+
decode_base64_image(src) ||
|
62
|
+
load_remote_image(src)
|
63
|
+
end
|
64
|
+
|
65
|
+
def custom_load_image(src)
|
60
66
|
if options[:image] && options[:image][:loader]
|
61
67
|
options[:image][:loader].call(src)
|
62
|
-
else
|
63
|
-
decode_base64_image(src) || load_remote_image(src)
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
@@ -125,7 +125,11 @@ module Prawn
|
|
125
125
|
def style_properties
|
126
126
|
style = current_attrs['style']
|
127
127
|
if style
|
128
|
-
style
|
128
|
+
style
|
129
|
+
.split(';')
|
130
|
+
.map { |p| p.split(':', 2).map(&:strip) }
|
131
|
+
.select { |tuple| tuple.size == 2 }
|
132
|
+
.to_h
|
129
133
|
else
|
130
134
|
{}
|
131
135
|
end
|
data/lib/prawn/markup/version.rb
CHANGED
data/prawn-markup.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.add_development_dependency 'bundler'
|
31
31
|
spec.add_development_dependency 'byebug'
|
32
|
+
spec.add_development_dependency 'matrix'
|
32
33
|
spec.add_development_dependency 'pdf-inspector'
|
33
34
|
spec.add_development_dependency 'rake'
|
34
35
|
spec.add_development_dependency 'rspec'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn-markup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pascal Zumkehr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: matrix
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: pdf-inspector
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -202,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
216
|
- !ruby/object:Gem::Version
|
203
217
|
version: '0'
|
204
218
|
requirements: []
|
205
|
-
rubygems_version: 3.
|
219
|
+
rubygems_version: 3.3.26
|
206
220
|
signing_key:
|
207
221
|
specification_version: 4
|
208
222
|
summary: Parse simple HTML markup to include in Prawn PDFs
|