prawn-html 0.4.0 → 0.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4dec0bd9a3746705bdaca34d49c8a8eff5700fd8a5feebc3b3452001cd239b0b
4
- data.tar.gz: 74b5e31d3056560435ea939f50f713f11c44ad4c1f584873203b910754e1f782
3
+ metadata.gz: 3eec6595a60748790725f32e92e7b749d92086e5331d8a572d287a3a90f9d83a
4
+ data.tar.gz: 89bcbe740f84c4ecdea2877e96d0f677a25bf424325b41fa40caf3d1351fba96
5
5
  SHA512:
6
- metadata.gz: 814c481a5fce1da43dcb04254ed97f76f234fbdcaa6826070b00594f80cd3b4396c190a2972c0f6f72e00d35e5fd1b534cf22c9ef932b8ee308562de7c6bc854
7
- data.tar.gz: f99ce1543d1b28689b19ceddd8e86a73fae8e204bc98270e6a422dd93e44d89ff50366969b67e0fb2a9a4e91d03367981ab5c0f9481b91378df57e2304358f40
6
+ metadata.gz: 9b34f31b07aaac30910fd1bcb2118b9cbe92bbdaf4ac80850520887e7c3803a6bb1217764551baeeb1a88d695d7b26c4885a4d3065bbd1f20527d37a5723c7bf
7
+ data.tar.gz: 6ed594bd070e4e4cf20519c28094f7d57eeb779f60c4867f380aab22946d20401bac307e17db47c0560b2cf1cdc591d80e07c3ff54999db92bd3040e19cc18d7
data/README.md CHANGED
@@ -41,6 +41,7 @@ HTML tags:
41
41
  - **b**: bold
42
42
  - **blockquote**: block quotation element
43
43
  - **br**: new line
44
+ - **code**: inline code element
44
45
  - **del**: strike-through
45
46
  - **div**: block element
46
47
  - **em**: italic
@@ -53,10 +54,13 @@ HTML tags:
53
54
  - **mark**: highlight
54
55
  - **ol**: ordered list
55
56
  - **p**: block element
57
+ - **pre**: preformatted text element
56
58
  - **s**: strike-through
57
59
  - **small**: smaller text
58
60
  - **span**: inline element
59
61
  - **strong**: bold
62
+ - **sub**: subscript element
63
+ - **sup**: superscript element
60
64
  - **u**: underline
61
65
  - **ul**: unordered list
62
66
 
@@ -10,7 +10,7 @@ module PrawnHtml
10
10
  block: %i[align leading left margin_left padding_left position top],
11
11
  tag_close: %i[margin_bottom padding_bottom break_after],
12
12
  tag_open: %i[margin_top padding_top break_before],
13
- text_node: %i[background callback character_spacing color font link list_style_type size styles]
13
+ text_node: %i[background callback character_spacing color font link list_style_type size styles white_space]
14
14
  }.freeze
15
15
 
16
16
  STYLES_LIST = {
@@ -26,6 +26,8 @@ module PrawnHtml
26
26
  'letter-spacing' => { key: :character_spacing, set: :convert_float },
27
27
  'list-style-type' => { key: :list_style_type, set: :unquote },
28
28
  'text-decoration' => { key: :styles, set: :append_styles },
29
+ 'vertical-align' => { key: :styles, set: :append_styles },
30
+ 'white-space' => { key: :white_space, set: :convert_symbol },
29
31
  # tag opening styles
30
32
  'break-before' => { key: :break_before, set: :convert_symbol },
31
33
  'margin-top' => { key: :margin_top, set: :convert_size },
@@ -48,9 +48,7 @@ module PrawnHtml
48
48
  def on_text_node(content)
49
49
  return if content.match?(/\A\s*\Z/)
50
50
 
51
- text = ::Oga::HTML::Entities.decode(context.before_content)
52
- text += content.gsub(/\A\s*\n\s*|\s*\n\s*\Z/, '').delete("\n").squeeze(' ')
53
- buffer << context.text_node_styles.merge(text: text)
51
+ buffer << context.text_node_styles.merge(text: prepare_text(content))
54
52
  context.last_text_node = true
55
53
  nil
56
54
  end
@@ -103,6 +101,13 @@ module PrawnHtml
103
101
  pdf.start_new_page if tag_styles[:break_before]
104
102
  end
105
103
 
104
+ def prepare_text(content)
105
+ white_space_pre = context.last && context.last.styles[:white_space] == :pre
106
+ text = ::Oga::HTML::Entities.decode(context.before_content)
107
+ text += white_space_pre ? content : content.gsub(/\A\s*\n\s*|\s*\n\s*\Z/, '').delete("\n").squeeze(' ')
108
+ text
109
+ end
110
+
106
111
  def output_content(buffer, block_styles)
107
112
  apply_callbacks(buffer)
108
113
  left_indent = block_styles[:margin_left].to_f + block_styles[:padding_left].to_f
@@ -6,7 +6,7 @@ module PrawnHtml
6
6
  'Highlight' => Callbacks::Highlight,
7
7
  'StrikeThrough' => Callbacks::StrikeThrough
8
8
  }.freeze
9
- TAG_CLASSES = %w[A B Blockquote Body Br Del Div H Hr I Img Li Mark Ol P Small Span U Ul].freeze
9
+ TAG_CLASSES = %w[A B Blockquote Body Br Code Del Div H Hr I Img Li Mark Ol P Pre Small Span Sub Sup U Ul].freeze
10
10
 
11
11
  attr_accessor :parent
12
12
  attr_reader :attrs, :tag
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrawnHtml
4
+ module Tags
5
+ class Code < Tag
6
+ ELEMENTS = [:code].freeze
7
+
8
+ def tag_styles
9
+ 'font-family: Courier'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrawnHtml
4
+ module Tags
5
+ class Pre < Tag
6
+ ELEMENTS = [:pre].freeze
7
+
8
+ MARGIN_BOTTOM = 14
9
+ MARGIN_TOP = 14
10
+
11
+ def block?
12
+ true
13
+ end
14
+
15
+ def tag_styles
16
+ <<~STYLES
17
+ font-family: Courier;
18
+ margin-bottom: #{MARGIN_BOTTOM}px;
19
+ margin-top: #{MARGIN_TOP}px;
20
+ white-space: pre;
21
+ STYLES
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrawnHtml
4
+ module Tags
5
+ class Sub < Tag
6
+ ELEMENTS = [:sub].freeze
7
+
8
+ def tag_styles
9
+ 'vertical-align: sub'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PrawnHtml
4
+ module Tags
5
+ class Sup < Tag
6
+ ELEMENTS = [:sup].freeze
7
+
8
+ def tag_styles
9
+ 'vertical-align: super'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,6 +5,8 @@ module PrawnHtml
5
5
  NORMALIZE_STYLES = {
6
6
  'bold' => :bold,
7
7
  'italic' => :italic,
8
+ 'sub' => :subscript,
9
+ 'super' => :superscript,
8
10
  'underline' => :underline
9
11
  }.freeze
10
12
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PrawnHtml # :nodoc:
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Roccoberton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-29 00:00:00.000000000 Z
11
+ date: 2021-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oga
@@ -60,6 +60,7 @@ files:
60
60
  - lib/prawn_html/tags/blockquote.rb
61
61
  - lib/prawn_html/tags/body.rb
62
62
  - lib/prawn_html/tags/br.rb
63
+ - lib/prawn_html/tags/code.rb
63
64
  - lib/prawn_html/tags/del.rb
64
65
  - lib/prawn_html/tags/div.rb
65
66
  - lib/prawn_html/tags/h.rb
@@ -70,8 +71,11 @@ files:
70
71
  - lib/prawn_html/tags/mark.rb
71
72
  - lib/prawn_html/tags/ol.rb
72
73
  - lib/prawn_html/tags/p.rb
74
+ - lib/prawn_html/tags/pre.rb
73
75
  - lib/prawn_html/tags/small.rb
74
76
  - lib/prawn_html/tags/span.rb
77
+ - lib/prawn_html/tags/sub.rb
78
+ - lib/prawn_html/tags/sup.rb
75
79
  - lib/prawn_html/tags/u.rb
76
80
  - lib/prawn_html/tags/ul.rb
77
81
  - lib/prawn_html/utils.rb