nokogiri 1.18.0-arm-linux-musl

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 (203) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +39 -0
  3. data/LICENSE-DEPENDENCIES.md +2224 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +293 -0
  6. data/bin/nokogiri +131 -0
  7. data/dependencies.yml +42 -0
  8. data/ext/nokogiri/depend +38 -0
  9. data/ext/nokogiri/extconf.rb +1173 -0
  10. data/ext/nokogiri/gumbo.c +610 -0
  11. data/ext/nokogiri/html4_document.c +171 -0
  12. data/ext/nokogiri/html4_element_description.c +299 -0
  13. data/ext/nokogiri/html4_entity_lookup.c +37 -0
  14. data/ext/nokogiri/html4_sax_parser.c +40 -0
  15. data/ext/nokogiri/html4_sax_parser_context.c +98 -0
  16. data/ext/nokogiri/html4_sax_push_parser.c +96 -0
  17. data/ext/nokogiri/include/libexslt/exslt.h +108 -0
  18. data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
  19. data/ext/nokogiri/include/libexslt/exsltexports.h +63 -0
  20. data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +336 -0
  21. data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
  22. data/ext/nokogiri/include/libxml2/libxml/SAX.h +202 -0
  23. data/ext/nokogiri/include/libxml2/libxml/SAX2.h +171 -0
  24. data/ext/nokogiri/include/libxml2/libxml/c14n.h +115 -0
  25. data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
  26. data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
  27. data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
  28. data/ext/nokogiri/include/libxml2/libxml/dict.h +82 -0
  29. data/ext/nokogiri/include/libxml2/libxml/encoding.h +244 -0
  30. data/ext/nokogiri/include/libxml2/libxml/entities.h +166 -0
  31. data/ext/nokogiri/include/libxml2/libxml/globals.h +41 -0
  32. data/ext/nokogiri/include/libxml2/libxml/hash.h +251 -0
  33. data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
  34. data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +186 -0
  35. data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +98 -0
  36. data/ext/nokogiri/include/libxml2/libxml/parser.h +1390 -0
  37. data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +671 -0
  38. data/ext/nokogiri/include/libxml2/libxml/pattern.h +106 -0
  39. data/ext/nokogiri/include/libxml2/libxml/relaxng.h +219 -0
  40. data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +959 -0
  41. data/ext/nokogiri/include/libxml2/libxml/schematron.h +143 -0
  42. data/ext/nokogiri/include/libxml2/libxml/threads.h +87 -0
  43. data/ext/nokogiri/include/libxml2/libxml/tree.h +1382 -0
  44. data/ext/nokogiri/include/libxml2/libxml/uri.h +106 -0
  45. data/ext/nokogiri/include/libxml2/libxml/valid.h +477 -0
  46. data/ext/nokogiri/include/libxml2/libxml/xinclude.h +136 -0
  47. data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
  48. data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +438 -0
  49. data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
  50. data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +962 -0
  51. data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +146 -0
  52. data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +188 -0
  53. data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
  54. data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +436 -0
  55. data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +215 -0
  56. data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +102 -0
  57. data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +249 -0
  58. data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +152 -0
  59. data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
  60. data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +366 -0
  61. data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +347 -0
  62. data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +489 -0
  63. data/ext/nokogiri/include/libxml2/libxml/xpath.h +579 -0
  64. data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +633 -0
  65. data/ext/nokogiri/include/libxml2/libxml/xpointer.h +138 -0
  66. data/ext/nokogiri/include/libxslt/attributes.h +39 -0
  67. data/ext/nokogiri/include/libxslt/documents.h +93 -0
  68. data/ext/nokogiri/include/libxslt/extensions.h +262 -0
  69. data/ext/nokogiri/include/libxslt/extra.h +72 -0
  70. data/ext/nokogiri/include/libxslt/functions.h +78 -0
  71. data/ext/nokogiri/include/libxslt/imports.h +75 -0
  72. data/ext/nokogiri/include/libxslt/keys.h +53 -0
  73. data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
  74. data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
  75. data/ext/nokogiri/include/libxslt/pattern.h +84 -0
  76. data/ext/nokogiri/include/libxslt/preproc.h +43 -0
  77. data/ext/nokogiri/include/libxslt/security.h +104 -0
  78. data/ext/nokogiri/include/libxslt/templates.h +77 -0
  79. data/ext/nokogiri/include/libxslt/transform.h +207 -0
  80. data/ext/nokogiri/include/libxslt/variables.h +118 -0
  81. data/ext/nokogiri/include/libxslt/xslt.h +110 -0
  82. data/ext/nokogiri/include/libxslt/xsltInternals.h +1995 -0
  83. data/ext/nokogiri/include/libxslt/xsltconfig.h +146 -0
  84. data/ext/nokogiri/include/libxslt/xsltexports.h +64 -0
  85. data/ext/nokogiri/include/libxslt/xsltlocale.h +44 -0
  86. data/ext/nokogiri/include/libxslt/xsltutils.h +343 -0
  87. data/ext/nokogiri/libxml2_polyfill.c +114 -0
  88. data/ext/nokogiri/nokogiri.c +294 -0
  89. data/ext/nokogiri/nokogiri.h +238 -0
  90. data/ext/nokogiri/test_global_handlers.c +40 -0
  91. data/ext/nokogiri/xml_attr.c +103 -0
  92. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  93. data/ext/nokogiri/xml_cdata.c +62 -0
  94. data/ext/nokogiri/xml_comment.c +57 -0
  95. data/ext/nokogiri/xml_document.c +784 -0
  96. data/ext/nokogiri/xml_document_fragment.c +29 -0
  97. data/ext/nokogiri/xml_dtd.c +208 -0
  98. data/ext/nokogiri/xml_element_content.c +131 -0
  99. data/ext/nokogiri/xml_element_decl.c +69 -0
  100. data/ext/nokogiri/xml_encoding_handler.c +112 -0
  101. data/ext/nokogiri/xml_entity_decl.c +112 -0
  102. data/ext/nokogiri/xml_entity_reference.c +50 -0
  103. data/ext/nokogiri/xml_namespace.c +181 -0
  104. data/ext/nokogiri/xml_node.c +2459 -0
  105. data/ext/nokogiri/xml_node_set.c +518 -0
  106. data/ext/nokogiri/xml_processing_instruction.c +54 -0
  107. data/ext/nokogiri/xml_reader.c +777 -0
  108. data/ext/nokogiri/xml_relax_ng.c +149 -0
  109. data/ext/nokogiri/xml_sax_parser.c +403 -0
  110. data/ext/nokogiri/xml_sax_parser_context.c +390 -0
  111. data/ext/nokogiri/xml_sax_push_parser.c +206 -0
  112. data/ext/nokogiri/xml_schema.c +226 -0
  113. data/ext/nokogiri/xml_syntax_error.c +93 -0
  114. data/ext/nokogiri/xml_text.c +59 -0
  115. data/ext/nokogiri/xml_xpath_context.c +486 -0
  116. data/ext/nokogiri/xslt_stylesheet.c +421 -0
  117. data/gumbo-parser/CHANGES.md +63 -0
  118. data/gumbo-parser/Makefile +129 -0
  119. data/gumbo-parser/THANKS +27 -0
  120. data/lib/nokogiri/3.1/nokogiri.so +0 -0
  121. data/lib/nokogiri/3.2/nokogiri.so +0 -0
  122. data/lib/nokogiri/3.3/nokogiri.so +0 -0
  123. data/lib/nokogiri/3.4/nokogiri.so +0 -0
  124. data/lib/nokogiri/class_resolver.rb +67 -0
  125. data/lib/nokogiri/css/node.rb +58 -0
  126. data/lib/nokogiri/css/parser.rb +772 -0
  127. data/lib/nokogiri/css/parser.y +277 -0
  128. data/lib/nokogiri/css/parser_extras.rb +36 -0
  129. data/lib/nokogiri/css/selector_cache.rb +38 -0
  130. data/lib/nokogiri/css/syntax_error.rb +9 -0
  131. data/lib/nokogiri/css/tokenizer.rb +155 -0
  132. data/lib/nokogiri/css/tokenizer.rex +57 -0
  133. data/lib/nokogiri/css/xpath_visitor.rb +375 -0
  134. data/lib/nokogiri/css.rb +132 -0
  135. data/lib/nokogiri/decorators/slop.rb +42 -0
  136. data/lib/nokogiri/encoding_handler.rb +57 -0
  137. data/lib/nokogiri/extension.rb +32 -0
  138. data/lib/nokogiri/gumbo.rb +15 -0
  139. data/lib/nokogiri/html.rb +48 -0
  140. data/lib/nokogiri/html4/builder.rb +37 -0
  141. data/lib/nokogiri/html4/document.rb +235 -0
  142. data/lib/nokogiri/html4/document_fragment.rb +166 -0
  143. data/lib/nokogiri/html4/element_description.rb +25 -0
  144. data/lib/nokogiri/html4/element_description_defaults.rb +2040 -0
  145. data/lib/nokogiri/html4/encoding_reader.rb +121 -0
  146. data/lib/nokogiri/html4/entity_lookup.rb +15 -0
  147. data/lib/nokogiri/html4/sax/parser.rb +48 -0
  148. data/lib/nokogiri/html4/sax/parser_context.rb +15 -0
  149. data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
  150. data/lib/nokogiri/html4.rb +42 -0
  151. data/lib/nokogiri/html5/builder.rb +40 -0
  152. data/lib/nokogiri/html5/document.rb +199 -0
  153. data/lib/nokogiri/html5/document_fragment.rb +200 -0
  154. data/lib/nokogiri/html5/node.rb +103 -0
  155. data/lib/nokogiri/html5.rb +368 -0
  156. data/lib/nokogiri/jruby/dependencies.rb +3 -0
  157. data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
  158. data/lib/nokogiri/syntax_error.rb +6 -0
  159. data/lib/nokogiri/version/constant.rb +6 -0
  160. data/lib/nokogiri/version/info.rb +224 -0
  161. data/lib/nokogiri/version.rb +4 -0
  162. data/lib/nokogiri/xml/attr.rb +66 -0
  163. data/lib/nokogiri/xml/attribute_decl.rb +22 -0
  164. data/lib/nokogiri/xml/builder.rb +494 -0
  165. data/lib/nokogiri/xml/cdata.rb +13 -0
  166. data/lib/nokogiri/xml/character_data.rb +9 -0
  167. data/lib/nokogiri/xml/document.rb +514 -0
  168. data/lib/nokogiri/xml/document_fragment.rb +276 -0
  169. data/lib/nokogiri/xml/dtd.rb +34 -0
  170. data/lib/nokogiri/xml/element_content.rb +46 -0
  171. data/lib/nokogiri/xml/element_decl.rb +17 -0
  172. data/lib/nokogiri/xml/entity_decl.rb +23 -0
  173. data/lib/nokogiri/xml/entity_reference.rb +20 -0
  174. data/lib/nokogiri/xml/namespace.rb +57 -0
  175. data/lib/nokogiri/xml/node/save_options.rb +76 -0
  176. data/lib/nokogiri/xml/node.rb +1650 -0
  177. data/lib/nokogiri/xml/node_set.rb +449 -0
  178. data/lib/nokogiri/xml/notation.rb +19 -0
  179. data/lib/nokogiri/xml/parse_options.rb +213 -0
  180. data/lib/nokogiri/xml/pp/character_data.rb +21 -0
  181. data/lib/nokogiri/xml/pp/node.rb +73 -0
  182. data/lib/nokogiri/xml/pp.rb +4 -0
  183. data/lib/nokogiri/xml/processing_instruction.rb +11 -0
  184. data/lib/nokogiri/xml/reader.rb +139 -0
  185. data/lib/nokogiri/xml/relax_ng.rb +75 -0
  186. data/lib/nokogiri/xml/sax/document.rb +258 -0
  187. data/lib/nokogiri/xml/sax/parser.rb +199 -0
  188. data/lib/nokogiri/xml/sax/parser_context.rb +129 -0
  189. data/lib/nokogiri/xml/sax/push_parser.rb +64 -0
  190. data/lib/nokogiri/xml/sax.rb +54 -0
  191. data/lib/nokogiri/xml/schema.rb +140 -0
  192. data/lib/nokogiri/xml/searchable.rb +274 -0
  193. data/lib/nokogiri/xml/syntax_error.rb +94 -0
  194. data/lib/nokogiri/xml/text.rb +11 -0
  195. data/lib/nokogiri/xml/xpath/syntax_error.rb +13 -0
  196. data/lib/nokogiri/xml/xpath.rb +21 -0
  197. data/lib/nokogiri/xml/xpath_context.rb +27 -0
  198. data/lib/nokogiri/xml.rb +65 -0
  199. data/lib/nokogiri/xslt/stylesheet.rb +49 -0
  200. data/lib/nokogiri/xslt.rb +129 -0
  201. data/lib/nokogiri.rb +128 -0
  202. data/lib/xsd/xmlparser/nokogiri.rb +105 -0
  203. metadata +321 -0
@@ -0,0 +1,276 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Nokogiri
5
+ module XML
6
+ # DocumentFragment represents a fragment of an \XML document. It provides the same functionality
7
+ # exposed by XML::Node and can be used to contain one or more \XML subtrees.
8
+ class DocumentFragment < Nokogiri::XML::Node
9
+ # The options used to parse the document fragment. Returns the value of any options that were
10
+ # passed into the constructor as a parameter or set in a config block, else the default
11
+ # options for the specific subclass.
12
+ attr_reader :parse_options
13
+
14
+ class << self
15
+ # :call-seq:
16
+ # parse(input) { |options| ... } → XML::DocumentFragment
17
+ # parse(input, options:) → XML::DocumentFragment
18
+ #
19
+ # Parse \XML fragment input from a String, and return a new XML::DocumentFragment. This
20
+ # method creates a new, empty XML::Document to contain the fragment.
21
+ #
22
+ # [Required Parameters]
23
+ # - +input+ (String) The content to be parsed.
24
+ #
25
+ # [Optional Keyword Arguments]
26
+ # - +options+ (Nokogiri::XML::ParseOptions) Configuration object that determines some
27
+ # behaviors during parsing. See ParseOptions for more information. The default value is
28
+ # +ParseOptions::DEFAULT_XML+.
29
+ #
30
+ # [Yields]
31
+ # If a block is given, a Nokogiri::XML::ParseOptions object is yielded to the block which
32
+ # can be configured before parsing. See Nokogiri::XML::ParseOptions for more information.
33
+ #
34
+ # [Returns] Nokogiri::XML::DocumentFragment
35
+ def parse(tags, options_ = ParseOptions::DEFAULT_XML, options: options_, &block)
36
+ new(XML::Document.new, tags, options: options, &block)
37
+ end
38
+
39
+ # Wrapper method to separate the concerns of:
40
+ # - the native object allocator's parameter (it only requires `document`)
41
+ # - the initializer's parameters
42
+ def new(document, ...) # :nodoc:
43
+ instance = native_new(document)
44
+ instance.send(:initialize, document, ...)
45
+ instance
46
+ end
47
+ end
48
+
49
+ # :call-seq:
50
+ # new(document, input=nil) { |options| ... } → DocumentFragment
51
+ # new(document, input=nil, context:, options:) → DocumentFragment
52
+ #
53
+ # Parse \XML fragment input from a String, and return a new DocumentFragment that is
54
+ # associated with the given +document+.
55
+ #
56
+ # 💡 It's recommended to use either XML::DocumentFragment.parse or Node#parse rather than call
57
+ # this method directly.
58
+ #
59
+ # [Required Parameters]
60
+ # - +document+ (XML::Document) The parent document to associate the returned fragment with.
61
+ #
62
+ # [Optional Parameters]
63
+ # - +input+ (String) The content to be parsed.
64
+ #
65
+ # [Optional Keyword Arguments]
66
+ # - +context:+ (Nokogiri::XML::Node) The <b>context node</b> for the subtree created. See
67
+ # below for more information.
68
+ #
69
+ # - +options:+ (Nokogiri::XML::ParseOptions) Configuration object that determines some
70
+ # behaviors during parsing. See ParseOptions for more information. The default value is
71
+ # +ParseOptions::DEFAULT_XML+.
72
+ #
73
+ # [Yields]
74
+ # If a block is given, a Nokogiri::XML::ParseOptions object is yielded to the block which
75
+ # can be configured before parsing. See ParseOptions for more information.
76
+ #
77
+ # [Returns] XML::DocumentFragment
78
+ #
79
+ # === Context \Node
80
+ #
81
+ # If a context node is specified using +context:+, then the fragment will be created by
82
+ # calling Node#parse on that node, so the parser will behave as if that Node is the parent of
83
+ # the fragment subtree, and will resolve namespaces relative to that node.
84
+ #
85
+ def initialize(
86
+ document, tags = nil,
87
+ context_ = nil, options_ = ParseOptions::DEFAULT_XML,
88
+ context: context_, options: options_
89
+ ) # rubocop:disable Lint/MissingSuper
90
+ return self unless tags
91
+
92
+ options = Nokogiri::XML::ParseOptions.new(options) if Integer === options
93
+ @parse_options = options
94
+ yield options if block_given?
95
+
96
+ children = if context
97
+ # Fix for issue#490
98
+ if Nokogiri.jruby?
99
+ # fix for issue #770
100
+ context.parse("<root #{namespace_declarations(context)}>#{tags}</root>", options).children
101
+ else
102
+ context.parse(tags, options)
103
+ end
104
+ else
105
+ wrapper_doc = XML::Document.parse("<root>#{tags}</root>", nil, nil, options)
106
+ self.errors = wrapper_doc.errors
107
+ wrapper_doc.xpath("/root/node()")
108
+ end
109
+ children.each { |child| child.parent = self }
110
+ end
111
+
112
+ if Nokogiri.uses_libxml?
113
+ def dup
114
+ new_document = document.dup
115
+ new_fragment = self.class.new(new_document)
116
+ children.each do |child|
117
+ child.dup(1, new_document).parent = new_fragment
118
+ end
119
+ new_fragment
120
+ end
121
+ end
122
+
123
+ ###
124
+ # return the name for DocumentFragment
125
+ def name
126
+ "#document-fragment"
127
+ end
128
+
129
+ ###
130
+ # Convert this DocumentFragment to a string
131
+ def to_s
132
+ children.to_s
133
+ end
134
+
135
+ ###
136
+ # Convert this DocumentFragment to html
137
+ # See Nokogiri::XML::NodeSet#to_html
138
+ def to_html(*args)
139
+ if Nokogiri.jruby?
140
+ options = args.first.is_a?(Hash) ? args.shift : {}
141
+ options[:save_with] ||= Node::SaveOptions::DEFAULT_HTML
142
+ args.insert(0, options)
143
+ end
144
+ children.to_html(*args)
145
+ end
146
+
147
+ ###
148
+ # Convert this DocumentFragment to xhtml
149
+ # See Nokogiri::XML::NodeSet#to_xhtml
150
+ def to_xhtml(*args)
151
+ if Nokogiri.jruby?
152
+ options = args.first.is_a?(Hash) ? args.shift : {}
153
+ options[:save_with] ||= Node::SaveOptions::DEFAULT_XHTML
154
+ args.insert(0, options)
155
+ end
156
+ children.to_xhtml(*args)
157
+ end
158
+
159
+ ###
160
+ # Convert this DocumentFragment to xml
161
+ # See Nokogiri::XML::NodeSet#to_xml
162
+ def to_xml(*args)
163
+ children.to_xml(*args)
164
+ end
165
+
166
+ ###
167
+ # call-seq: css *rules, [namespace-bindings, custom-pseudo-class]
168
+ #
169
+ # Search this fragment for CSS +rules+. +rules+ must be one or more CSS
170
+ # selectors. For example:
171
+ #
172
+ # For more information see Nokogiri::XML::Searchable#css
173
+ def css(*args)
174
+ if children.any?
175
+ children.css(*args) # 'children' is a smell here
176
+ else
177
+ NodeSet.new(document)
178
+ end
179
+ end
180
+
181
+ #
182
+ # NOTE that we don't delegate #xpath to children ... another smell.
183
+ # def xpath ; end
184
+ #
185
+
186
+ ###
187
+ # call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
188
+ #
189
+ # Search this fragment for +paths+. +paths+ must be one or more XPath or CSS queries.
190
+ #
191
+ # For more information see Nokogiri::XML::Searchable#search
192
+ def search(*rules)
193
+ rules, handler, ns, binds = extract_params(rules)
194
+
195
+ rules.inject(NodeSet.new(document)) do |set, rule|
196
+ set + if Searchable::LOOKS_LIKE_XPATH.match?(rule)
197
+ xpath(*[rule, ns, handler, binds].compact)
198
+ else
199
+ children.css(*[rule, ns, handler].compact) # 'children' is a smell here
200
+ end
201
+ end
202
+ end
203
+
204
+ alias_method :serialize, :to_s
205
+
206
+ # A list of Nokogiri::XML::SyntaxError found when parsing a document
207
+ def errors
208
+ document.errors
209
+ end
210
+
211
+ def errors=(things) # :nodoc:
212
+ document.errors = things
213
+ end
214
+
215
+ def fragment(data)
216
+ document.fragment(data)
217
+ end
218
+
219
+ #
220
+ # :call-seq: deconstruct() → Array
221
+ #
222
+ # Returns the root nodes of this document fragment as an array, to use in pattern matching.
223
+ #
224
+ # 💡 Note that text nodes are returned as well as elements. If you wish to operate only on
225
+ # root elements, you should deconstruct the array returned by
226
+ # <tt>DocumentFragment#elements</tt>.
227
+ #
228
+ # *Example*
229
+ #
230
+ # frag = Nokogiri::HTML5.fragment(<<~HTML)
231
+ # <div>Start</div>
232
+ # This is a <a href="#jump">shortcut</a> for you.
233
+ # <div>End</div>
234
+ # HTML
235
+ #
236
+ # frag.deconstruct
237
+ # # => [#(Element:0x35c { name = "div", children = [ #(Text "Start")] }),
238
+ # # #(Text "\n" + "This is a "),
239
+ # # #(Element:0x370 {
240
+ # # name = "a",
241
+ # # attributes = [ #(Attr:0x384 { name = "href", value = "#jump" })],
242
+ # # children = [ #(Text "shortcut")]
243
+ # # }),
244
+ # # #(Text " for you.\n"),
245
+ # # #(Element:0x398 { name = "div", children = [ #(Text "End")] }),
246
+ # # #(Text "\n")]
247
+ #
248
+ # *Example* only the elements, not the text nodes.
249
+ #
250
+ # frag.elements.deconstruct
251
+ # # => [#(Element:0x35c { name = "div", children = [ #(Text "Start")] }),
252
+ # # #(Element:0x370 {
253
+ # # name = "a",
254
+ # # attributes = [ #(Attr:0x384 { name = "href", value = "#jump" })],
255
+ # # children = [ #(Text "shortcut")]
256
+ # # }),
257
+ # # #(Element:0x398 { name = "div", children = [ #(Text "End")] })]
258
+ #
259
+ # Since v1.14.0
260
+ #
261
+ def deconstruct
262
+ children.to_a
263
+ end
264
+
265
+ private
266
+
267
+ # fix for issue 770
268
+ def namespace_declarations(ctx)
269
+ ctx.namespace_scopes.map do |namespace|
270
+ prefix = namespace.prefix.nil? ? "" : ":#{namespace.prefix}"
271
+ %{xmlns#{prefix}="#{namespace.href}"}
272
+ end.join(" ")
273
+ end
274
+ end
275
+ end
276
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class DTD < Nokogiri::XML::Node
6
+ undef_method :attribute_nodes
7
+ undef_method :values
8
+ undef_method :content
9
+ undef_method :namespace
10
+ undef_method :namespace_definitions
11
+ undef_method :line if method_defined?(:line)
12
+
13
+ def keys
14
+ attributes.keys
15
+ end
16
+
17
+ def each
18
+ attributes.each do |key, value|
19
+ yield([key, value])
20
+ end
21
+ end
22
+
23
+ def html_dtd?
24
+ name.casecmp("html").zero?
25
+ end
26
+
27
+ def html5_dtd?
28
+ html_dtd? &&
29
+ external_id.nil? &&
30
+ (system_id.nil? || system_id == "about:legacy-compat")
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ ###
6
+ # Represents the allowed content in an Element Declaration inside a DTD:
7
+ #
8
+ # <?xml version="1.0"?><?TEST-STYLE PIDATA?>
9
+ # <!DOCTYPE staff SYSTEM "staff.dtd" [
10
+ # <!ELEMENT div1 (head, (p | list | note)*, div2*)>
11
+ # ]>
12
+ # </root>
13
+ #
14
+ # ElementContent represents the binary tree inside the <!ELEMENT> tag shown above that lists the
15
+ # possible content for the div1 tag.
16
+ class ElementContent
17
+ include Nokogiri::XML::PP::Node
18
+
19
+ # Possible definitions of type
20
+ PCDATA = 1
21
+ ELEMENT = 2
22
+ SEQ = 3
23
+ OR = 4
24
+
25
+ # Possible content occurrences
26
+ ONCE = 1
27
+ OPT = 2
28
+ MULT = 3
29
+ PLUS = 4
30
+
31
+ attr_reader :document
32
+
33
+ ###
34
+ # Get the children of this ElementContent node
35
+ def children
36
+ [c1, c2].compact
37
+ end
38
+
39
+ private
40
+
41
+ def inspect_attributes
42
+ [:prefix, :name, :type, :occur, :children]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class ElementDecl < Nokogiri::XML::Node
6
+ undef_method :namespace
7
+ undef_method :namespace_definitions
8
+ undef_method :line if method_defined?(:line)
9
+
10
+ private
11
+
12
+ def inspect_attributes
13
+ [:to_s]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class EntityDecl < Nokogiri::XML::Node
6
+ undef_method :attribute_nodes
7
+ undef_method :attributes
8
+ undef_method :namespace
9
+ undef_method :namespace_definitions
10
+ undef_method :line if method_defined?(:line)
11
+
12
+ def self.new(name, doc, *args)
13
+ doc.create_entity(name, *args)
14
+ end
15
+
16
+ private
17
+
18
+ def inspect_attributes
19
+ [:to_s]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class EntityReference < Nokogiri::XML::Node
6
+ def children
7
+ # libxml2 will create a malformed child node for predefined
8
+ # entities. because any use of that child is likely to cause a
9
+ # segfault, we shall pretend that it doesn't exist.
10
+ #
11
+ # see https://github.com/sparklemotion/nokogiri/issues/1238 for details
12
+ NodeSet.new(document)
13
+ end
14
+
15
+ def inspect_attributes
16
+ [:name]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,57 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Nokogiri
5
+ module XML
6
+ class Namespace
7
+ include Nokogiri::XML::PP::Node
8
+ attr_reader :document
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
+ # *Example*
20
+ #
21
+ # doc = Nokogiri::XML.parse(<<~XML)
22
+ # <?xml version="1.0"?>
23
+ # <root xmlns="http://nokogiri.org/ns/default" xmlns:noko="http://nokogiri.org/ns/noko">
24
+ # <child1 foo="abc" noko:bar="def"/>
25
+ # <noko:child2 foo="qwe" noko:bar="rty"/>
26
+ # </root>
27
+ # XML
28
+ #
29
+ # doc.root.elements.first.namespace
30
+ # # => #(Namespace:0x35c { href = "http://nokogiri.org/ns/default" })
31
+ #
32
+ # doc.root.elements.first.namespace.deconstruct_keys([:prefix, :href])
33
+ # # => {:prefix=>nil, :href=>"http://nokogiri.org/ns/default"}
34
+ #
35
+ # doc.root.elements.last.namespace
36
+ # # => #(Namespace:0x370 {
37
+ # # prefix = "noko",
38
+ # # href = "http://nokogiri.org/ns/noko"
39
+ # # })
40
+ #
41
+ # doc.root.elements.last.namespace.deconstruct_keys([:prefix, :href])
42
+ # # => {:prefix=>"noko", :href=>"http://nokogiri.org/ns/noko"}
43
+ #
44
+ # Since v1.14.0
45
+ #
46
+ def deconstruct_keys(keys)
47
+ { prefix: prefix, href: href }
48
+ end
49
+
50
+ private
51
+
52
+ def inspect_attributes
53
+ [:prefix, :href]
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class Node
6
+ ###
7
+ # Save options for serializing nodes.
8
+ # See the method group entitled Node@Serialization+and+Generating+Output for usage.
9
+ class SaveOptions
10
+ # Format serialized xml
11
+ FORMAT = 1
12
+ # Do not include declarations
13
+ NO_DECLARATION = 2
14
+ # Do not include empty tags
15
+ NO_EMPTY_TAGS = 4
16
+ # Do not save XHTML
17
+ NO_XHTML = 8
18
+ # Save as XHTML
19
+ AS_XHTML = 16
20
+ # Save as XML
21
+ AS_XML = 32
22
+ # Save as HTML
23
+ AS_HTML = 64
24
+
25
+ if Nokogiri.jruby?
26
+ # Save builder created document
27
+ AS_BUILDER = 128
28
+ # the default for XML documents
29
+ DEFAULT_XML = AS_XML # https://github.com/sparklemotion/nokogiri/issues/#issue/415
30
+ # the default for HTML document
31
+ DEFAULT_HTML = NO_DECLARATION | NO_EMPTY_TAGS | AS_HTML
32
+ # the default for XHTML document
33
+ DEFAULT_XHTML = NO_DECLARATION | AS_XHTML
34
+ else
35
+ # the default for XML documents
36
+ DEFAULT_XML = FORMAT | AS_XML
37
+ # the default for HTML document
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
41
+ end
42
+
43
+ # Integer representation of the SaveOptions
44
+ attr_reader :options
45
+
46
+ # Create a new SaveOptions object with +options+
47
+ def initialize(options = 0)
48
+ @options = options
49
+ end
50
+
51
+ constants.each do |constant|
52
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
53
+ def #{constant.downcase}
54
+ @options |= #{constant}
55
+ self
56
+ end
57
+
58
+ def #{constant.downcase}?
59
+ #{constant} & @options == #{constant}
60
+ end
61
+ RUBY
62
+ end
63
+
64
+ alias_method :to_i, :options
65
+
66
+ def inspect
67
+ options = []
68
+ self.class.constants.each do |k|
69
+ options << k.downcase if send(:"#{k.downcase}?")
70
+ end
71
+ super.sub(/>$/, " " + options.join(", ") + ">")
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end