nokogiri 1.12.5 → 1.14.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +41 -0
- data/LICENSE-DEPENDENCIES.md +830 -509
- data/LICENSE.md +1 -1
- data/README.md +23 -14
- data/bin/nokogiri +63 -50
- data/dependencies.yml +33 -66
- data/ext/nokogiri/extconf.rb +159 -63
- data/ext/nokogiri/gumbo.c +21 -11
- data/ext/nokogiri/html4_document.c +2 -2
- data/ext/nokogiri/html4_element_description.c +1 -1
- data/ext/nokogiri/html4_entity_lookup.c +2 -2
- data/ext/nokogiri/html4_sax_parser_context.c +3 -9
- data/ext/nokogiri/html4_sax_push_parser.c +1 -1
- data/ext/nokogiri/nokogiri.c +38 -51
- data/ext/nokogiri/nokogiri.h +26 -14
- data/ext/nokogiri/test_global_handlers.c +1 -1
- data/ext/nokogiri/xml_attr.c +3 -3
- data/ext/nokogiri/xml_attribute_decl.c +5 -5
- data/ext/nokogiri/xml_cdata.c +3 -3
- data/ext/nokogiri/xml_comment.c +1 -1
- data/ext/nokogiri/xml_document.c +53 -44
- data/ext/nokogiri/xml_document_fragment.c +1 -3
- data/ext/nokogiri/xml_dtd.c +11 -11
- data/ext/nokogiri/xml_element_content.c +3 -3
- data/ext/nokogiri/xml_element_decl.c +5 -5
- data/ext/nokogiri/xml_encoding_handler.c +28 -14
- data/ext/nokogiri/xml_entity_decl.c +6 -6
- data/ext/nokogiri/xml_entity_reference.c +1 -1
- data/ext/nokogiri/xml_namespace.c +80 -14
- data/ext/nokogiri/xml_node.c +982 -396
- data/ext/nokogiri/xml_node_set.c +4 -6
- data/ext/nokogiri/xml_processing_instruction.c +1 -1
- data/ext/nokogiri/xml_reader.c +133 -32
- data/ext/nokogiri/xml_relax_ng.c +1 -3
- data/ext/nokogiri/xml_sax_parser.c +23 -17
- data/ext/nokogiri/xml_sax_parser_context.c +11 -9
- data/ext/nokogiri/xml_sax_push_parser.c +1 -3
- data/ext/nokogiri/xml_schema.c +4 -6
- data/ext/nokogiri/xml_syntax_error.c +1 -1
- data/ext/nokogiri/xml_text.c +2 -2
- data/ext/nokogiri/xml_xpath_context.c +144 -114
- data/ext/nokogiri/xslt_stylesheet.c +122 -23
- data/gumbo-parser/Makefile +10 -0
- data/gumbo-parser/src/attribute.h +1 -1
- data/gumbo-parser/src/error.c +2 -2
- data/gumbo-parser/src/error.h +1 -1
- data/gumbo-parser/src/foreign_attrs.c +2 -2
- data/gumbo-parser/src/{gumbo.h → nokogiri_gumbo.h} +1 -0
- data/gumbo-parser/src/parser.c +8 -16
- data/gumbo-parser/src/replacement.h +1 -1
- data/gumbo-parser/src/string_buffer.h +1 -1
- data/gumbo-parser/src/string_piece.c +1 -1
- data/gumbo-parser/src/svg_attrs.c +2 -2
- data/gumbo-parser/src/svg_tags.c +2 -2
- data/gumbo-parser/src/tag.c +2 -1
- data/gumbo-parser/src/tag_lookup.c +7 -7
- data/gumbo-parser/src/tag_lookup.gperf +1 -0
- data/gumbo-parser/src/tag_lookup.h +1 -1
- data/gumbo-parser/src/token_buffer.h +1 -1
- data/gumbo-parser/src/tokenizer.c +1 -1
- data/gumbo-parser/src/tokenizer.h +1 -1
- data/gumbo-parser/src/utf8.c +1 -1
- data/gumbo-parser/src/utf8.h +1 -1
- data/gumbo-parser/src/util.c +1 -3
- data/gumbo-parser/src/util.h +4 -0
- data/gumbo-parser/src/vector.h +1 -1
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +9 -8
- data/lib/nokogiri/css/parser.rb +360 -341
- data/lib/nokogiri/css/parser.y +249 -244
- data/lib/nokogiri/css/parser_extras.rb +22 -20
- data/lib/nokogiri/css/syntax_error.rb +1 -0
- data/lib/nokogiri/css/tokenizer.rb +4 -3
- data/lib/nokogiri/css/tokenizer.rex +3 -2
- data/lib/nokogiri/css/xpath_visitor.rb +184 -85
- data/lib/nokogiri/css.rb +44 -6
- data/lib/nokogiri/decorators/slop.rb +8 -7
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +4 -3
- data/lib/nokogiri/gumbo.rb +1 -0
- data/lib/nokogiri/html.rb +16 -10
- data/lib/nokogiri/html4/builder.rb +1 -0
- data/lib/nokogiri/html4/document.rb +56 -164
- data/lib/nokogiri/html4/document_fragment.rb +11 -7
- data/lib/nokogiri/html4/element_description.rb +1 -0
- data/lib/nokogiri/html4/element_description_defaults.rb +432 -532
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/html4/entity_lookup.rb +2 -1
- data/lib/nokogiri/html4/sax/parser.rb +5 -2
- data/lib/nokogiri/html4/sax/parser_context.rb +1 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +7 -7
- data/lib/nokogiri/html4.rb +12 -5
- data/lib/nokogiri/html5/document.rb +126 -32
- data/lib/nokogiri/html5/document_fragment.rb +14 -4
- data/lib/nokogiri/html5/node.rb +12 -7
- data/lib/nokogiri/html5.rb +138 -222
- data/lib/nokogiri/jruby/dependencies.rb +2 -19
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/syntax_error.rb +1 -0
- data/lib/nokogiri/version/constant.rb +2 -1
- data/lib/nokogiri/version/info.rb +32 -24
- data/lib/nokogiri/version.rb +1 -0
- data/lib/nokogiri/xml/attr.rb +54 -3
- data/lib/nokogiri/xml/attribute_decl.rb +2 -1
- data/lib/nokogiri/xml/builder.rb +35 -33
- data/lib/nokogiri/xml/cdata.rb +2 -1
- data/lib/nokogiri/xml/character_data.rb +1 -0
- data/lib/nokogiri/xml/document.rb +232 -143
- data/lib/nokogiri/xml/document_fragment.rb +88 -42
- data/lib/nokogiri/xml/dtd.rb +3 -2
- data/lib/nokogiri/xml/element_content.rb +1 -0
- data/lib/nokogiri/xml/element_decl.rb +2 -1
- data/lib/nokogiri/xml/entity_decl.rb +3 -2
- data/lib/nokogiri/xml/entity_reference.rb +1 -0
- data/lib/nokogiri/xml/namespace.rb +44 -0
- data/lib/nokogiri/xml/node/save_options.rb +14 -8
- data/lib/nokogiri/xml/node.rb +708 -383
- data/lib/nokogiri/xml/node_set.rb +134 -59
- data/lib/nokogiri/xml/notation.rb +12 -0
- data/lib/nokogiri/xml/parse_options.rb +140 -56
- data/lib/nokogiri/xml/pp/character_data.rb +8 -6
- data/lib/nokogiri/xml/pp/node.rb +26 -26
- data/lib/nokogiri/xml/pp.rb +1 -0
- data/lib/nokogiri/xml/processing_instruction.rb +3 -1
- data/lib/nokogiri/xml/reader.rb +20 -24
- data/lib/nokogiri/xml/relax_ng.rb +1 -0
- data/lib/nokogiri/xml/sax/document.rb +20 -19
- data/lib/nokogiri/xml/sax/parser.rb +38 -36
- data/lib/nokogiri/xml/sax/parser_context.rb +7 -3
- data/lib/nokogiri/xml/sax/push_parser.rb +5 -5
- data/lib/nokogiri/xml/sax.rb +1 -0
- data/lib/nokogiri/xml/schema.rb +7 -6
- data/lib/nokogiri/xml/searchable.rb +93 -62
- data/lib/nokogiri/xml/syntax_error.rb +5 -4
- data/lib/nokogiri/xml/text.rb +1 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +2 -1
- data/lib/nokogiri/xml/xpath.rb +12 -0
- data/lib/nokogiri/xml/xpath_context.rb +2 -3
- data/lib/nokogiri/xml.rb +4 -3
- data/lib/nokogiri/xslt/stylesheet.rb +1 -0
- data/lib/nokogiri/xslt.rb +21 -13
- data/lib/nokogiri.rb +22 -27
- data/lib/xsd/xmlparser/nokogiri.rb +28 -25
- data/patches/libxml2/0009-allow-wildcard-namespaces.patch +77 -0
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2445 -1919
- data/ports/archives/libxml2-2.10.4.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.37.tar.xz +0 -0
- metadata +20 -171
- data/patches/libxml2/0004-use-glibc-strlen.patch +0 -53
- data/patches/libxml2/0005-avoid-isnan-isinf.patch +0 -81
- data/patches/libxml2/0006-update-automake-files-for-arm64.patch +0 -2511
- data/patches/libxml2/0007-Fix-XPath-recursion-limit.patch +0 -31
- data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +0 -19
- data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
- data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
@@ -1,28 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
# frozen_string_literal: true
|
3
|
+
|
2
4
|
module Nokogiri
|
3
5
|
module XML
|
4
6
|
class DocumentFragment < Nokogiri::XML::Node
|
7
|
+
####
|
8
|
+
# Create a Nokogiri::XML::DocumentFragment from +tags+
|
9
|
+
def self.parse(tags, options = ParseOptions::DEFAULT_XML, &block)
|
10
|
+
new(XML::Document.new, tags, nil, options, &block)
|
11
|
+
end
|
12
|
+
|
5
13
|
##
|
6
14
|
# Create a new DocumentFragment from +tags+.
|
7
15
|
#
|
8
16
|
# If +ctx+ is present, it is used as a context node for the
|
9
17
|
# subtree created, e.g., namespaces will be resolved relative
|
10
18
|
# to +ctx+.
|
11
|
-
def initialize
|
19
|
+
def initialize(document, tags = nil, ctx = nil, options = ParseOptions::DEFAULT_XML)
|
12
20
|
return self unless tags
|
13
21
|
|
22
|
+
options = Nokogiri::XML::ParseOptions.new(options) if Integer === options
|
23
|
+
yield options if block_given?
|
24
|
+
|
14
25
|
children = if ctx
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
# Fix for issue#490
|
27
|
+
if Nokogiri.jruby?
|
28
|
+
# fix for issue #770
|
29
|
+
ctx.parse("<root #{namespace_declarations(ctx)}>#{tags}</root>", options).children
|
30
|
+
else
|
31
|
+
ctx.parse(tags, options)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
wrapper_doc = XML::Document.parse("<root>#{tags}</root>", nil, nil, options)
|
35
|
+
self.errors = wrapper_doc.errors
|
36
|
+
wrapper_doc.xpath("/root/node()")
|
37
|
+
end
|
26
38
|
children.each { |child| child.parent = self }
|
27
39
|
end
|
28
40
|
|
@@ -40,7 +52,7 @@ module Nokogiri
|
|
40
52
|
###
|
41
53
|
# return the name for DocumentFragment
|
42
54
|
def name
|
43
|
-
|
55
|
+
"#document-fragment"
|
44
56
|
end
|
45
57
|
|
46
58
|
###
|
@@ -52,12 +64,10 @@ module Nokogiri
|
|
52
64
|
###
|
53
65
|
# Convert this DocumentFragment to html
|
54
66
|
# See Nokogiri::XML::NodeSet#to_html
|
55
|
-
def to_html
|
67
|
+
def to_html(*args)
|
56
68
|
if Nokogiri.jruby?
|
57
69
|
options = args.first.is_a?(Hash) ? args.shift : {}
|
58
|
-
|
59
|
-
options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
|
60
|
-
end
|
70
|
+
options[:save_with] ||= Node::SaveOptions::DEFAULT_HTML
|
61
71
|
args.insert(0, options)
|
62
72
|
end
|
63
73
|
children.to_html(*args)
|
@@ -66,12 +76,10 @@ module Nokogiri
|
|
66
76
|
###
|
67
77
|
# Convert this DocumentFragment to xhtml
|
68
78
|
# See Nokogiri::XML::NodeSet#to_xhtml
|
69
|
-
def to_xhtml
|
79
|
+
def to_xhtml(*args)
|
70
80
|
if Nokogiri.jruby?
|
71
81
|
options = args.first.is_a?(Hash) ? args.shift : {}
|
72
|
-
|
73
|
-
options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_XHTML
|
74
|
-
end
|
82
|
+
options[:save_with] ||= Node::SaveOptions::DEFAULT_XHTML
|
75
83
|
args.insert(0, options)
|
76
84
|
end
|
77
85
|
children.to_xhtml(*args)
|
@@ -80,7 +88,7 @@ module Nokogiri
|
|
80
88
|
###
|
81
89
|
# Convert this DocumentFragment to xml
|
82
90
|
# See Nokogiri::XML::NodeSet#to_xml
|
83
|
-
def to_xml
|
91
|
+
def to_xml(*args)
|
84
92
|
children.to_xml(*args)
|
85
93
|
end
|
86
94
|
|
@@ -91,7 +99,7 @@ module Nokogiri
|
|
91
99
|
# selectors. For example:
|
92
100
|
#
|
93
101
|
# For more information see Nokogiri::XML::Searchable#css
|
94
|
-
def css
|
102
|
+
def css(*args)
|
95
103
|
if children.any?
|
96
104
|
children.css(*args) # 'children' is a smell here
|
97
105
|
else
|
@@ -110,34 +118,26 @@ module Nokogiri
|
|
110
118
|
# Search this fragment for +paths+. +paths+ must be one or more XPath or CSS queries.
|
111
119
|
#
|
112
120
|
# For more information see Nokogiri::XML::Searchable#search
|
113
|
-
def search
|
121
|
+
def search(*rules)
|
114
122
|
rules, handler, ns, binds = extract_params(rules)
|
115
123
|
|
116
124
|
rules.inject(NodeSet.new(document)) do |set, rule|
|
117
|
-
set
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
125
|
+
set + if Searchable::LOOKS_LIKE_XPATH.match?(rule)
|
126
|
+
xpath(*[rule, ns, handler, binds].compact)
|
127
|
+
else
|
128
|
+
children.css(*[rule, ns, handler].compact) # 'children' is a smell here
|
129
|
+
end
|
122
130
|
end
|
123
131
|
end
|
124
132
|
|
125
|
-
|
126
|
-
|
127
|
-
class << self
|
128
|
-
####
|
129
|
-
# Create a Nokogiri::XML::DocumentFragment from +tags+
|
130
|
-
def parse tags
|
131
|
-
self.new(XML::Document.new, tags)
|
132
|
-
end
|
133
|
-
end
|
133
|
+
alias_method :serialize, :to_s
|
134
134
|
|
135
135
|
# A list of Nokogiri::XML::SyntaxError found when parsing a document
|
136
136
|
def errors
|
137
137
|
document.errors
|
138
138
|
end
|
139
139
|
|
140
|
-
def errors=
|
140
|
+
def errors=(things) # :nodoc:
|
141
141
|
document.errors = things
|
142
142
|
end
|
143
143
|
|
@@ -145,14 +145,60 @@ module Nokogiri
|
|
145
145
|
document.fragment(data)
|
146
146
|
end
|
147
147
|
|
148
|
+
#
|
149
|
+
# :call-seq: deconstruct() → Array
|
150
|
+
#
|
151
|
+
# Returns the root nodes of this document fragment as an array, to use in pattern matching.
|
152
|
+
#
|
153
|
+
# 💡 Note that text nodes are returned as well as elements. If you wish to operate only on
|
154
|
+
# root elements, you should deconstruct the array returned by
|
155
|
+
# <tt>DocumentFragment#elements</tt>.
|
156
|
+
#
|
157
|
+
# ⚡ This is an experimental feature, available since v1.14.0
|
158
|
+
#
|
159
|
+
# *Example*
|
160
|
+
#
|
161
|
+
# frag = Nokogiri::HTML5.fragment(<<~HTML)
|
162
|
+
# <div>Start</div>
|
163
|
+
# This is a <a href="#jump">shortcut</a> for you.
|
164
|
+
# <div>End</div>
|
165
|
+
# HTML
|
166
|
+
#
|
167
|
+
# frag.deconstruct
|
168
|
+
# # => [#(Element:0x35c { name = "div", children = [ #(Text "Start")] }),
|
169
|
+
# # #(Text "\n" + "This is a "),
|
170
|
+
# # #(Element:0x370 {
|
171
|
+
# # name = "a",
|
172
|
+
# # attributes = [ #(Attr:0x384 { name = "href", value = "#jump" })],
|
173
|
+
# # children = [ #(Text "shortcut")]
|
174
|
+
# # }),
|
175
|
+
# # #(Text " for you.\n"),
|
176
|
+
# # #(Element:0x398 { name = "div", children = [ #(Text "End")] }),
|
177
|
+
# # #(Text "\n")]
|
178
|
+
#
|
179
|
+
# *Example* only the elements, not the text nodes.
|
180
|
+
#
|
181
|
+
# frag.elements.deconstruct
|
182
|
+
# # => [#(Element:0x35c { name = "div", children = [ #(Text "Start")] }),
|
183
|
+
# # #(Element:0x370 {
|
184
|
+
# # name = "a",
|
185
|
+
# # attributes = [ #(Attr:0x384 { name = "href", value = "#jump" })],
|
186
|
+
# # children = [ #(Text "shortcut")]
|
187
|
+
# # }),
|
188
|
+
# # #(Element:0x398 { name = "div", children = [ #(Text "End")] })]
|
189
|
+
#
|
190
|
+
def deconstruct
|
191
|
+
children.to_a
|
192
|
+
end
|
193
|
+
|
148
194
|
private
|
149
195
|
|
150
196
|
# fix for issue 770
|
151
|
-
def namespace_declarations
|
197
|
+
def namespace_declarations(ctx)
|
152
198
|
ctx.namespace_scopes.map do |namespace|
|
153
199
|
prefix = namespace.prefix.nil? ? "" : ":#{namespace.prefix}"
|
154
|
-
%
|
155
|
-
end.join
|
200
|
+
%{xmlns#{prefix}="#{namespace.href}"}
|
201
|
+
end.join(" ")
|
156
202
|
end
|
157
203
|
end
|
158
204
|
end
|
data/lib/nokogiri/xml/dtd.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Nokogiri
|
3
4
|
module XML
|
4
5
|
class DTD < Nokogiri::XML::Node
|
@@ -20,13 +21,13 @@ module Nokogiri
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def html_dtd?
|
23
|
-
name.casecmp(
|
24
|
+
name.casecmp("html").zero?
|
24
25
|
end
|
25
26
|
|
26
27
|
def html5_dtd?
|
27
28
|
html_dtd? &&
|
28
29
|
external_id.nil? &&
|
29
|
-
(system_id.nil? || system_id ==
|
30
|
+
(system_id.nil? || system_id == "about:legacy-compat")
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Nokogiri
|
3
4
|
module XML
|
4
5
|
class ElementDecl < Nokogiri::XML::Node
|
@@ -7,7 +8,7 @@ module Nokogiri
|
|
7
8
|
undef_method :line if method_defined?(:line)
|
8
9
|
|
9
10
|
def inspect
|
10
|
-
"#<#{self.class.name}:#{
|
11
|
+
"#<#{self.class.name}:#{format("0x%x", object_id)} #{to_s.inspect}>"
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Nokogiri
|
3
4
|
module XML
|
4
5
|
class EntityDecl < Nokogiri::XML::Node
|
@@ -8,12 +9,12 @@ module Nokogiri
|
|
8
9
|
undef_method :namespace_definitions
|
9
10
|
undef_method :line if method_defined?(:line)
|
10
11
|
|
11
|
-
def self.new
|
12
|
+
def self.new(name, doc, *args)
|
12
13
|
doc.create_entity(name, *args)
|
13
14
|
end
|
14
15
|
|
15
16
|
def inspect
|
16
|
-
"#<#{self.class.name}:#{
|
17
|
+
"#<#{self.class.name}:#{format("0x%x", object_id)} #{to_s.inspect}>"
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
@@ -1,11 +1,55 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
# frozen_string_literal: true
|
3
|
+
|
2
4
|
module Nokogiri
|
3
5
|
module XML
|
4
6
|
class Namespace
|
5
7
|
include Nokogiri::XML::PP::Node
|
6
8
|
attr_reader :document
|
7
9
|
|
10
|
+
#
|
11
|
+
# :call-seq: deconstruct_keys(array_of_names) → Hash
|
12
|
+
#
|
13
|
+
# Returns a hash describing the Namespace, to use in pattern matching.
|
14
|
+
#
|
15
|
+
# Valid keys and their values:
|
16
|
+
# - +prefix+ → (String, nil) The namespace's prefix, or +nil+ if there is no prefix (e.g., default namespace).
|
17
|
+
# - +href+ → (String) The namespace's URI
|
18
|
+
#
|
19
|
+
# ⚡ This is an experimental feature, available since v1.14.0
|
20
|
+
#
|
21
|
+
# *Example*
|
22
|
+
#
|
23
|
+
# doc = Nokogiri::XML.parse(<<~XML)
|
24
|
+
# <?xml version="1.0"?>
|
25
|
+
# <root xmlns="http://nokogiri.org/ns/default" xmlns:noko="http://nokogiri.org/ns/noko">
|
26
|
+
# <child1 foo="abc" noko:bar="def"/>
|
27
|
+
# <noko:child2 foo="qwe" noko:bar="rty"/>
|
28
|
+
# </root>
|
29
|
+
# XML
|
30
|
+
#
|
31
|
+
# doc.root.elements.first.namespace
|
32
|
+
# # => #(Namespace:0x35c { href = "http://nokogiri.org/ns/default" })
|
33
|
+
#
|
34
|
+
# doc.root.elements.first.namespace.deconstruct_keys([:prefix, :href])
|
35
|
+
# # => {:prefix=>nil, :href=>"http://nokogiri.org/ns/default"}
|
36
|
+
#
|
37
|
+
# doc.root.elements.last.namespace
|
38
|
+
# # => #(Namespace:0x370 {
|
39
|
+
# # prefix = "noko",
|
40
|
+
# # href = "http://nokogiri.org/ns/noko"
|
41
|
+
# # })
|
42
|
+
#
|
43
|
+
# doc.root.elements.last.namespace.deconstruct_keys([:prefix, :href])
|
44
|
+
# # => {:prefix=>"noko", :href=>"http://nokogiri.org/ns/noko"}
|
45
|
+
#
|
46
|
+
#
|
47
|
+
def deconstruct_keys(keys)
|
48
|
+
{ prefix: prefix, href: href }
|
49
|
+
end
|
50
|
+
|
8
51
|
private
|
52
|
+
|
9
53
|
def inspect_attributes
|
10
54
|
[:prefix, :href]
|
11
55
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Nokogiri
|
3
4
|
module XML
|
4
5
|
class Node
|
5
6
|
###
|
6
|
-
# Save options for serializing nodes
|
7
|
+
# Save options for serializing nodes.
|
8
|
+
# See the method group entitled Node@Serialization+and+Generating+Output for usage.
|
7
9
|
class SaveOptions
|
8
10
|
# Format serialized xml
|
9
11
|
FORMAT = 1
|
@@ -22,28 +24,32 @@ module Nokogiri
|
|
22
24
|
|
23
25
|
if Nokogiri.jruby?
|
24
26
|
# Save builder created document
|
25
|
-
AS_BUILDER
|
27
|
+
AS_BUILDER = 128
|
26
28
|
# the default for XML documents
|
27
29
|
DEFAULT_XML = AS_XML # https://github.com/sparklemotion/nokogiri/issues/#issue/415
|
28
30
|
# the default for HTML document
|
29
31
|
DEFAULT_HTML = NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
|
32
|
+
# the default for XHTML document
|
33
|
+
DEFAULT_XHTML = NO_DECLARATION | AS_XHTML
|
30
34
|
else
|
31
35
|
# the default for XML documents
|
32
36
|
DEFAULT_XML = FORMAT | AS_XML
|
33
37
|
# the default for HTML document
|
34
38
|
DEFAULT_HTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
|
39
|
+
# the default for XHTML document
|
40
|
+
DEFAULT_XHTML = FORMAT | NO_DECLARATION | AS_XHTML
|
35
41
|
end
|
36
|
-
# the default for XHTML document
|
37
|
-
DEFAULT_XHTML = FORMAT | NO_DECLARATION | AS_XHTML
|
38
42
|
|
39
43
|
# Integer representation of the SaveOptions
|
40
44
|
attr_reader :options
|
41
45
|
|
42
46
|
# Create a new SaveOptions object with +options+
|
43
|
-
def initialize
|
47
|
+
def initialize(options = 0)
|
48
|
+
@options = options
|
49
|
+
end
|
44
50
|
|
45
51
|
constants.each do |constant|
|
46
|
-
class_eval
|
52
|
+
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
47
53
|
def #{constant.downcase}
|
48
54
|
@options |= #{constant}
|
49
55
|
self
|
@@ -52,10 +58,10 @@ module Nokogiri
|
|
52
58
|
def #{constant.downcase}?
|
53
59
|
#{constant} & @options == #{constant}
|
54
60
|
end
|
55
|
-
|
61
|
+
RUBY
|
56
62
|
end
|
57
63
|
|
58
|
-
|
64
|
+
alias_method :to_i, :options
|
59
65
|
end
|
60
66
|
end
|
61
67
|
end
|