webtranslateit-hpricot 1.0.0 → 1.0.1

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: 23b27a1746fc1bbaf18618228aa7355bb333c6b6b7bef6ba3baa228c096307bc
4
- data.tar.gz: 79c391d5c90b510b969557372e9c944fca144b3bc42241908f894ed20dcbea70
3
+ metadata.gz: c9e0fe82d6e535d851172d7b897f527ed83ad9e57e600bd5af6637cdac73b2d4
4
+ data.tar.gz: 91a84b8ceea81a0d204cac790a00ba6cae9f453dcd3a9360059f7cafd4e7f6f2
5
5
  SHA512:
6
- metadata.gz: 269e7a6e9f389c3045a5ee1f5eb824a5e99db52896b60b210d55ae51b66ac5894cebb2b3926837c3303ee6aec841289730f7e9e0ebfd653e06e94ecc0355f9ab
7
- data.tar.gz: f0ac2d5cb9d96a7d2929e73d2ca94236fa067f1bd13832fb636eaad4638e73cac614f25ee5891cdf6bc8153545a8efea032994437adc7f065a41376e32ef1e96
6
+ metadata.gz: d45f0c8e2cb8fb1926e761ade66fb939da8574608d5e00a6929b29001f902fe37b8a59b159708fb6dfaf194538298d242a7454e719902b85350fa7af54e6dd8c
7
+ data.tar.gz: 3609483dd4ee0e5e3366d09c15b800b4f6fc09cbcee8f59ad3b00d290c70f68d0456bb26211bdc9764dd721c0ea9107f14cfb552385f3288a5f3d0432b7e97e6
data/CHANGELOG CHANGED
@@ -1,3 +1,21 @@
1
+ = 1.0.1
2
+ === 9 September 2026
3
+
4
+ * Added a :void_elements parse option, naming which tag names are void instead
5
+ of taking HTML's whole list the way :html_void does. Void-ness belongs to the
6
+ document type rather than to the tag name: an XML vocabulary is free to reuse
7
+ a name HTML treats as void and mean a container by it. TYPO3's locallang XML
8
+ has a <meta> holding <type> and <description>, and html_void: true drops both
9
+ its children and its end tag. void_elements: %w[br] gives such a document the
10
+ one tag it needs and leaves every other name an ordinary element.
11
+
12
+ The set is matched exactly, since XML is case sensitive and this option is for
13
+ XML mode. A String or Symbol is accepted as a one-element set. An explicit
14
+ empty list means no element is void, and an explicit set overrides
15
+ :html_void, so a caller can narrow the list without restating it as a
16
+ negation. Serialization is unchanged: a void element is still written the way
17
+ the source wrote it, and HTML mode is untouched.
18
+
1
19
  = 1.0.0
2
20
  === 9 September 2026
3
21
 
data/hpricot.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'webtranslateit-hpricot'
3
- s.version = '1.0.0'
3
+ s.version = '1.0.1'
4
4
 
5
5
  s.authors = ['why the lucky stiff', 'WebTranslateIt']
6
6
  s.email = 'support@webtranslateit.com'
@@ -17,13 +17,15 @@ module Hpricot
17
17
  # * Every byte of the input appears in exactly one token's `raw`.
18
18
  # * Attribute values are stored undecoded.
19
19
  class Scanner
20
- def initialize(source, xml: false, fixup_tags: false, xhtml_strict: false, html_void: false)
20
+ def initialize(source, xml: false, fixup_tags: false, xhtml_strict: false, html_void: false,
21
+ void_elements: nil)
21
22
  @xml = xml
22
23
  @fixup_tags = fixup_tags
23
24
  @xhtml_strict = xhtml_strict
24
25
  # Consumed by TreeBuilder; accepted here so Hpricot.scan can pass one
25
26
  # option hash to both.
26
27
  @html_void = html_void
28
+ @void_elements = void_elements
27
29
 
28
30
  # Lowest position from which no '>' (respectively ']') remains in the
29
31
  # document. Both start unknown. See gt_ahead?.
@@ -9,10 +9,15 @@ module Hpricot
9
9
  # implicit closing driven by ElementContent (see #close_implied), matching
10
10
  # ext/hpricot_scan/hpricot_scan.rl:316-400.
11
11
  class TreeBuilder
12
- def initialize(tokens, xml: false, fixup_tags: false, xhtml_strict: false, html_void: false)
12
+ def initialize(tokens, xml: false, fixup_tags: false, xhtml_strict: false, html_void: false,
13
+ void_elements: nil)
13
14
  @tokens = tokens
14
15
  @xml = xml
15
- @html_void = html_void
16
+ # Which tag names are void in XML mode, or nil for none (ordinary XML).
17
+ # :void_elements names the set outright; :html_void is shorthand for
18
+ # HTML's own list. An explicit set wins, so a caller can narrow the list
19
+ # without restating it as a negation.
20
+ @void_tags = void_elements || (html_void ? VOID_TAGS : nil)
16
21
  @fixup_tags = fixup_tags
17
22
  @xhtml_strict = xhtml_strict
18
23
  end
@@ -170,7 +175,15 @@ module Hpricot
170
175
  # XHTML way, with a self-closing slash". HTML mode keeps :EMPTY and so
171
176
  # keeps emitting '<br />'; html_void writes '<br>' as the source did,
172
177
  # which matters when the element sits inside translatable text.
173
- e.allowed = :VOID if @html_void && VOID_TAGS[tok.name]
178
+ #
179
+ # void_elements names the set instead of taking HTML's whole list,
180
+ # because void-ness belongs to the document type rather than to the tag
181
+ # name. An XML vocabulary is free to reuse a name HTML happens to treat
182
+ # as void and mean a container by it -- TYPO3's locallang XML has a
183
+ # <meta> holding <type> and <description> -- and applying HTML's list
184
+ # there drops the children and the end tag. Such a caller asks for the
185
+ # one or two names it actually needs, typically %w[br].
186
+ e.allowed = :VOID if @void_tags&.key?(tok.name)
174
187
  else
175
188
  e.allowed = ElementContent[tok.name]
176
189
  end
data/lib/hpricot.rb CHANGED
@@ -57,9 +57,26 @@ module Hpricot
57
57
  kw = { xml: !!opts[:xml],
58
58
  fixup_tags: !!opts[:fixup_tags],
59
59
  xhtml_strict: !!opts[:xhtml_strict],
60
- html_void: !!opts[:html_void] }
60
+ html_void: !!opts[:html_void],
61
+ void_elements: void_element_set(opts[:void_elements]) }
61
62
  doc = TreeBuilder.new(Scanner.new(source, **kw).tokens, **kw).document
62
63
  doc.instance_variable_set(:@options, opts)
63
64
  doc
64
65
  end
66
+
67
+ # Normalises the :void_elements option into a name => true lookup.
68
+ #
69
+ # nil means the option was not given, and TreeBuilder falls back to
70
+ # :html_void. An explicit empty list is a different statement -- "no element
71
+ # is void" -- so it normalises to an empty Hash, which is truthy and
72
+ # therefore overrides :html_void the way any other explicit set does.
73
+ #
74
+ # Names are matched exactly. XML is case sensitive, and this option exists
75
+ # for XML mode, so a set naming 'br' does not cover '<BR>'.
76
+ def self.void_element_set(names)
77
+ return nil if names.nil?
78
+
79
+ Array(names).each_with_object({}) { |name, set| set[name.to_s] = true }.freeze
80
+ end
81
+ private_class_method :void_element_set
65
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webtranslateit-hpricot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - why the lucky stiff