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 +4 -4
- data/CHANGELOG +18 -0
- data/hpricot.gemspec +1 -1
- data/lib/hpricot/scanner.rb +3 -1
- data/lib/hpricot/tree_builder.rb +16 -3
- data/lib/hpricot.rb +18 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c9e0fe82d6e535d851172d7b897f527ed83ad9e57e600bd5af6637cdac73b2d4
|
|
4
|
+
data.tar.gz: 91a84b8ceea81a0d204cac790a00ba6cae9f453dcd3a9360059f7cafd4e7f6f2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
data/lib/hpricot/scanner.rb
CHANGED
|
@@ -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?.
|
data/lib/hpricot/tree_builder.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|