prawn-markup 1.0.0 → 1.1.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 +4 -4
- data/README.md +5 -1
- data/lib/prawn/markup/builders/nestable_builder.rb +1 -1
- data/lib/prawn/markup/builders/table_builder.rb +1 -1
- data/lib/prawn/markup/processor/blocks.rb +9 -5
- data/lib/prawn/markup/processor/tables.rb +4 -0
- data/lib/prawn/markup/processor/text.rb +26 -2
- data/lib/prawn/markup/processor.rb +3 -1
- data/lib/prawn/markup/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d7d7fba33e7e87da6a9b6828a8dfdd0ea40be83eaf4564744f4b20e766a85b2
|
4
|
+
data.tar.gz: 2e7fdf53d140797d993f651320728ff42755371294c5fd501f2716f52111b443
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9f6ec2986e5e6fda0ad851689cdf6fa34d24a1b0a11656778613bd57e0937cab3dc082bd8bdc4c0e9f3713f5197010f84d5aa9ce6654cbfa6e5d7425d6c46cf
|
7
|
+
data.tar.gz: 76ae5a9dd1f544ab2164e4e4e56d805c71114b4772585dae07c532edbff92493c54e41a0a48fedc033112027e80516ba7322e2fe0e9e2a9182e3d015abf546cc
|
data/README.md
CHANGED
@@ -69,7 +69,7 @@ doc.markup('<p>Hello World</p><hr/><p>KTHXBYE</p>', text: { align: :center })
|
|
69
69
|
|
70
70
|
Options may be set for `text`, `heading[1-6]`, `table` (subkeys `cell` and `header`) and `list` (subkeys `content` and `bullet`).
|
71
71
|
|
72
|
-
Text and heading options include all keys from Prawns [#text](
|
72
|
+
Text and heading options include all keys from Prawns [#text](https://prawnpdf.org/docs/prawn/2.5.0/Prawn/Text.html#text-instance_method) method: `font`, `size`, `color`, `style`, `align`, `valign`, `leading`,`direction`, `character_spacing`, `indent_paragraphs`, `kerning`, `mode`.
|
73
73
|
|
74
74
|
Tables and lists are rendered with [prawn-table](https://github.com/prawnpdf/prawn-table) and have the following additional options: `padding`, `borders`, `border_width`, `border_color`, `background_color`, `border_lines`, `rotate`, `overflow`, `min_font_size`. Options from `text` may be overridden.
|
75
75
|
|
@@ -78,6 +78,7 @@ Beside these options handled by Prawn / prawn-table, the following values may be
|
|
78
78
|
- `:text`
|
79
79
|
- `:preprocessor`: A proc/callable that is called each time before a chunk of text is rendered.
|
80
80
|
- `:margin_bottom`: Margin after each `<p>`, `<ol>`, `<ul>` or `<table>`. Defaults to about half a line.
|
81
|
+
- `:treat_empty_paragraph_as_new_line`: Boolean flag to set a new line if paragraph is empty.
|
81
82
|
- `:heading1-6`
|
82
83
|
- `:margin_top`: Margin before a heading. Default is 0.
|
83
84
|
- `:margin_bottom`: Margin after a heading. Default is 0.
|
@@ -109,6 +110,9 @@ Beside these options handled by Prawn / prawn-table, the following values may be
|
|
109
110
|
- `:radio`
|
110
111
|
- `:checked`: The char to print for a checked radio. Default is '◉'.
|
111
112
|
- `:unchecked`: The char to print for an unchecked radio. Default is '○'.
|
113
|
+
- `:link`
|
114
|
+
- `:color`: The link color, which can be specified in either RGB hex format or 4-value CMYK.
|
115
|
+
- `:underline`: Specifies whether the link should be underlined. Default is false.
|
112
116
|
|
113
117
|
## Development
|
114
118
|
|
@@ -63,11 +63,11 @@ module Prawn
|
|
63
63
|
def add_paragraph
|
64
64
|
text = dump_text
|
65
65
|
text.gsub!(/[^\n]/, '') if text.strip.empty?
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
return if text.empty? && !treat_empty_paragraph_as_new_line?
|
67
|
+
|
68
|
+
add_bottom_margin
|
69
|
+
add_formatted_text(text.empty? ? "\n" : text, text_options)
|
70
|
+
put_bottom_margin(text_margin_bottom)
|
71
71
|
end
|
72
72
|
|
73
73
|
def add_current_text(options = text_options)
|
@@ -151,6 +151,10 @@ module Prawn
|
|
151
151
|
inline_format: true
|
152
152
|
}
|
153
153
|
end
|
154
|
+
|
155
|
+
def treat_empty_paragraph_as_new_line?
|
156
|
+
text_options[:treat_empty_paragraph_as_new_line] || false
|
157
|
+
end
|
154
158
|
end
|
155
159
|
end
|
156
160
|
end
|
@@ -86,6 +86,10 @@ module Prawn
|
|
86
86
|
def add_cell_text_node(cell, options = {})
|
87
87
|
return unless buffered_text?
|
88
88
|
|
89
|
+
# only allow on supported options of prawn-table; See https://github.com/prawnpdf/prawn-table/blob/master/manual/table/cell_text.rb
|
90
|
+
options = options.slice(*%i[font font_style inline_format kerning leading min_font_size size
|
91
|
+
overflow rotate rotate_around single_line text_color valign])
|
92
|
+
|
89
93
|
cell.nodes << options.merge(content: dump_text.strip)
|
90
94
|
end
|
91
95
|
|
@@ -11,15 +11,30 @@ module Prawn
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def start_a
|
14
|
+
start_u if link_options[:underline]
|
15
|
+
append_color_tag(link_options[:color]) if link_options[:color]
|
14
16
|
append_text("<link href=\"#{current_attrs['href']}\">")
|
15
17
|
end
|
16
18
|
alias start_link start_a
|
17
19
|
|
18
20
|
def end_a
|
19
21
|
append_text('</link>')
|
22
|
+
end_color if link_options[:color]
|
23
|
+
end_u if link_options[:underline]
|
20
24
|
end
|
21
25
|
alias end_link end_a
|
22
26
|
|
27
|
+
def link_options
|
28
|
+
@link_options ||= HashMerger.deep(default_link_options, options[:link] || {})
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_link_options
|
32
|
+
{
|
33
|
+
color: nil,
|
34
|
+
underline: false
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
23
38
|
def start_b
|
24
39
|
append_text('<b>')
|
25
40
|
end
|
@@ -82,9 +97,9 @@ module Prawn
|
|
82
97
|
rgb, c, m, y, k = current_attrs.values_at('rgb', 'c', 'm', 'y', 'k')
|
83
98
|
|
84
99
|
if [c, m, y, k].all?
|
85
|
-
|
100
|
+
append_color_tag([c, m, y, k])
|
86
101
|
else
|
87
|
-
|
102
|
+
append_color_tag(rgb)
|
88
103
|
end
|
89
104
|
end
|
90
105
|
|
@@ -103,6 +118,15 @@ module Prawn
|
|
103
118
|
def end_font
|
104
119
|
append_text('</font>')
|
105
120
|
end
|
121
|
+
|
122
|
+
def append_color_tag(color)
|
123
|
+
if color.is_a?(Array)
|
124
|
+
c, m, y, k = color
|
125
|
+
append_text("<color c=\"#{c}\" m=\"#{m}\" y=\"#{y}\" k=\"#{k}\">")
|
126
|
+
else
|
127
|
+
append_text("<color rgb=\"#{color}\">")
|
128
|
+
end
|
129
|
+
end
|
106
130
|
end
|
107
131
|
end
|
108
132
|
end
|
@@ -49,7 +49,9 @@ module Prawn
|
|
49
49
|
|
50
50
|
reset
|
51
51
|
html = Prawn::Markup::Normalizer.new(html).normalize
|
52
|
-
Nokogiri::HTML::SAX::Parser.new(self).parse(html)
|
52
|
+
Nokogiri::HTML::SAX::Parser.new(self, html.encoding&.to_s).parse(html) do |ctx|
|
53
|
+
ctx.recovery = true
|
54
|
+
end
|
53
55
|
end
|
54
56
|
|
55
57
|
def start_element(name, attrs = [])
|
data/lib/prawn/markup/version.rb
CHANGED
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: 1.
|
4
|
+
version: 1.1.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: 2025-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -216,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
216
|
- !ruby/object:Gem::Version
|
217
217
|
version: '0'
|
218
218
|
requirements: []
|
219
|
-
rubygems_version: 3.
|
219
|
+
rubygems_version: 3.4.10
|
220
220
|
signing_key:
|
221
221
|
specification_version: 4
|
222
222
|
summary: Parse simple HTML markup to include in Prawn PDFs
|