nokogiri 1.11.0.rc1-x86-linux

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.

Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-DEPENDENCIES.md +1614 -0
  3. data/LICENSE.md +9 -0
  4. data/README.md +200 -0
  5. data/bin/nokogiri +118 -0
  6. data/dependencies.yml +74 -0
  7. data/ext/nokogiri/depend +358 -0
  8. data/ext/nokogiri/extconf.rb +695 -0
  9. data/ext/nokogiri/html_document.c +170 -0
  10. data/ext/nokogiri/html_document.h +10 -0
  11. data/ext/nokogiri/html_element_description.c +279 -0
  12. data/ext/nokogiri/html_element_description.h +10 -0
  13. data/ext/nokogiri/html_entity_lookup.c +32 -0
  14. data/ext/nokogiri/html_entity_lookup.h +8 -0
  15. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  16. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  17. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  18. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  19. data/ext/nokogiri/nokogiri.c +147 -0
  20. data/ext/nokogiri/nokogiri.h +122 -0
  21. data/ext/nokogiri/xml_attr.c +103 -0
  22. data/ext/nokogiri/xml_attr.h +9 -0
  23. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  24. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  25. data/ext/nokogiri/xml_cdata.c +62 -0
  26. data/ext/nokogiri/xml_cdata.h +9 -0
  27. data/ext/nokogiri/xml_comment.c +69 -0
  28. data/ext/nokogiri/xml_comment.h +9 -0
  29. data/ext/nokogiri/xml_document.c +617 -0
  30. data/ext/nokogiri/xml_document.h +23 -0
  31. data/ext/nokogiri/xml_document_fragment.c +48 -0
  32. data/ext/nokogiri/xml_document_fragment.h +10 -0
  33. data/ext/nokogiri/xml_dtd.c +202 -0
  34. data/ext/nokogiri/xml_dtd.h +10 -0
  35. data/ext/nokogiri/xml_element_content.c +123 -0
  36. data/ext/nokogiri/xml_element_content.h +10 -0
  37. data/ext/nokogiri/xml_element_decl.c +69 -0
  38. data/ext/nokogiri/xml_element_decl.h +9 -0
  39. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  40. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  41. data/ext/nokogiri/xml_entity_decl.c +110 -0
  42. data/ext/nokogiri/xml_entity_decl.h +10 -0
  43. data/ext/nokogiri/xml_entity_reference.c +52 -0
  44. data/ext/nokogiri/xml_entity_reference.h +9 -0
  45. data/ext/nokogiri/xml_io.c +61 -0
  46. data/ext/nokogiri/xml_io.h +11 -0
  47. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  48. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  49. data/ext/nokogiri/xml_namespace.c +111 -0
  50. data/ext/nokogiri/xml_namespace.h +14 -0
  51. data/ext/nokogiri/xml_node.c +1773 -0
  52. data/ext/nokogiri/xml_node.h +13 -0
  53. data/ext/nokogiri/xml_node_set.c +486 -0
  54. data/ext/nokogiri/xml_node_set.h +12 -0
  55. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  56. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  57. data/ext/nokogiri/xml_reader.c +668 -0
  58. data/ext/nokogiri/xml_reader.h +10 -0
  59. data/ext/nokogiri/xml_relax_ng.c +161 -0
  60. data/ext/nokogiri/xml_relax_ng.h +9 -0
  61. data/ext/nokogiri/xml_sax_parser.c +310 -0
  62. data/ext/nokogiri/xml_sax_parser.h +39 -0
  63. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  64. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  65. data/ext/nokogiri/xml_sax_push_parser.c +159 -0
  66. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  67. data/ext/nokogiri/xml_schema.c +205 -0
  68. data/ext/nokogiri/xml_schema.h +9 -0
  69. data/ext/nokogiri/xml_syntax_error.c +64 -0
  70. data/ext/nokogiri/xml_syntax_error.h +13 -0
  71. data/ext/nokogiri/xml_text.c +52 -0
  72. data/ext/nokogiri/xml_text.h +9 -0
  73. data/ext/nokogiri/xml_xpath_context.c +298 -0
  74. data/ext/nokogiri/xml_xpath_context.h +10 -0
  75. data/ext/nokogiri/xslt_stylesheet.c +266 -0
  76. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  77. data/lib/nokogiri.rb +127 -0
  78. data/lib/nokogiri/2.4/nokogiri.so +0 -0
  79. data/lib/nokogiri/2.5/nokogiri.so +0 -0
  80. data/lib/nokogiri/2.6/nokogiri.so +0 -0
  81. data/lib/nokogiri/2.7/nokogiri.so +0 -0
  82. data/lib/nokogiri/css.rb +28 -0
  83. data/lib/nokogiri/css/node.rb +53 -0
  84. data/lib/nokogiri/css/parser.rb +751 -0
  85. data/lib/nokogiri/css/parser.y +272 -0
  86. data/lib/nokogiri/css/parser_extras.rb +92 -0
  87. data/lib/nokogiri/css/syntax_error.rb +8 -0
  88. data/lib/nokogiri/css/tokenizer.rb +154 -0
  89. data/lib/nokogiri/css/tokenizer.rex +55 -0
  90. data/lib/nokogiri/css/xpath_visitor.rb +232 -0
  91. data/lib/nokogiri/decorators/slop.rb +43 -0
  92. data/lib/nokogiri/html.rb +38 -0
  93. data/lib/nokogiri/html/builder.rb +36 -0
  94. data/lib/nokogiri/html/document.rb +336 -0
  95. data/lib/nokogiri/html/document_fragment.rb +50 -0
  96. data/lib/nokogiri/html/element_description.rb +24 -0
  97. data/lib/nokogiri/html/element_description_defaults.rb +672 -0
  98. data/lib/nokogiri/html/entity_lookup.rb +14 -0
  99. data/lib/nokogiri/html/sax/parser.rb +63 -0
  100. data/lib/nokogiri/html/sax/parser_context.rb +17 -0
  101. data/lib/nokogiri/html/sax/push_parser.rb +37 -0
  102. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  103. data/lib/nokogiri/syntax_error.rb +5 -0
  104. data/lib/nokogiri/version.rb +149 -0
  105. data/lib/nokogiri/xml.rb +76 -0
  106. data/lib/nokogiri/xml/attr.rb +15 -0
  107. data/lib/nokogiri/xml/attribute_decl.rb +19 -0
  108. data/lib/nokogiri/xml/builder.rb +447 -0
  109. data/lib/nokogiri/xml/cdata.rb +12 -0
  110. data/lib/nokogiri/xml/character_data.rb +8 -0
  111. data/lib/nokogiri/xml/document.rb +280 -0
  112. data/lib/nokogiri/xml/document_fragment.rb +161 -0
  113. data/lib/nokogiri/xml/dtd.rb +33 -0
  114. data/lib/nokogiri/xml/element_content.rb +37 -0
  115. data/lib/nokogiri/xml/element_decl.rb +14 -0
  116. data/lib/nokogiri/xml/entity_decl.rb +20 -0
  117. data/lib/nokogiri/xml/entity_reference.rb +19 -0
  118. data/lib/nokogiri/xml/namespace.rb +14 -0
  119. data/lib/nokogiri/xml/node.rb +916 -0
  120. data/lib/nokogiri/xml/node/save_options.rb +62 -0
  121. data/lib/nokogiri/xml/node_set.rb +372 -0
  122. data/lib/nokogiri/xml/notation.rb +7 -0
  123. data/lib/nokogiri/xml/parse_options.rb +121 -0
  124. data/lib/nokogiri/xml/pp.rb +3 -0
  125. data/lib/nokogiri/xml/pp/character_data.rb +19 -0
  126. data/lib/nokogiri/xml/pp/node.rb +57 -0
  127. data/lib/nokogiri/xml/processing_instruction.rb +9 -0
  128. data/lib/nokogiri/xml/reader.rb +116 -0
  129. data/lib/nokogiri/xml/relax_ng.rb +33 -0
  130. data/lib/nokogiri/xml/sax.rb +5 -0
  131. data/lib/nokogiri/xml/sax/document.rb +172 -0
  132. data/lib/nokogiri/xml/sax/parser.rb +123 -0
  133. data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
  134. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  135. data/lib/nokogiri/xml/schema.rb +64 -0
  136. data/lib/nokogiri/xml/searchable.rb +231 -0
  137. data/lib/nokogiri/xml/syntax_error.rb +71 -0
  138. data/lib/nokogiri/xml/text.rb +10 -0
  139. data/lib/nokogiri/xml/xpath.rb +11 -0
  140. data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
  141. data/lib/nokogiri/xml/xpath_context.rb +17 -0
  142. data/lib/nokogiri/xslt.rb +57 -0
  143. data/lib/nokogiri/xslt/stylesheet.rb +26 -0
  144. data/lib/xsd/xmlparser/nokogiri.rb +103 -0
  145. metadata +482 -0
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ class Node
5
+ ###
6
+ # Save options for serializing nodes
7
+ class SaveOptions
8
+ # Format serialized xml
9
+ FORMAT = 1
10
+ # Do not include declarations
11
+ NO_DECLARATION = 2
12
+ # Do not include empty tags
13
+ NO_EMPTY_TAGS = 4
14
+ # Do not save XHTML
15
+ NO_XHTML = 8
16
+ # Save as XHTML
17
+ AS_XHTML = 16
18
+ # Save as XML
19
+ AS_XML = 32
20
+ # Save as HTML
21
+ AS_HTML = 64
22
+
23
+ if Nokogiri.jruby?
24
+ # Save builder created document
25
+ AS_BUILDER = 128
26
+ # the default for XML documents
27
+ DEFAULT_XML = AS_XML # https://github.com/sparklemotion/nokogiri/issues/#issue/415
28
+ # the default for HTML document
29
+ DEFAULT_HTML = NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
30
+ else
31
+ # the default for XML documents
32
+ DEFAULT_XML = FORMAT | AS_XML
33
+ # the default for HTML document
34
+ DEFAULT_HTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
35
+ end
36
+ # the default for XHTML document
37
+ DEFAULT_XHTML = FORMAT | NO_DECLARATION | NO_EMPTY_TAGS | AS_XHTML
38
+
39
+ # Integer representation of the SaveOptions
40
+ attr_reader :options
41
+
42
+ # Create a new SaveOptions object with +options+
43
+ def initialize options = 0; @options = options; end
44
+
45
+ constants.each do |constant|
46
+ class_eval %{
47
+ def #{constant.downcase}
48
+ @options |= #{constant}
49
+ self
50
+ end
51
+
52
+ def #{constant.downcase}?
53
+ #{constant} & @options == #{constant}
54
+ end
55
+ }
56
+ end
57
+
58
+ alias :to_i :options
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,372 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ ####
5
+ # A NodeSet contains a list of Nokogiri::XML::Node objects. Typically
6
+ # a NodeSet is return as a result of searching a Document via
7
+ # Nokogiri::XML::Searchable#css or Nokogiri::XML::Searchable#xpath
8
+ class NodeSet
9
+ include Nokogiri::XML::Searchable
10
+ include Enumerable
11
+
12
+ # The Document this NodeSet is associated with
13
+ attr_accessor :document
14
+
15
+ alias :clone :dup
16
+
17
+ # Create a NodeSet with +document+ defaulting to +list+
18
+ def initialize document, list = []
19
+ @document = document
20
+ document.decorate(self)
21
+ list.each { |x| self << x }
22
+ yield self if block_given?
23
+ end
24
+
25
+ ###
26
+ # Get the first element of the NodeSet.
27
+ def first n = nil
28
+ return self[0] unless n
29
+ list = []
30
+ [n, length].min.times { |i| list << self[i] }
31
+ list
32
+ end
33
+
34
+ ###
35
+ # Get the last element of the NodeSet.
36
+ def last
37
+ self[-1]
38
+ end
39
+
40
+ ###
41
+ # Is this NodeSet empty?
42
+ def empty?
43
+ length == 0
44
+ end
45
+
46
+ ###
47
+ # Returns the index of the first node in self that is == to +node+ or meets the given block. Returns nil if no match is found.
48
+ def index(node = nil)
49
+ if node
50
+ warn "given block not used" if block_given?
51
+ each_with_index { |member, j| return j if member == node }
52
+ elsif block_given?
53
+ each_with_index { |member, j| return j if yield(member) }
54
+ end
55
+ nil
56
+ end
57
+
58
+ ###
59
+ # Insert +datum+ before the first Node in this NodeSet
60
+ def before datum
61
+ first.before datum
62
+ end
63
+
64
+ ###
65
+ # Insert +datum+ after the last Node in this NodeSet
66
+ def after datum
67
+ last.after datum
68
+ end
69
+
70
+ alias :<< :push
71
+ alias :remove :unlink
72
+
73
+ ###
74
+ # call-seq: css *rules, [namespace-bindings, custom-pseudo-class]
75
+ #
76
+ # Search this node set for CSS +rules+. +rules+ must be one or more CSS
77
+ # selectors. For example:
78
+ #
79
+ # For more information see Nokogiri::XML::Searchable#css
80
+ def css *args
81
+ rules, handler, ns, _ = extract_params(args)
82
+ paths = css_rules_to_xpath(rules, ns)
83
+
84
+ inject(NodeSet.new(document)) do |set, node|
85
+ set + xpath_internal(node, paths, handler, ns, nil)
86
+ end
87
+ end
88
+
89
+ ###
90
+ # call-seq: xpath *paths, [namespace-bindings, variable-bindings, custom-handler-class]
91
+ #
92
+ # Search this node set for XPath +paths+. +paths+ must be one or more XPath
93
+ # queries.
94
+ #
95
+ # For more information see Nokogiri::XML::Searchable#xpath
96
+ def xpath *args
97
+ paths, handler, ns, binds = extract_params(args)
98
+
99
+ inject(NodeSet.new(document)) do |set, node|
100
+ set + xpath_internal(node, paths, handler, ns, binds)
101
+ end
102
+ end
103
+
104
+ ###
105
+ # Search this NodeSet's nodes' immediate children using CSS selector +selector+
106
+ def > selector
107
+ ns = document.root.namespaces
108
+ xpath CSS.xpath_for(selector, :prefix => "./", :ns => ns).first
109
+ end
110
+
111
+ ###
112
+ # call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
113
+ #
114
+ # Search this object for +paths+, and return only the first
115
+ # result. +paths+ must be one or more XPath or CSS queries.
116
+ #
117
+ # See Searchable#search for more information.
118
+ #
119
+ # Or, if passed an integer, index into the NodeSet:
120
+ #
121
+ # node_set.at(3) # same as node_set[3]
122
+ #
123
+ def at *args
124
+ if args.length == 1 && args.first.is_a?(Numeric)
125
+ return self[args.first]
126
+ end
127
+
128
+ super(*args)
129
+ end
130
+ alias :% :at
131
+
132
+ ###
133
+ # Filter this list for nodes that match +expr+
134
+ def filter expr
135
+ find_all { |node| node.matches?(expr) }
136
+ end
137
+
138
+ ###
139
+ # Add the class attribute +name+ to all Node objects in the
140
+ # NodeSet.
141
+ #
142
+ # See Nokogiri::XML::Node#add_class for more information.
143
+ def add_class name
144
+ each do |el|
145
+ el.add_class(name)
146
+ end
147
+ self
148
+ end
149
+
150
+ ###
151
+ # Append the class attribute +name+ to all Node objects in the
152
+ # NodeSet.
153
+ #
154
+ # See Nokogiri::XML::Node#append_class for more information.
155
+ def append_class name
156
+ each do |el|
157
+ el.append_class(name)
158
+ end
159
+ self
160
+ end
161
+
162
+ ###
163
+ # Remove the class attribute +name+ from all Node objects in the
164
+ # NodeSet.
165
+ #
166
+ # See Nokogiri::XML::Node#remove_class for more information.
167
+ def remove_class name = nil
168
+ each do |el|
169
+ el.remove_class(name)
170
+ end
171
+ self
172
+ end
173
+
174
+ ###
175
+ # Set attributes on each Node in the NodeSet, or get an
176
+ # attribute from the first Node in the NodeSet.
177
+ #
178
+ # To get an attribute from the first Node in a NodeSet:
179
+ #
180
+ # node_set.attr("href") # => "https://www.nokogiri.org"
181
+ #
182
+ # Note that an empty NodeSet will return nil when +#attr+ is called as a getter.
183
+ #
184
+ # To set an attribute on each node, +key+ can either be an
185
+ # attribute name, or a Hash of attribute names and values. When
186
+ # called as a setter, +#attr+ returns the NodeSet.
187
+ #
188
+ # If +key+ is an attribute name, then either +value+ or +block+
189
+ # must be passed.
190
+ #
191
+ # If +key+ is a Hash then attributes will be set for each
192
+ # key/value pair:
193
+ #
194
+ # node_set.attr("href" => "https://www.nokogiri.org", "class" => "member")
195
+ #
196
+ # If +value+ is passed, it will be used as the attribute value
197
+ # for all nodes:
198
+ #
199
+ # node_set.attr("href", "https://www.nokogiri.org")
200
+ #
201
+ # If +block+ is passed, it will be called on each Node object in
202
+ # the NodeSet and the return value used as the attribute value
203
+ # for that node:
204
+ #
205
+ # node_set.attr("class") { |node| node.name }
206
+ #
207
+ def attr key, value = nil, &block
208
+ unless key.is_a?(Hash) || (key && (value || block))
209
+ return first ? first.attribute(key) : nil
210
+ end
211
+
212
+ hash = key.is_a?(Hash) ? key : { key => value }
213
+
214
+ hash.each do |k,v|
215
+ each do |node|
216
+ node[k] = v || block.call(node)
217
+ end
218
+ end
219
+
220
+ self
221
+ end
222
+ alias :set :attr
223
+ alias :attribute :attr
224
+
225
+ ###
226
+ # Remove the attributed named +name+ from all Node objects in the NodeSet
227
+ def remove_attr name
228
+ each { |el| el.delete name }
229
+ self
230
+ end
231
+ alias remove_attribute remove_attr
232
+
233
+ ###
234
+ # Iterate over each node, yielding to +block+
235
+ def each
236
+ return to_enum unless block_given?
237
+
238
+ 0.upto(length - 1) do |x|
239
+ yield self[x]
240
+ end
241
+ self
242
+ end
243
+
244
+ ###
245
+ # Get the inner text of all contained Node objects
246
+ #
247
+ # Note: This joins the text of all Node objects in the NodeSet:
248
+ #
249
+ # doc = Nokogiri::XML('<xml><a><d>foo</d><d>bar</d></a></xml>')
250
+ # doc.css('d').text # => "foobar"
251
+ #
252
+ # Instead, if you want to return the text of all nodes in the NodeSet:
253
+ #
254
+ # doc.css('d').map(&:text) # => ["foo", "bar"]
255
+ #
256
+ # See Nokogiri::XML::Node#content for more information.
257
+ def inner_text
258
+ collect(&:inner_text).join('')
259
+ end
260
+ alias :text :inner_text
261
+
262
+ ###
263
+ # Get the inner html of all contained Node objects
264
+ def inner_html *args
265
+ collect{|j| j.inner_html(*args) }.join('')
266
+ end
267
+
268
+ ###
269
+ # Wrap this NodeSet with +html+
270
+ def wrap html
271
+ map { |node| node.wrap html }
272
+ end
273
+
274
+ ###
275
+ # Convert this NodeSet to a string.
276
+ def to_s
277
+ map(&:to_s).join
278
+ end
279
+
280
+ ###
281
+ # Convert this NodeSet to HTML
282
+ def to_html *args
283
+ if Nokogiri.jruby?
284
+ options = args.first.is_a?(Hash) ? args.shift : {}
285
+ if !options[:save_with]
286
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
287
+ end
288
+ args.insert(0, options)
289
+ end
290
+ map { |x| x.to_html(*args) }.join
291
+ end
292
+
293
+ ###
294
+ # Convert this NodeSet to XHTML
295
+ def to_xhtml *args
296
+ map { |x| x.to_xhtml(*args) }.join
297
+ end
298
+
299
+ ###
300
+ # Convert this NodeSet to XML
301
+ def to_xml *args
302
+ map { |x| x.to_xml(*args) }.join
303
+ end
304
+
305
+ alias :size :length
306
+ alias :to_ary :to_a
307
+
308
+ ###
309
+ # Removes the last element from set and returns it, or +nil+ if
310
+ # the set is empty
311
+ def pop
312
+ return nil if length == 0
313
+ delete last
314
+ end
315
+
316
+ ###
317
+ # Returns the first element of the NodeSet and removes it. Returns
318
+ # +nil+ if the set is empty.
319
+ def shift
320
+ return nil if length == 0
321
+ delete first
322
+ end
323
+
324
+ ###
325
+ # Equality -- Two NodeSets are equal if the contain the same number
326
+ # of elements and if each element is equal to the corresponding
327
+ # element in the other NodeSet
328
+ def == other
329
+ return false unless other.is_a?(Nokogiri::XML::NodeSet)
330
+ return false unless length == other.length
331
+ each_with_index do |node, i|
332
+ return false unless node == other[i]
333
+ end
334
+ true
335
+ end
336
+
337
+ ###
338
+ # Returns a new NodeSet containing all the children of all the nodes in
339
+ # the NodeSet
340
+ def children
341
+ node_set = NodeSet.new(document)
342
+ each do |node|
343
+ node.children.each { |n| node_set.push(n) }
344
+ end
345
+ node_set
346
+ end
347
+
348
+ ###
349
+ # Returns a new NodeSet containing all the nodes in the NodeSet
350
+ # in reverse order
351
+ def reverse
352
+ node_set = NodeSet.new(document)
353
+ (length - 1).downto(0) do |x|
354
+ node_set.push self[x]
355
+ end
356
+ node_set
357
+ end
358
+
359
+ ###
360
+ # Return a nicely formated string representation
361
+ def inspect
362
+ "[#{map(&:inspect).join ', '}]"
363
+ end
364
+
365
+ alias :+ :|
366
+
367
+ # @private
368
+ IMPLIED_XPATH_CONTEXTS = [ './/'.freeze, 'self::'.freeze ].freeze # :nodoc:
369
+
370
+ end
371
+ end
372
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ class Notation < Struct.new(:name, :public_id, :system_id)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ ###
5
+ # Parse options for passing to Nokogiri.XML or Nokogiri.HTML
6
+ #
7
+ # == Building combinations of parse options
8
+ # You can build your own combinations of these parse options by using any of the following methods:
9
+ # *Note*: All examples attempt to set the +RECOVER+ & +NOENT+ options.
10
+ # [Ruby's bitwise operators] You can use the Ruby bitwise operators to set various combinations.
11
+ # Nokogiri.XML('<content>Chapter 1</content', nil, nil, Nokogiri::XML::ParseOptions.new((1 << 0) | (1 << 1)))
12
+ # [Method chaining] Every option has an equivalent method in lowercase. You can chain these methods together to set various combinations.
13
+ # Nokogiri.XML('<content>Chapter 1</content', nil, nil, Nokogiri::XML::ParseOptions.new.recover.noent)
14
+ # [Using Ruby Blocks] You can also setup parse combinations in the block passed to Nokogiri.XML or Nokogiri.HTML
15
+ # Nokogiri.XML('<content>Chapter 1</content') {|config| config.recover.noent}
16
+ #
17
+ # == Removing particular parse options
18
+ # You can also remove options from an instance of +ParseOptions+ dynamically.
19
+ # Every option has an equivalent <code>no{option}</code> method in lowercase. You can call these methods on an instance of +ParseOptions+ to remove the option.
20
+ # Note that this is not available for +STRICT+.
21
+ #
22
+ # # Setting the RECOVER & NOENT options...
23
+ # options = Nokogiri::XML::ParseOptions.new.recover.noent
24
+ # # later...
25
+ # options.norecover # Removes the Nokogiri::XML::ParseOptions::RECOVER option
26
+ # options.nonoent # Removes the Nokogiri::XML::ParseOptions::NOENT option
27
+ #
28
+ class ParseOptions
29
+ # Strict parsing
30
+ STRICT = 0
31
+ # Recover from errors
32
+ RECOVER = 1 << 0
33
+ # Substitute entities
34
+ NOENT = 1 << 1
35
+ # Load external subsets
36
+ DTDLOAD = 1 << 2
37
+ # Default DTD attributes
38
+ DTDATTR = 1 << 3
39
+ # validate with the DTD
40
+ DTDVALID = 1 << 4
41
+ # suppress error reports
42
+ NOERROR = 1 << 5
43
+ # suppress warning reports
44
+ NOWARNING = 1 << 6
45
+ # pedantic error reporting
46
+ PEDANTIC = 1 << 7
47
+ # remove blank nodes
48
+ NOBLANKS = 1 << 8
49
+ # use the SAX1 interface internally
50
+ SAX1 = 1 << 9
51
+ # Implement XInclude substitution
52
+ XINCLUDE = 1 << 10
53
+ # Forbid network access. Recommended for dealing with untrusted documents.
54
+ NONET = 1 << 11
55
+ # Do not reuse the context dictionary
56
+ NODICT = 1 << 12
57
+ # remove redundant namespaces declarations
58
+ NSCLEAN = 1 << 13
59
+ # merge CDATA as text nodes
60
+ NOCDATA = 1 << 14
61
+ # do not generate XINCLUDE START/END nodes
62
+ NOXINCNODE = 1 << 15
63
+ # compact small text nodes; no modification of the tree allowed afterwards (will possibly crash if you try to modify the tree)
64
+ COMPACT = 1 << 16
65
+ # parse using XML-1.0 before update 5
66
+ OLD10 = 1 << 17
67
+ # do not fixup XINCLUDE xml:base uris
68
+ NOBASEFIX = 1 << 18
69
+ # relax any hardcoded limit from the parser
70
+ HUGE = 1 << 19
71
+
72
+ # the default options used for parsing XML documents
73
+ DEFAULT_XML = RECOVER | NONET
74
+ # the default options used for parsing HTML documents
75
+ DEFAULT_HTML = RECOVER | NOERROR | NOWARNING | NONET
76
+
77
+ attr_accessor :options
78
+ def initialize options = STRICT
79
+ @options = options
80
+ end
81
+
82
+ constants.each do |constant|
83
+ next if constant.to_sym == :STRICT
84
+ class_eval %{
85
+ def #{constant.downcase}
86
+ @options |= #{constant}
87
+ self
88
+ end
89
+
90
+ def no#{constant.downcase}
91
+ @options &= ~#{constant}
92
+ self
93
+ end
94
+
95
+ def #{constant.downcase}?
96
+ #{constant} & @options == #{constant}
97
+ end
98
+ }
99
+ end
100
+
101
+ def strict
102
+ @options &= ~RECOVER
103
+ self
104
+ end
105
+
106
+ def strict?
107
+ @options & RECOVER == STRICT
108
+ end
109
+
110
+ alias :to_i :options
111
+
112
+ def inspect
113
+ options = []
114
+ self.class.constants.each do |k|
115
+ options << k.downcase if send(:"#{k.downcase}?")
116
+ end
117
+ super.sub(/>$/, " " + options.join(', ') + ">")
118
+ end
119
+ end
120
+ end
121
+ end