prawn-markup 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bf5359f2a3cd6a08af1cb55a8f698a0ff16105d27a8de7c1e747f9f2ea521a1
4
- data.tar.gz: 3bd829e28c2bc4bc079834a9b0a21eb7d93ce57cfd3d511f2e511f2c8bd0cd4a
3
+ metadata.gz: 7d7d7fba33e7e87da6a9b6828a8dfdd0ea40be83eaf4564744f4b20e766a85b2
4
+ data.tar.gz: 2e7fdf53d140797d993f651320728ff42755371294c5fd501f2716f52111b443
5
5
  SHA512:
6
- metadata.gz: b0e6c543856fb3fdd86e9d873b093faec9ac91049489512dc16cbc23fee6f77a33b7eff48d152fda4f0d4dd4d12374de05efed01a4e295cf1adccc42a7699280
7
- data.tar.gz: b5a02c1fa07ad2b2326e981f41b551d7f57b033ac196e94798f9d3250ed9ba76dd889709b77838c0eb8feebb5d7034309a03548ce5b0773d8c04d4c61103d335
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](http://prawnpdf.org/api-docs/2.0/Prawn/Text.html#text-instance_method) method: `font`, `size`, `color`, `style`, `align`, `valign`, `leading`,`direction`, `character_spacing`, `indent_paragraphs`, `kerning`, `mode`.
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
 
@@ -27,7 +27,7 @@ module Prawn
27
27
  end
28
28
 
29
29
  def text_options
30
- (options[:text] || {})
30
+ options[:text] || {}
31
31
  end
32
32
 
33
33
  def compute_image_width(hash, max_width)
@@ -133,7 +133,7 @@ module Prawn
133
133
  if width.nil? && total_width
134
134
  width = total_width - column_width_sum - ((columns_without_width - 1) * MIN_COL_WIDTH)
135
135
  end
136
- super(node, width, style_options)
136
+ super
137
137
  end
138
138
 
139
139
  def compute_column_widths
@@ -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
- unless text.empty?
67
- add_bottom_margin
68
- add_formatted_text(text, text_options)
69
- put_bottom_margin(text_margin_bottom)
70
- end
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
- append_text("<color c=\"#{c}\" m=\"#{m}\" y=\"#{y}\" k=\"#{k}\">")
100
+ append_color_tag([c, m, y, k])
86
101
  else
87
- append_text("<color rgb=\"#{rgb}\">")
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) { |ctx| ctx.recovery = true }
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 = [])
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Prawn
4
4
  module Markup
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
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.0.0
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: 2023-06-14 00:00:00.000000000 Z
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.3.26
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