nokogiri 1.11.0.rc4-arm64-darwin

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 (218) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-DEPENDENCIES.md +1682 -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 +477 -0
  8. data/ext/nokogiri/extconf.rb +819 -0
  9. data/ext/nokogiri/html_document.c +171 -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/include/libexslt/exslt.h +102 -0
  20. data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
  21. data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
  22. data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
  23. data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
  24. data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
  25. data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
  26. data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
  27. data/ext/nokogiri/include/libxml2/libxml/c14n.h +126 -0
  28. data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
  29. data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
  30. data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
  31. data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
  32. data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
  33. data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
  34. data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
  35. data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
  36. data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
  37. data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
  38. data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
  39. data/ext/nokogiri/include/libxml2/libxml/parser.h +1241 -0
  40. data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
  41. data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
  42. data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
  43. data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
  44. data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
  45. data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
  46. data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
  47. data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
  48. data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
  49. data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
  50. data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
  51. data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +366 -0
  52. data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
  53. data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +945 -0
  54. data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +153 -0
  55. data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
  56. data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
  57. data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
  58. data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
  59. data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
  60. data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
  61. data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
  62. data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
  63. data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
  64. data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
  65. data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
  66. data/ext/nokogiri/include/libxml2/libxml/xpath.h +566 -0
  67. data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
  68. data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
  69. data/ext/nokogiri/include/libxslt/attributes.h +38 -0
  70. data/ext/nokogiri/include/libxslt/documents.h +93 -0
  71. data/ext/nokogiri/include/libxslt/extensions.h +262 -0
  72. data/ext/nokogiri/include/libxslt/extra.h +72 -0
  73. data/ext/nokogiri/include/libxslt/functions.h +78 -0
  74. data/ext/nokogiri/include/libxslt/imports.h +75 -0
  75. data/ext/nokogiri/include/libxslt/keys.h +53 -0
  76. data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
  77. data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
  78. data/ext/nokogiri/include/libxslt/pattern.h +84 -0
  79. data/ext/nokogiri/include/libxslt/preproc.h +43 -0
  80. data/ext/nokogiri/include/libxslt/security.h +104 -0
  81. data/ext/nokogiri/include/libxslt/templates.h +77 -0
  82. data/ext/nokogiri/include/libxslt/transform.h +207 -0
  83. data/ext/nokogiri/include/libxslt/variables.h +118 -0
  84. data/ext/nokogiri/include/libxslt/xslt.h +110 -0
  85. data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
  86. data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
  87. data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
  88. data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
  89. data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
  90. data/ext/nokogiri/nokogiri.c +135 -0
  91. data/ext/nokogiri/nokogiri.h +130 -0
  92. data/ext/nokogiri/xml_attr.c +103 -0
  93. data/ext/nokogiri/xml_attr.h +9 -0
  94. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  95. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  96. data/ext/nokogiri/xml_cdata.c +62 -0
  97. data/ext/nokogiri/xml_cdata.h +9 -0
  98. data/ext/nokogiri/xml_comment.c +69 -0
  99. data/ext/nokogiri/xml_comment.h +9 -0
  100. data/ext/nokogiri/xml_document.c +622 -0
  101. data/ext/nokogiri/xml_document.h +23 -0
  102. data/ext/nokogiri/xml_document_fragment.c +48 -0
  103. data/ext/nokogiri/xml_document_fragment.h +10 -0
  104. data/ext/nokogiri/xml_dtd.c +202 -0
  105. data/ext/nokogiri/xml_dtd.h +10 -0
  106. data/ext/nokogiri/xml_element_content.c +123 -0
  107. data/ext/nokogiri/xml_element_content.h +10 -0
  108. data/ext/nokogiri/xml_element_decl.c +69 -0
  109. data/ext/nokogiri/xml_element_decl.h +9 -0
  110. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  111. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  112. data/ext/nokogiri/xml_entity_decl.c +110 -0
  113. data/ext/nokogiri/xml_entity_decl.h +10 -0
  114. data/ext/nokogiri/xml_entity_reference.c +52 -0
  115. data/ext/nokogiri/xml_entity_reference.h +9 -0
  116. data/ext/nokogiri/xml_io.c +63 -0
  117. data/ext/nokogiri/xml_io.h +11 -0
  118. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  119. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  120. data/ext/nokogiri/xml_namespace.c +111 -0
  121. data/ext/nokogiri/xml_namespace.h +14 -0
  122. data/ext/nokogiri/xml_node.c +1773 -0
  123. data/ext/nokogiri/xml_node.h +13 -0
  124. data/ext/nokogiri/xml_node_set.c +486 -0
  125. data/ext/nokogiri/xml_node_set.h +12 -0
  126. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  127. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  128. data/ext/nokogiri/xml_reader.c +657 -0
  129. data/ext/nokogiri/xml_reader.h +10 -0
  130. data/ext/nokogiri/xml_relax_ng.c +179 -0
  131. data/ext/nokogiri/xml_relax_ng.h +9 -0
  132. data/ext/nokogiri/xml_sax_parser.c +305 -0
  133. data/ext/nokogiri/xml_sax_parser.h +39 -0
  134. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  135. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  136. data/ext/nokogiri/xml_sax_push_parser.c +159 -0
  137. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  138. data/ext/nokogiri/xml_schema.c +276 -0
  139. data/ext/nokogiri/xml_schema.h +9 -0
  140. data/ext/nokogiri/xml_syntax_error.c +64 -0
  141. data/ext/nokogiri/xml_syntax_error.h +13 -0
  142. data/ext/nokogiri/xml_text.c +52 -0
  143. data/ext/nokogiri/xml_text.h +9 -0
  144. data/ext/nokogiri/xml_xpath_context.c +374 -0
  145. data/ext/nokogiri/xml_xpath_context.h +10 -0
  146. data/ext/nokogiri/xslt_stylesheet.c +263 -0
  147. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  148. data/lib/nokogiri.rb +127 -0
  149. data/lib/nokogiri/2.5/nokogiri.bundle +0 -0
  150. data/lib/nokogiri/2.6/nokogiri.bundle +0 -0
  151. data/lib/nokogiri/2.7/nokogiri.bundle +0 -0
  152. data/lib/nokogiri/3.0/nokogiri.bundle +0 -0
  153. data/lib/nokogiri/css.rb +28 -0
  154. data/lib/nokogiri/css/node.rb +53 -0
  155. data/lib/nokogiri/css/parser.rb +751 -0
  156. data/lib/nokogiri/css/parser.y +272 -0
  157. data/lib/nokogiri/css/parser_extras.rb +94 -0
  158. data/lib/nokogiri/css/syntax_error.rb +8 -0
  159. data/lib/nokogiri/css/tokenizer.rb +154 -0
  160. data/lib/nokogiri/css/tokenizer.rex +55 -0
  161. data/lib/nokogiri/css/xpath_visitor.rb +260 -0
  162. data/lib/nokogiri/decorators/slop.rb +43 -0
  163. data/lib/nokogiri/html.rb +38 -0
  164. data/lib/nokogiri/html/builder.rb +36 -0
  165. data/lib/nokogiri/html/document.rb +322 -0
  166. data/lib/nokogiri/html/document_fragment.rb +50 -0
  167. data/lib/nokogiri/html/element_description.rb +24 -0
  168. data/lib/nokogiri/html/element_description_defaults.rb +672 -0
  169. data/lib/nokogiri/html/entity_lookup.rb +14 -0
  170. data/lib/nokogiri/html/sax/parser.rb +63 -0
  171. data/lib/nokogiri/html/sax/parser_context.rb +17 -0
  172. data/lib/nokogiri/html/sax/push_parser.rb +37 -0
  173. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  174. data/lib/nokogiri/syntax_error.rb +5 -0
  175. data/lib/nokogiri/version.rb +3 -0
  176. data/lib/nokogiri/version/constant.rb +5 -0
  177. data/lib/nokogiri/version/info.rb +182 -0
  178. data/lib/nokogiri/xml.rb +76 -0
  179. data/lib/nokogiri/xml/attr.rb +15 -0
  180. data/lib/nokogiri/xml/attribute_decl.rb +19 -0
  181. data/lib/nokogiri/xml/builder.rb +447 -0
  182. data/lib/nokogiri/xml/cdata.rb +12 -0
  183. data/lib/nokogiri/xml/character_data.rb +8 -0
  184. data/lib/nokogiri/xml/document.rb +290 -0
  185. data/lib/nokogiri/xml/document_fragment.rb +159 -0
  186. data/lib/nokogiri/xml/dtd.rb +33 -0
  187. data/lib/nokogiri/xml/element_content.rb +37 -0
  188. data/lib/nokogiri/xml/element_decl.rb +14 -0
  189. data/lib/nokogiri/xml/entity_decl.rb +20 -0
  190. data/lib/nokogiri/xml/entity_reference.rb +19 -0
  191. data/lib/nokogiri/xml/namespace.rb +14 -0
  192. data/lib/nokogiri/xml/node.rb +1240 -0
  193. data/lib/nokogiri/xml/node/save_options.rb +62 -0
  194. data/lib/nokogiri/xml/node_set.rb +372 -0
  195. data/lib/nokogiri/xml/notation.rb +7 -0
  196. data/lib/nokogiri/xml/parse_options.rb +127 -0
  197. data/lib/nokogiri/xml/pp.rb +3 -0
  198. data/lib/nokogiri/xml/pp/character_data.rb +19 -0
  199. data/lib/nokogiri/xml/pp/node.rb +57 -0
  200. data/lib/nokogiri/xml/processing_instruction.rb +9 -0
  201. data/lib/nokogiri/xml/reader.rb +116 -0
  202. data/lib/nokogiri/xml/relax_ng.rb +37 -0
  203. data/lib/nokogiri/xml/sax.rb +5 -0
  204. data/lib/nokogiri/xml/sax/document.rb +172 -0
  205. data/lib/nokogiri/xml/sax/parser.rb +123 -0
  206. data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
  207. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  208. data/lib/nokogiri/xml/schema.rb +72 -0
  209. data/lib/nokogiri/xml/searchable.rb +239 -0
  210. data/lib/nokogiri/xml/syntax_error.rb +71 -0
  211. data/lib/nokogiri/xml/text.rb +10 -0
  212. data/lib/nokogiri/xml/xpath.rb +11 -0
  213. data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
  214. data/lib/nokogiri/xml/xpath_context.rb +17 -0
  215. data/lib/nokogiri/xslt.rb +57 -0
  216. data/lib/nokogiri/xslt/stylesheet.rb +26 -0
  217. data/lib/xsd/xmlparser/nokogiri.rb +103 -0
  218. metadata +565 -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,127 @@
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
+ # the default options used for parsing XML schemas
77
+ DEFAULT_SCHEMA = NONET
78
+
79
+ attr_accessor :options
80
+ def initialize options = STRICT
81
+ @options = options
82
+ end
83
+
84
+ constants.each do |constant|
85
+ next if constant.to_sym == :STRICT
86
+ class_eval %{
87
+ def #{constant.downcase}
88
+ @options |= #{constant}
89
+ self
90
+ end
91
+
92
+ def no#{constant.downcase}
93
+ @options &= ~#{constant}
94
+ self
95
+ end
96
+
97
+ def #{constant.downcase}?
98
+ #{constant} & @options == #{constant}
99
+ end
100
+ }
101
+ end
102
+
103
+ def strict
104
+ @options &= ~RECOVER
105
+ self
106
+ end
107
+
108
+ def strict?
109
+ @options & RECOVER == STRICT
110
+ end
111
+
112
+ def ==(other)
113
+ other.to_i == to_i
114
+ end
115
+
116
+ alias :to_i :options
117
+
118
+ def inspect
119
+ options = []
120
+ self.class.constants.each do |k|
121
+ options << k.downcase if send(:"#{k.downcase}?")
122
+ end
123
+ super.sub(/>$/, " " + options.join(', ') + ">")
124
+ end
125
+ end
126
+ end
127
+ end