Nokogiri_precompiled_aarch64_dedshit 1.14.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +44 -0
  3. data/LICENSE-DEPENDENCIES.md +2224 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +287 -0
  6. data/bin/nokogiri +131 -0
  7. data/dependencies.yml +41 -0
  8. data/ext/java/nokogiri/Html4Document.java +157 -0
  9. data/ext/java/nokogiri/Html4ElementDescription.java +133 -0
  10. data/ext/java/nokogiri/Html4EntityLookup.java +63 -0
  11. data/ext/java/nokogiri/Html4SaxParserContext.java +289 -0
  12. data/ext/java/nokogiri/Html4SaxPushParser.java +213 -0
  13. data/ext/java/nokogiri/NokogiriService.java +613 -0
  14. data/ext/java/nokogiri/XmlAttr.java +154 -0
  15. data/ext/java/nokogiri/XmlAttributeDecl.java +119 -0
  16. data/ext/java/nokogiri/XmlCdata.java +60 -0
  17. data/ext/java/nokogiri/XmlComment.java +77 -0
  18. data/ext/java/nokogiri/XmlDocument.java +705 -0
  19. data/ext/java/nokogiri/XmlDocumentFragment.java +163 -0
  20. data/ext/java/nokogiri/XmlDtd.java +516 -0
  21. data/ext/java/nokogiri/XmlElement.java +44 -0
  22. data/ext/java/nokogiri/XmlElementContent.java +412 -0
  23. data/ext/java/nokogiri/XmlElementDecl.java +148 -0
  24. data/ext/java/nokogiri/XmlEntityDecl.java +151 -0
  25. data/ext/java/nokogiri/XmlEntityReference.java +79 -0
  26. data/ext/java/nokogiri/XmlNamespace.java +193 -0
  27. data/ext/java/nokogiri/XmlNode.java +1938 -0
  28. data/ext/java/nokogiri/XmlNodeSet.java +463 -0
  29. data/ext/java/nokogiri/XmlProcessingInstruction.java +79 -0
  30. data/ext/java/nokogiri/XmlReader.java +615 -0
  31. data/ext/java/nokogiri/XmlRelaxng.java +133 -0
  32. data/ext/java/nokogiri/XmlSaxParserContext.java +329 -0
  33. data/ext/java/nokogiri/XmlSaxPushParser.java +288 -0
  34. data/ext/java/nokogiri/XmlSchema.java +423 -0
  35. data/ext/java/nokogiri/XmlSyntaxError.java +137 -0
  36. data/ext/java/nokogiri/XmlText.java +90 -0
  37. data/ext/java/nokogiri/XmlXpathContext.java +305 -0
  38. data/ext/java/nokogiri/XsltStylesheet.java +368 -0
  39. data/ext/java/nokogiri/internals/ClosedStreamException.java +13 -0
  40. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +252 -0
  41. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +27 -0
  42. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +178 -0
  43. data/ext/java/nokogiri/internals/NokogiriDomParser.java +99 -0
  44. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +140 -0
  45. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +65 -0
  46. data/ext/java/nokogiri/internals/NokogiriHandler.java +339 -0
  47. data/ext/java/nokogiri/internals/NokogiriHelpers.java +817 -0
  48. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +228 -0
  49. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +110 -0
  50. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +86 -0
  51. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +107 -0
  52. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +62 -0
  53. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +165 -0
  54. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +50 -0
  55. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +37 -0
  56. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +70 -0
  57. data/ext/java/nokogiri/internals/ParserContext.java +262 -0
  58. data/ext/java/nokogiri/internals/ReaderNode.java +564 -0
  59. data/ext/java/nokogiri/internals/SaveContextVisitor.java +865 -0
  60. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +50 -0
  61. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +174 -0
  62. data/ext/java/nokogiri/internals/XmlDeclHandler.java +11 -0
  63. data/ext/java/nokogiri/internals/XmlDomParserContext.java +265 -0
  64. data/ext/java/nokogiri/internals/XmlSaxParser.java +40 -0
  65. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +122 -0
  66. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +178 -0
  67. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +43 -0
  68. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +106 -0
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +278 -0
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +664 -0
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +45 -0
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +45 -0
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +388 -0
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +308 -0
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +47 -0
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +51 -0
  77. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +51 -0
  78. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +50 -0
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +660 -0
  80. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +194 -0
  81. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +77 -0
  82. data/ext/java/nokogiri/internals/c14n/Constants.java +45 -0
  83. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +325 -0
  84. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +106 -0
  85. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +86 -0
  86. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +181 -0
  87. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +87 -0
  88. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +452 -0
  89. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +52 -0
  90. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +190 -0
  91. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +540 -0
  92. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1712 -0
  93. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +737 -0
  94. data/ext/nokogiri/depend +38 -0
  95. data/ext/nokogiri/extconf.rb +1086 -0
  96. data/ext/nokogiri/gumbo.c +594 -0
  97. data/ext/nokogiri/html4_document.c +167 -0
  98. data/ext/nokogiri/html4_element_description.c +294 -0
  99. data/ext/nokogiri/html4_entity_lookup.c +37 -0
  100. data/ext/nokogiri/html4_sax_parser_context.c +116 -0
  101. data/ext/nokogiri/html4_sax_push_parser.c +95 -0
  102. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  103. data/ext/nokogiri/nokogiri.c +265 -0
  104. data/ext/nokogiri/nokogiri.h +235 -0
  105. data/ext/nokogiri/test_global_handlers.c +42 -0
  106. data/ext/nokogiri/xml_attr.c +103 -0
  107. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  108. data/ext/nokogiri/xml_cdata.c +57 -0
  109. data/ext/nokogiri/xml_comment.c +62 -0
  110. data/ext/nokogiri/xml_document.c +689 -0
  111. data/ext/nokogiri/xml_document_fragment.c +44 -0
  112. data/ext/nokogiri/xml_dtd.c +210 -0
  113. data/ext/nokogiri/xml_element_content.c +128 -0
  114. data/ext/nokogiri/xml_element_decl.c +69 -0
  115. data/ext/nokogiri/xml_encoding_handler.c +104 -0
  116. data/ext/nokogiri/xml_entity_decl.c +112 -0
  117. data/ext/nokogiri/xml_entity_reference.c +50 -0
  118. data/ext/nokogiri/xml_namespace.c +186 -0
  119. data/ext/nokogiri/xml_node.c +2426 -0
  120. data/ext/nokogiri/xml_node_set.c +496 -0
  121. data/ext/nokogiri/xml_processing_instruction.c +54 -0
  122. data/ext/nokogiri/xml_reader.c +794 -0
  123. data/ext/nokogiri/xml_relax_ng.c +164 -0
  124. data/ext/nokogiri/xml_sax_parser.c +316 -0
  125. data/ext/nokogiri/xml_sax_parser_context.c +283 -0
  126. data/ext/nokogiri/xml_sax_push_parser.c +166 -0
  127. data/ext/nokogiri/xml_schema.c +260 -0
  128. data/ext/nokogiri/xml_syntax_error.c +85 -0
  129. data/ext/nokogiri/xml_text.c +48 -0
  130. data/ext/nokogiri/xml_xpath_context.c +415 -0
  131. data/ext/nokogiri/xslt_stylesheet.c +363 -0
  132. data/gumbo-parser/CHANGES.md +63 -0
  133. data/gumbo-parser/Makefile +111 -0
  134. data/gumbo-parser/THANKS +27 -0
  135. data/gumbo-parser/src/Makefile +34 -0
  136. data/gumbo-parser/src/README.md +41 -0
  137. data/gumbo-parser/src/ascii.c +75 -0
  138. data/gumbo-parser/src/ascii.h +115 -0
  139. data/gumbo-parser/src/attribute.c +42 -0
  140. data/gumbo-parser/src/attribute.h +17 -0
  141. data/gumbo-parser/src/char_ref.c +22225 -0
  142. data/gumbo-parser/src/char_ref.h +29 -0
  143. data/gumbo-parser/src/char_ref.rl +2154 -0
  144. data/gumbo-parser/src/error.c +626 -0
  145. data/gumbo-parser/src/error.h +148 -0
  146. data/gumbo-parser/src/foreign_attrs.c +104 -0
  147. data/gumbo-parser/src/foreign_attrs.gperf +27 -0
  148. data/gumbo-parser/src/insertion_mode.h +33 -0
  149. data/gumbo-parser/src/macros.h +91 -0
  150. data/gumbo-parser/src/nokogiri_gumbo.h +944 -0
  151. data/gumbo-parser/src/parser.c +4878 -0
  152. data/gumbo-parser/src/parser.h +41 -0
  153. data/gumbo-parser/src/replacement.h +33 -0
  154. data/gumbo-parser/src/string_buffer.c +103 -0
  155. data/gumbo-parser/src/string_buffer.h +68 -0
  156. data/gumbo-parser/src/string_piece.c +48 -0
  157. data/gumbo-parser/src/svg_attrs.c +174 -0
  158. data/gumbo-parser/src/svg_attrs.gperf +77 -0
  159. data/gumbo-parser/src/svg_tags.c +137 -0
  160. data/gumbo-parser/src/svg_tags.gperf +55 -0
  161. data/gumbo-parser/src/tag.c +223 -0
  162. data/gumbo-parser/src/tag_lookup.c +382 -0
  163. data/gumbo-parser/src/tag_lookup.gperf +170 -0
  164. data/gumbo-parser/src/tag_lookup.h +13 -0
  165. data/gumbo-parser/src/token_buffer.c +79 -0
  166. data/gumbo-parser/src/token_buffer.h +71 -0
  167. data/gumbo-parser/src/token_type.h +17 -0
  168. data/gumbo-parser/src/tokenizer.c +3463 -0
  169. data/gumbo-parser/src/tokenizer.h +112 -0
  170. data/gumbo-parser/src/tokenizer_states.h +339 -0
  171. data/gumbo-parser/src/utf8.c +245 -0
  172. data/gumbo-parser/src/utf8.h +164 -0
  173. data/gumbo-parser/src/util.c +66 -0
  174. data/gumbo-parser/src/util.h +34 -0
  175. data/gumbo-parser/src/vector.c +111 -0
  176. data/gumbo-parser/src/vector.h +45 -0
  177. data/lib/nokogiri/class_resolver.rb +67 -0
  178. data/lib/nokogiri/css/node.rb +54 -0
  179. data/lib/nokogiri/css/parser.rb +770 -0
  180. data/lib/nokogiri/css/parser.y +277 -0
  181. data/lib/nokogiri/css/parser_extras.rb +96 -0
  182. data/lib/nokogiri/css/syntax_error.rb +9 -0
  183. data/lib/nokogiri/css/tokenizer.rb +155 -0
  184. data/lib/nokogiri/css/tokenizer.rex +56 -0
  185. data/lib/nokogiri/css/xpath_visitor.rb +359 -0
  186. data/lib/nokogiri/css.rb +66 -0
  187. data/lib/nokogiri/decorators/slop.rb +44 -0
  188. data/lib/nokogiri/encoding_handler.rb +57 -0
  189. data/lib/nokogiri/extension.rb +32 -0
  190. data/lib/nokogiri/gumbo.rb +15 -0
  191. data/lib/nokogiri/html.rb +48 -0
  192. data/lib/nokogiri/html4/builder.rb +37 -0
  193. data/lib/nokogiri/html4/document.rb +214 -0
  194. data/lib/nokogiri/html4/document_fragment.rb +54 -0
  195. data/lib/nokogiri/html4/element_description.rb +25 -0
  196. data/lib/nokogiri/html4/element_description_defaults.rb +572 -0
  197. data/lib/nokogiri/html4/encoding_reader.rb +121 -0
  198. data/lib/nokogiri/html4/entity_lookup.rb +15 -0
  199. data/lib/nokogiri/html4/sax/parser.rb +63 -0
  200. data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
  201. data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
  202. data/lib/nokogiri/html4.rb +47 -0
  203. data/lib/nokogiri/html5/document.rb +168 -0
  204. data/lib/nokogiri/html5/document_fragment.rb +90 -0
  205. data/lib/nokogiri/html5/node.rb +98 -0
  206. data/lib/nokogiri/html5.rb +389 -0
  207. data/lib/nokogiri/jruby/dependencies.rb +3 -0
  208. data/lib/nokogiri/jruby/isorelax/isorelax/20030108/isorelax-20030108.jar +0 -0
  209. data/lib/nokogiri/jruby/net/sf/saxon/Saxon-HE/9.6.0-4/Saxon-HE-9.6.0-4.jar +0 -0
  210. data/lib/nokogiri/jruby/net/sourceforge/htmlunit/neko-htmlunit/2.63.0/neko-htmlunit-2.63.0.jar +0 -0
  211. data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
  212. data/lib/nokogiri/jruby/nu/validator/jing/20200702VNU/jing-20200702VNU.jar +0 -0
  213. data/lib/nokogiri/jruby/org/nokogiri/nekodtd/0.1.11.noko2/nekodtd-0.1.11.noko2.jar +0 -0
  214. data/lib/nokogiri/jruby/xalan/serializer/2.7.3/serializer-2.7.3.jar +0 -0
  215. data/lib/nokogiri/jruby/xalan/xalan/2.7.3/xalan-2.7.3.jar +0 -0
  216. data/lib/nokogiri/jruby/xerces/xercesImpl/2.12.2/xercesImpl-2.12.2.jar +0 -0
  217. data/lib/nokogiri/jruby/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar +0 -0
  218. data/lib/nokogiri/syntax_error.rb +6 -0
  219. data/lib/nokogiri/version/constant.rb +6 -0
  220. data/lib/nokogiri/version/info.rb +223 -0
  221. data/lib/nokogiri/version.rb +4 -0
  222. data/lib/nokogiri/xml/attr.rb +66 -0
  223. data/lib/nokogiri/xml/attribute_decl.rb +20 -0
  224. data/lib/nokogiri/xml/builder.rb +487 -0
  225. data/lib/nokogiri/xml/cdata.rb +13 -0
  226. data/lib/nokogiri/xml/character_data.rb +9 -0
  227. data/lib/nokogiri/xml/document.rb +471 -0
  228. data/lib/nokogiri/xml/document_fragment.rb +205 -0
  229. data/lib/nokogiri/xml/dtd.rb +34 -0
  230. data/lib/nokogiri/xml/element_content.rb +38 -0
  231. data/lib/nokogiri/xml/element_decl.rb +15 -0
  232. data/lib/nokogiri/xml/entity_decl.rb +21 -0
  233. data/lib/nokogiri/xml/entity_reference.rb +20 -0
  234. data/lib/nokogiri/xml/namespace.rb +58 -0
  235. data/lib/nokogiri/xml/node/save_options.rb +68 -0
  236. data/lib/nokogiri/xml/node.rb +1563 -0
  237. data/lib/nokogiri/xml/node_set.rb +447 -0
  238. data/lib/nokogiri/xml/notation.rb +19 -0
  239. data/lib/nokogiri/xml/parse_options.rb +213 -0
  240. data/lib/nokogiri/xml/pp/character_data.rb +21 -0
  241. data/lib/nokogiri/xml/pp/node.rb +57 -0
  242. data/lib/nokogiri/xml/pp.rb +4 -0
  243. data/lib/nokogiri/xml/processing_instruction.rb +11 -0
  244. data/lib/nokogiri/xml/reader.rb +105 -0
  245. data/lib/nokogiri/xml/relax_ng.rb +38 -0
  246. data/lib/nokogiri/xml/sax/document.rb +167 -0
  247. data/lib/nokogiri/xml/sax/parser.rb +125 -0
  248. data/lib/nokogiri/xml/sax/parser_context.rb +21 -0
  249. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  250. data/lib/nokogiri/xml/sax.rb +6 -0
  251. data/lib/nokogiri/xml/schema.rb +73 -0
  252. data/lib/nokogiri/xml/searchable.rb +270 -0
  253. data/lib/nokogiri/xml/syntax_error.rb +72 -0
  254. data/lib/nokogiri/xml/text.rb +11 -0
  255. data/lib/nokogiri/xml/xpath/syntax_error.rb +13 -0
  256. data/lib/nokogiri/xml/xpath.rb +21 -0
  257. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  258. data/lib/nokogiri/xml.rb +76 -0
  259. data/lib/nokogiri/xslt/stylesheet.rb +27 -0
  260. data/lib/nokogiri/xslt.rb +65 -0
  261. data/lib/nokogiri.rb +120 -0
  262. data/lib/xsd/xmlparser/nokogiri.rb +106 -0
  263. metadata +391 -0
@@ -0,0 +1,447 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Nokogiri
5
+ module XML
6
+ ####
7
+ # A NodeSet contains a list of Nokogiri::XML::Node objects. Typically
8
+ # a NodeSet is return as a result of searching a Document via
9
+ # Nokogiri::XML::Searchable#css or Nokogiri::XML::Searchable#xpath
10
+ class NodeSet
11
+ include Nokogiri::XML::Searchable
12
+ include Enumerable
13
+
14
+ # The Document this NodeSet is associated with
15
+ attr_accessor :document
16
+
17
+ alias_method :clone, :dup
18
+
19
+ # Create a NodeSet with +document+ defaulting to +list+
20
+ def initialize(document, list = [])
21
+ @document = document
22
+ document.decorate(self)
23
+ list.each { |x| self << x }
24
+ yield self if block_given?
25
+ end
26
+
27
+ ###
28
+ # Get the first element of the NodeSet.
29
+ def first(n = nil)
30
+ return self[0] unless n
31
+
32
+ list = []
33
+ [n, length].min.times { |i| list << self[i] }
34
+ list
35
+ end
36
+
37
+ ###
38
+ # Get the last element of the NodeSet.
39
+ def last
40
+ self[-1]
41
+ end
42
+
43
+ ###
44
+ # Is this NodeSet empty?
45
+ def empty?
46
+ length == 0
47
+ end
48
+
49
+ ###
50
+ # 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.
51
+ def index(node = nil)
52
+ if node
53
+ warn("given block not used") if block_given?
54
+ each_with_index { |member, j| return j if member == node }
55
+ elsif block_given?
56
+ each_with_index { |member, j| return j if yield(member) }
57
+ end
58
+ nil
59
+ end
60
+
61
+ ###
62
+ # Insert +datum+ before the first Node in this NodeSet
63
+ def before(datum)
64
+ first.before(datum)
65
+ end
66
+
67
+ ###
68
+ # Insert +datum+ after the last Node in this NodeSet
69
+ def after(datum)
70
+ last.after(datum)
71
+ end
72
+
73
+ alias_method :<<, :push
74
+ alias_method :remove, :unlink
75
+
76
+ ###
77
+ # call-seq: css *rules, [namespace-bindings, custom-pseudo-class]
78
+ #
79
+ # Search this node set for CSS +rules+. +rules+ must be one or more CSS
80
+ # selectors. For example:
81
+ #
82
+ # For more information see Nokogiri::XML::Searchable#css
83
+ def css(*args)
84
+ rules, handler, ns, _ = extract_params(args)
85
+ paths = css_rules_to_xpath(rules, ns)
86
+
87
+ inject(NodeSet.new(document)) do |set, node|
88
+ set + xpath_internal(node, paths, handler, ns, nil)
89
+ end
90
+ end
91
+
92
+ ###
93
+ # call-seq: xpath *paths, [namespace-bindings, variable-bindings, custom-handler-class]
94
+ #
95
+ # Search this node set for XPath +paths+. +paths+ must be one or more XPath
96
+ # queries.
97
+ #
98
+ # For more information see Nokogiri::XML::Searchable#xpath
99
+ def xpath(*args)
100
+ paths, handler, ns, binds = extract_params(args)
101
+
102
+ inject(NodeSet.new(document)) do |set, node|
103
+ set + xpath_internal(node, paths, handler, ns, binds)
104
+ end
105
+ end
106
+
107
+ ###
108
+ # call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
109
+ #
110
+ # Search this object for +paths+, and return only the first
111
+ # result. +paths+ must be one or more XPath or CSS queries.
112
+ #
113
+ # See Searchable#search for more information.
114
+ #
115
+ # Or, if passed an integer, index into the NodeSet:
116
+ #
117
+ # node_set.at(3) # same as node_set[3]
118
+ #
119
+ def at(*args)
120
+ if args.length == 1 && args.first.is_a?(Numeric)
121
+ return self[args.first]
122
+ end
123
+
124
+ super(*args)
125
+ end
126
+ alias_method :%, :at
127
+
128
+ ###
129
+ # Filter this list for nodes that match +expr+
130
+ def filter(expr)
131
+ find_all { |node| node.matches?(expr) }
132
+ end
133
+
134
+ ###
135
+ # Add the class attribute +name+ to all Node objects in the
136
+ # NodeSet.
137
+ #
138
+ # See Nokogiri::XML::Node#add_class for more information.
139
+ def add_class(name)
140
+ each do |el|
141
+ el.add_class(name)
142
+ end
143
+ self
144
+ end
145
+
146
+ ###
147
+ # Append the class attribute +name+ to all Node objects in the
148
+ # NodeSet.
149
+ #
150
+ # See Nokogiri::XML::Node#append_class for more information.
151
+ def append_class(name)
152
+ each do |el|
153
+ el.append_class(name)
154
+ end
155
+ self
156
+ end
157
+
158
+ ###
159
+ # Remove the class attribute +name+ from all Node objects in the
160
+ # NodeSet.
161
+ #
162
+ # See Nokogiri::XML::Node#remove_class for more information.
163
+ def remove_class(name = nil)
164
+ each do |el|
165
+ el.remove_class(name)
166
+ end
167
+ self
168
+ end
169
+
170
+ ###
171
+ # Set attributes on each Node in the NodeSet, or get an
172
+ # attribute from the first Node in the NodeSet.
173
+ #
174
+ # To get an attribute from the first Node in a NodeSet:
175
+ #
176
+ # node_set.attr("href") # => "https://www.nokogiri.org"
177
+ #
178
+ # Note that an empty NodeSet will return nil when +#attr+ is called as a getter.
179
+ #
180
+ # To set an attribute on each node, +key+ can either be an
181
+ # attribute name, or a Hash of attribute names and values. When
182
+ # called as a setter, +#attr+ returns the NodeSet.
183
+ #
184
+ # If +key+ is an attribute name, then either +value+ or +block+
185
+ # must be passed.
186
+ #
187
+ # If +key+ is a Hash then attributes will be set for each
188
+ # key/value pair:
189
+ #
190
+ # node_set.attr("href" => "https://www.nokogiri.org", "class" => "member")
191
+ #
192
+ # If +value+ is passed, it will be used as the attribute value
193
+ # for all nodes:
194
+ #
195
+ # node_set.attr("href", "https://www.nokogiri.org")
196
+ #
197
+ # If +block+ is passed, it will be called on each Node object in
198
+ # the NodeSet and the return value used as the attribute value
199
+ # for that node:
200
+ #
201
+ # node_set.attr("class") { |node| node.name }
202
+ #
203
+ def attr(key, value = nil, &block)
204
+ unless key.is_a?(Hash) || (key && (value || block))
205
+ return first&.attribute(key)
206
+ end
207
+
208
+ hash = key.is_a?(Hash) ? key : { key => value }
209
+
210
+ hash.each do |k, v|
211
+ each do |node|
212
+ node[k] = v || yield(node)
213
+ end
214
+ end
215
+
216
+ self
217
+ end
218
+ alias_method :set, :attr
219
+ alias_method :attribute, :attr
220
+
221
+ ###
222
+ # Remove the attributed named +name+ from all Node objects in the NodeSet
223
+ def remove_attr(name)
224
+ each { |el| el.delete(name) }
225
+ self
226
+ end
227
+ alias_method :remove_attribute, :remove_attr
228
+
229
+ ###
230
+ # Iterate over each node, yielding to +block+
231
+ def each
232
+ return to_enum unless block_given?
233
+
234
+ 0.upto(length - 1) do |x|
235
+ yield self[x]
236
+ end
237
+ self
238
+ end
239
+
240
+ ###
241
+ # Get the inner text of all contained Node objects
242
+ #
243
+ # Note: This joins the text of all Node objects in the NodeSet:
244
+ #
245
+ # doc = Nokogiri::XML('<xml><a><d>foo</d><d>bar</d></a></xml>')
246
+ # doc.css('d').text # => "foobar"
247
+ #
248
+ # Instead, if you want to return the text of all nodes in the NodeSet:
249
+ #
250
+ # doc.css('d').map(&:text) # => ["foo", "bar"]
251
+ #
252
+ # See Nokogiri::XML::Node#content for more information.
253
+ def inner_text
254
+ collect(&:inner_text).join("")
255
+ end
256
+ alias_method :text, :inner_text
257
+
258
+ ###
259
+ # Get the inner html of all contained Node objects
260
+ def inner_html(*args)
261
+ collect { |j| j.inner_html(*args) }.join("")
262
+ end
263
+
264
+ # :call-seq:
265
+ # wrap(markup) -> self
266
+ # wrap(node) -> self
267
+ #
268
+ # Wrap each member of this NodeSet with the node parsed from +markup+ or a dup of the +node+.
269
+ #
270
+ # [Parameters]
271
+ # - *markup* (String)
272
+ # Markup that is parsed, once per member of the NodeSet, and used as the wrapper. Each
273
+ # node's parent, if it exists, is used as the context node for parsing; otherwise the
274
+ # associated document is used. If the parsed fragment has multiple roots, the first root
275
+ # node is used as the wrapper.
276
+ # - *node* (Nokogiri::XML::Node)
277
+ # An element that is `#dup`ed and used as the wrapper.
278
+ #
279
+ # [Returns] +self+, to support chaining.
280
+ #
281
+ # ⚠ Note that if a +String+ is passed, the markup will be parsed <b>once per node</b> in the
282
+ # NodeSet. You can avoid this overhead in cases where you know exactly the wrapper you wish to
283
+ # use by passing a +Node+ instead.
284
+ #
285
+ # Also see Node#wrap
286
+ #
287
+ # *Example* with a +String+ argument:
288
+ #
289
+ # doc = Nokogiri::HTML5(<<~HTML)
290
+ # <html><body>
291
+ # <a>a</a>
292
+ # <a>b</a>
293
+ # <a>c</a>
294
+ # <a>d</a>
295
+ # </body></html>
296
+ # HTML
297
+ # doc.css("a").wrap("<div></div>")
298
+ # doc.to_html
299
+ # # => <html><head></head><body>
300
+ # # <div><a>a</a></div>
301
+ # # <div><a>b</a></div>
302
+ # # <div><a>c</a></div>
303
+ # # <div><a>d</a></div>
304
+ # # </body></html>
305
+ #
306
+ # *Example* with a +Node+ argument
307
+ #
308
+ # 💡 Note that this is faster than the equivalent call passing a +String+ because it avoids
309
+ # having to reparse the wrapper markup for each node.
310
+ #
311
+ # doc = Nokogiri::HTML5(<<~HTML)
312
+ # <html><body>
313
+ # <a>a</a>
314
+ # <a>b</a>
315
+ # <a>c</a>
316
+ # <a>d</a>
317
+ # </body></html>
318
+ # HTML
319
+ # doc.css("a").wrap(doc.create_element("div"))
320
+ # doc.to_html
321
+ # # => <html><head></head><body>
322
+ # # <div><a>a</a></div>
323
+ # # <div><a>b</a></div>
324
+ # # <div><a>c</a></div>
325
+ # # <div><a>d</a></div>
326
+ # # </body></html>
327
+ #
328
+ def wrap(node_or_tags)
329
+ map { |node| node.wrap(node_or_tags) }
330
+ self
331
+ end
332
+
333
+ ###
334
+ # Convert this NodeSet to a string.
335
+ def to_s
336
+ map(&:to_s).join
337
+ end
338
+
339
+ ###
340
+ # Convert this NodeSet to HTML
341
+ def to_html(*args)
342
+ if Nokogiri.jruby?
343
+ options = args.first.is_a?(Hash) ? args.shift : {}
344
+ options[:save_with] ||= Node::SaveOptions::DEFAULT_HTML
345
+ args.insert(0, options)
346
+ end
347
+ if empty?
348
+ encoding = (args.first.is_a?(Hash) ? args.first[:encoding] : nil)
349
+ encoding ||= document.encoding
350
+ encoding.nil? ? "" : "".encode(encoding)
351
+ else
352
+ map { |x| x.to_html(*args) }.join
353
+ end
354
+ end
355
+
356
+ ###
357
+ # Convert this NodeSet to XHTML
358
+ def to_xhtml(*args)
359
+ map { |x| x.to_xhtml(*args) }.join
360
+ end
361
+
362
+ ###
363
+ # Convert this NodeSet to XML
364
+ def to_xml(*args)
365
+ map { |x| x.to_xml(*args) }.join
366
+ end
367
+
368
+ alias_method :size, :length
369
+ alias_method :to_ary, :to_a
370
+
371
+ ###
372
+ # Removes the last element from set and returns it, or +nil+ if
373
+ # the set is empty
374
+ def pop
375
+ return nil if length == 0
376
+
377
+ delete(last)
378
+ end
379
+
380
+ ###
381
+ # Returns the first element of the NodeSet and removes it. Returns
382
+ # +nil+ if the set is empty.
383
+ def shift
384
+ return nil if length == 0
385
+
386
+ delete(first)
387
+ end
388
+
389
+ ###
390
+ # Equality -- Two NodeSets are equal if the contain the same number
391
+ # of elements and if each element is equal to the corresponding
392
+ # element in the other NodeSet
393
+ def ==(other)
394
+ return false unless other.is_a?(Nokogiri::XML::NodeSet)
395
+ return false unless length == other.length
396
+
397
+ each_with_index do |node, i|
398
+ return false unless node == other[i]
399
+ end
400
+ true
401
+ end
402
+
403
+ ###
404
+ # Returns a new NodeSet containing all the children of all the nodes in
405
+ # the NodeSet
406
+ def children
407
+ node_set = NodeSet.new(document)
408
+ each do |node|
409
+ node.children.each { |n| node_set.push(n) }
410
+ end
411
+ node_set
412
+ end
413
+
414
+ ###
415
+ # Returns a new NodeSet containing all the nodes in the NodeSet
416
+ # in reverse order
417
+ def reverse
418
+ node_set = NodeSet.new(document)
419
+ (length - 1).downto(0) do |x|
420
+ node_set.push(self[x])
421
+ end
422
+ node_set
423
+ end
424
+
425
+ ###
426
+ # Return a nicely formated string representation
427
+ def inspect
428
+ "[#{map(&:inspect).join(", ")}]"
429
+ end
430
+
431
+ alias_method :+, :|
432
+
433
+ #
434
+ # :call-seq: deconstruct() → Array
435
+ #
436
+ # Returns the members of this NodeSet as an array, to use in pattern matching.
437
+ #
438
+ # ⚡ This is an experimental feature, available since v1.14.0
439
+ #
440
+ def deconstruct
441
+ to_a
442
+ end
443
+
444
+ IMPLIED_XPATH_CONTEXTS = [".//", "self::"].freeze # :nodoc:
445
+ end
446
+ end
447
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ # Struct representing an {XML Schema Notation}[https://www.w3.org/TR/xml/#Notations]
6
+ class Notation < Struct.new(:name, :public_id, :system_id)
7
+ # dead comment to ensure rdoc processing
8
+
9
+ # :attr: name (String)
10
+ # The name for the element.
11
+
12
+ # :attr: public_id (String)
13
+ # The URI corresponding to the public identifier
14
+
15
+ # :attr: system_id (String,nil)
16
+ # The URI corresponding to the system identifier
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,213 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Nokogiri
5
+ module XML
6
+ # Options that control the parsing behavior for XML::Document, XML::DocumentFragment,
7
+ # HTML4::Document, HTML4::DocumentFragment, XSLT::Stylesheet, and XML::Schema.
8
+ #
9
+ # These options directly expose libxml2's parse options, which are all boolean in the sense that
10
+ # an option is "on" or "off".
11
+ #
12
+ # 💡 Note that HTML5 parsing has a separate, orthogonal set of options due to the nature of the
13
+ # HTML5 specification. See Nokogiri::HTML5.
14
+ #
15
+ # ⚠ Not all parse options are supported on JRuby. Nokogiri will attempt to invoke the equivalent
16
+ # behavior in Xerces/NekoHTML on JRuby when it's possible.
17
+ #
18
+ # == Setting and unsetting parse options
19
+ #
20
+ # You can build your own combinations of parse options by using any of the following methods:
21
+ #
22
+ # [ParseOptions method chaining]
23
+ #
24
+ # Every option has an equivalent method in lowercase. You can chain these methods together to
25
+ # set various combinations.
26
+ #
27
+ # # Set the HUGE & PEDANTIC options
28
+ # po = Nokogiri::XML::ParseOptions.new.huge.pedantic
29
+ # doc = Nokogiri::XML::Document.parse(xml, nil, nil, po)
30
+ #
31
+ # Every option has an equivalent <code>no{option}</code> method in lowercase. You can call these
32
+ # methods on an instance of ParseOptions to unset the option.
33
+ #
34
+ # # Set the HUGE & PEDANTIC options
35
+ # po = Nokogiri::XML::ParseOptions.new.huge.pedantic
36
+ #
37
+ # # later we want to modify the options
38
+ # po.nohuge # Unset the HUGE option
39
+ # po.nopedantic # Unset the PEDANTIC option
40
+ #
41
+ # 💡 Note that some options begin with "no" leading to the logical but perhaps unintuitive
42
+ # double negative:
43
+ #
44
+ # po.nocdata # Set the NOCDATA parse option
45
+ # po.nonocdata # Unset the NOCDATA parse option
46
+ #
47
+ # 💡 Note that negation is not available for STRICT, which is itself a negation of all other
48
+ # features.
49
+ #
50
+ #
51
+ # [Using Ruby Blocks]
52
+ #
53
+ # Most parsing methods will accept a block for configuration of parse options, and we
54
+ # recommend chaining the setter methods:
55
+ #
56
+ # doc = Nokogiri::XML::Document.parse(xml) { |config| config.huge.pedantic }
57
+ #
58
+ #
59
+ # [ParseOptions constants]
60
+ #
61
+ # You can also use the constants declared under Nokogiri::XML::ParseOptions to set various
62
+ # combinations. They are bits in a bitmask, and so can be combined with bitwise operators:
63
+ #
64
+ # po = Nokogiri::XML::ParseOptions.new(Nokogiri::XML::ParseOptions::HUGE | Nokogiri::XML::ParseOptions::PEDANTIC)
65
+ # doc = Nokogiri::XML::Document.parse(xml, nil, nil, po)
66
+ #
67
+ class ParseOptions
68
+ # Strict parsing
69
+ STRICT = 0
70
+
71
+ # Recover from errors. On by default for XML::Document, XML::DocumentFragment,
72
+ # HTML4::Document, HTML4::DocumentFragment, XSLT::Stylesheet, and XML::Schema.
73
+ RECOVER = 1 << 0
74
+
75
+ # Substitute entities. Off by default.
76
+ #
77
+ # ⚠ This option enables entity substitution, contrary to what the name implies.
78
+ #
79
+ # ⚠ <b>It is UNSAFE to set this option</b> when parsing untrusted documents.
80
+ NOENT = 1 << 1
81
+
82
+ # Load external subsets. On by default for XSLT::Stylesheet.
83
+ #
84
+ # ⚠ <b>It is UNSAFE to set this option</b> when parsing untrusted documents.
85
+ DTDLOAD = 1 << 2
86
+
87
+ # Default DTD attributes. On by default for XSLT::Stylesheet.
88
+ DTDATTR = 1 << 3
89
+
90
+ # Validate with the DTD. Off by default.
91
+ DTDVALID = 1 << 4
92
+
93
+ # Suppress error reports. On by default for HTML4::Document and HTML4::DocumentFragment
94
+ NOERROR = 1 << 5
95
+
96
+ # Suppress warning reports. On by default for HTML4::Document and HTML4::DocumentFragment
97
+ NOWARNING = 1 << 6
98
+
99
+ # Enable pedantic error reporting. Off by default.
100
+ PEDANTIC = 1 << 7
101
+
102
+ # Remove blank nodes. Off by default.
103
+ NOBLANKS = 1 << 8
104
+
105
+ # Use the SAX1 interface internally. Off by default.
106
+ SAX1 = 1 << 9
107
+
108
+ # Implement XInclude substitution. Off by default.
109
+ XINCLUDE = 1 << 10
110
+
111
+ # Forbid network access. On by default for XML::Document, XML::DocumentFragment,
112
+ # HTML4::Document, HTML4::DocumentFragment, XSLT::Stylesheet, and XML::Schema.
113
+ #
114
+ # ⚠ <b>It is UNSAFE to unset this option</b> when parsing untrusted documents.
115
+ NONET = 1 << 11
116
+
117
+ # Do not reuse the context dictionary. Off by default.
118
+ NODICT = 1 << 12
119
+
120
+ # Remove redundant namespaces declarations. Off by default.
121
+ NSCLEAN = 1 << 13
122
+
123
+ # Merge CDATA as text nodes. On by default for XSLT::Stylesheet.
124
+ NOCDATA = 1 << 14
125
+
126
+ # Do not generate XInclude START/END nodes. Off by default.
127
+ NOXINCNODE = 1 << 15
128
+
129
+ # Compact small text nodes. Off by default.
130
+ #
131
+ # ⚠ No modification of the DOM tree is allowed after parsing. libxml2 may crash if you try to
132
+ # modify the tree.
133
+ COMPACT = 1 << 16
134
+
135
+ # Parse using XML-1.0 before update 5. Off by default
136
+ OLD10 = 1 << 17
137
+
138
+ # Do not fixup XInclude xml:base uris. Off by default
139
+ NOBASEFIX = 1 << 18
140
+
141
+ # Relax any hardcoded limit from the parser. Off by default.
142
+ #
143
+ # ⚠ There may be a performance penalty when this option is set.
144
+ HUGE = 1 << 19
145
+
146
+ # Support line numbers up to <code>long int</code> (default is a <code>short int</code>). On
147
+ # by default for for XML::Document, XML::DocumentFragment, HTML4::Document,
148
+ # HTML4::DocumentFragment, XSLT::Stylesheet, and XML::Schema.
149
+ BIG_LINES = 1 << 22
150
+
151
+ # The options mask used by default for parsing XML::Document and XML::DocumentFragment
152
+ DEFAULT_XML = RECOVER | NONET | BIG_LINES
153
+
154
+ # The options mask used by default used for parsing XSLT::Stylesheet
155
+ DEFAULT_XSLT = RECOVER | NONET | NOENT | DTDLOAD | DTDATTR | NOCDATA | BIG_LINES
156
+
157
+ # The options mask used by default used for parsing HTML4::Document and HTML4::DocumentFragment
158
+ DEFAULT_HTML = RECOVER | NOERROR | NOWARNING | NONET | BIG_LINES
159
+
160
+ # The options mask used by default used for parsing XML::Schema
161
+ DEFAULT_SCHEMA = NONET | BIG_LINES
162
+
163
+ attr_accessor :options
164
+
165
+ def initialize(options = STRICT)
166
+ @options = options
167
+ end
168
+
169
+ constants.each do |constant|
170
+ next if constant.to_sym == :STRICT
171
+
172
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
173
+ def #{constant.downcase}
174
+ @options |= #{constant}
175
+ self
176
+ end
177
+
178
+ def no#{constant.downcase}
179
+ @options &= ~#{constant}
180
+ self
181
+ end
182
+
183
+ def #{constant.downcase}?
184
+ #{constant} & @options == #{constant}
185
+ end
186
+ RUBY
187
+ end
188
+
189
+ def strict
190
+ @options &= ~RECOVER
191
+ self
192
+ end
193
+
194
+ def strict?
195
+ @options & RECOVER == STRICT
196
+ end
197
+
198
+ def ==(other)
199
+ other.to_i == to_i
200
+ end
201
+
202
+ alias_method :to_i, :options
203
+
204
+ def inspect
205
+ options = []
206
+ self.class.constants.each do |k|
207
+ options << k.downcase if send(:"#{k.downcase}?")
208
+ end
209
+ super.sub(/>$/, " " + options.join(", ") + ">")
210
+ end
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ # :nodoc: all
6
+ module PP
7
+ module CharacterData
8
+ def pretty_print(pp)
9
+ nice_name = self.class.name.split("::").last
10
+ pp.group(2, "#(#{nice_name} ", ")") do
11
+ pp.pp(text)
12
+ end
13
+ end
14
+
15
+ def inspect
16
+ "#<#{self.class.name}:#{format("0x%x", object_id)} #{text.inspect}>"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end