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.
- checksums.yaml +7 -0
- data/LICENSE-DEPENDENCIES.md +1614 -0
- data/LICENSE.md +9 -0
- data/README.md +200 -0
- data/bin/nokogiri +118 -0
- data/dependencies.yml +74 -0
- data/ext/nokogiri/depend +358 -0
- data/ext/nokogiri/extconf.rb +695 -0
- data/ext/nokogiri/html_document.c +170 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +279 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +32 -0
- data/ext/nokogiri/html_entity_lookup.h +8 -0
- data/ext/nokogiri/html_sax_parser_context.c +116 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/html_sax_push_parser.c +87 -0
- data/ext/nokogiri/html_sax_push_parser.h +9 -0
- data/ext/nokogiri/nokogiri.c +147 -0
- data/ext/nokogiri/nokogiri.h +122 -0
- data/ext/nokogiri/xml_attr.c +103 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +62 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +69 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +617 -0
- data/ext/nokogiri/xml_document.h +23 -0
- data/ext/nokogiri/xml_document_fragment.c +48 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +202 -0
- data/ext/nokogiri/xml_dtd.h +10 -0
- data/ext/nokogiri/xml_element_content.c +123 -0
- data/ext/nokogiri/xml_element_content.h +10 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_element_decl.h +9 -0
- data/ext/nokogiri/xml_encoding_handler.c +79 -0
- data/ext/nokogiri/xml_encoding_handler.h +8 -0
- data/ext/nokogiri/xml_entity_decl.c +110 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +52 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +61 -0
- data/ext/nokogiri/xml_io.h +11 -0
- data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
- data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
- data/ext/nokogiri/xml_namespace.c +111 -0
- data/ext/nokogiri/xml_namespace.h +14 -0
- data/ext/nokogiri/xml_node.c +1773 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +486 -0
- data/ext/nokogiri/xml_node_set.h +12 -0
- data/ext/nokogiri/xml_processing_instruction.c +56 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +668 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +161 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +310 -0
- data/ext/nokogiri/xml_sax_parser.h +39 -0
- data/ext/nokogiri/xml_sax_parser_context.c +262 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +159 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +205 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +64 -0
- data/ext/nokogiri/xml_syntax_error.h +13 -0
- data/ext/nokogiri/xml_text.c +52 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath_context.c +298 -0
- data/ext/nokogiri/xml_xpath_context.h +10 -0
- data/ext/nokogiri/xslt_stylesheet.c +266 -0
- data/ext/nokogiri/xslt_stylesheet.h +14 -0
- data/lib/nokogiri.rb +127 -0
- data/lib/nokogiri/2.4/nokogiri.so +0 -0
- data/lib/nokogiri/2.5/nokogiri.so +0 -0
- data/lib/nokogiri/2.6/nokogiri.so +0 -0
- data/lib/nokogiri/2.7/nokogiri.so +0 -0
- data/lib/nokogiri/css.rb +28 -0
- data/lib/nokogiri/css/node.rb +53 -0
- data/lib/nokogiri/css/parser.rb +751 -0
- data/lib/nokogiri/css/parser.y +272 -0
- data/lib/nokogiri/css/parser_extras.rb +92 -0
- data/lib/nokogiri/css/syntax_error.rb +8 -0
- data/lib/nokogiri/css/tokenizer.rb +154 -0
- data/lib/nokogiri/css/tokenizer.rex +55 -0
- data/lib/nokogiri/css/xpath_visitor.rb +232 -0
- data/lib/nokogiri/decorators/slop.rb +43 -0
- data/lib/nokogiri/html.rb +38 -0
- data/lib/nokogiri/html/builder.rb +36 -0
- data/lib/nokogiri/html/document.rb +336 -0
- data/lib/nokogiri/html/document_fragment.rb +50 -0
- data/lib/nokogiri/html/element_description.rb +24 -0
- data/lib/nokogiri/html/element_description_defaults.rb +672 -0
- data/lib/nokogiri/html/entity_lookup.rb +14 -0
- data/lib/nokogiri/html/sax/parser.rb +63 -0
- data/lib/nokogiri/html/sax/parser_context.rb +17 -0
- data/lib/nokogiri/html/sax/push_parser.rb +37 -0
- data/lib/nokogiri/jruby/dependencies.rb +20 -0
- data/lib/nokogiri/syntax_error.rb +5 -0
- data/lib/nokogiri/version.rb +149 -0
- data/lib/nokogiri/xml.rb +76 -0
- data/lib/nokogiri/xml/attr.rb +15 -0
- data/lib/nokogiri/xml/attribute_decl.rb +19 -0
- data/lib/nokogiri/xml/builder.rb +447 -0
- data/lib/nokogiri/xml/cdata.rb +12 -0
- data/lib/nokogiri/xml/character_data.rb +8 -0
- data/lib/nokogiri/xml/document.rb +280 -0
- data/lib/nokogiri/xml/document_fragment.rb +161 -0
- data/lib/nokogiri/xml/dtd.rb +33 -0
- data/lib/nokogiri/xml/element_content.rb +37 -0
- data/lib/nokogiri/xml/element_decl.rb +14 -0
- data/lib/nokogiri/xml/entity_decl.rb +20 -0
- data/lib/nokogiri/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/xml/namespace.rb +14 -0
- data/lib/nokogiri/xml/node.rb +916 -0
- data/lib/nokogiri/xml/node/save_options.rb +62 -0
- data/lib/nokogiri/xml/node_set.rb +372 -0
- data/lib/nokogiri/xml/notation.rb +7 -0
- data/lib/nokogiri/xml/parse_options.rb +121 -0
- data/lib/nokogiri/xml/pp.rb +3 -0
- data/lib/nokogiri/xml/pp/character_data.rb +19 -0
- data/lib/nokogiri/xml/pp/node.rb +57 -0
- data/lib/nokogiri/xml/processing_instruction.rb +9 -0
- data/lib/nokogiri/xml/reader.rb +116 -0
- data/lib/nokogiri/xml/relax_ng.rb +33 -0
- data/lib/nokogiri/xml/sax.rb +5 -0
- data/lib/nokogiri/xml/sax/document.rb +172 -0
- data/lib/nokogiri/xml/sax/parser.rb +123 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
- data/lib/nokogiri/xml/schema.rb +64 -0
- data/lib/nokogiri/xml/searchable.rb +231 -0
- data/lib/nokogiri/xml/syntax_error.rb +71 -0
- data/lib/nokogiri/xml/text.rb +10 -0
- data/lib/nokogiri/xml/xpath.rb +11 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
- data/lib/nokogiri/xml/xpath_context.rb +17 -0
- data/lib/nokogiri/xslt.rb +57 -0
- data/lib/nokogiri/xslt/stylesheet.rb +26 -0
- data/lib/xsd/xmlparser/nokogiri.rb +103 -0
- metadata +482 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
#ifndef NOKOGIRI_XML_XPATH_CONTEXT
|
2
|
+
#define NOKOGIRI_XML_XPATH_CONTEXT
|
3
|
+
|
4
|
+
#include <nokogiri.h>
|
5
|
+
|
6
|
+
void init_xml_xpath_context();
|
7
|
+
void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr ctx, int nargs, VALUE handler, const char* function_name) ;
|
8
|
+
|
9
|
+
extern VALUE cNokogiriXmlXpathContext;
|
10
|
+
#endif
|
@@ -0,0 +1,266 @@
|
|
1
|
+
#include <xslt_stylesheet.h>
|
2
|
+
|
3
|
+
#include <libxslt/xsltInternals.h>
|
4
|
+
#include <libxslt/xsltutils.h>
|
5
|
+
#include <libxslt/transform.h>
|
6
|
+
#include <libexslt/exslt.h>
|
7
|
+
|
8
|
+
VALUE xslt;
|
9
|
+
|
10
|
+
int vasprintf (char **strp, const char *fmt, va_list ap);
|
11
|
+
void vasprintf_free (void *p);
|
12
|
+
|
13
|
+
static void mark(nokogiriXsltStylesheetTuple *wrapper)
|
14
|
+
{
|
15
|
+
rb_gc_mark(wrapper->func_instances);
|
16
|
+
}
|
17
|
+
|
18
|
+
static void dealloc(nokogiriXsltStylesheetTuple *wrapper)
|
19
|
+
{
|
20
|
+
xsltStylesheetPtr doc = wrapper->ss;
|
21
|
+
|
22
|
+
NOKOGIRI_DEBUG_START(doc);
|
23
|
+
xsltFreeStylesheet(doc); /* commented out for now. */
|
24
|
+
NOKOGIRI_DEBUG_END(doc);
|
25
|
+
|
26
|
+
free(wrapper);
|
27
|
+
}
|
28
|
+
|
29
|
+
static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
|
30
|
+
{
|
31
|
+
char * message;
|
32
|
+
|
33
|
+
va_list args;
|
34
|
+
va_start(args, msg);
|
35
|
+
vasprintf(&message, msg, args);
|
36
|
+
va_end(args);
|
37
|
+
|
38
|
+
rb_str_cat2((VALUE)ctx, message);
|
39
|
+
|
40
|
+
vasprintf_free(message);
|
41
|
+
}
|
42
|
+
|
43
|
+
VALUE Nokogiri_wrap_xslt_stylesheet(xsltStylesheetPtr ss)
|
44
|
+
{
|
45
|
+
VALUE self;
|
46
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
47
|
+
|
48
|
+
self = Data_Make_Struct(cNokogiriXsltStylesheet, nokogiriXsltStylesheetTuple,
|
49
|
+
mark, dealloc, wrapper);
|
50
|
+
|
51
|
+
ss->_private = (void *)self;
|
52
|
+
wrapper->ss = ss;
|
53
|
+
wrapper->func_instances = rb_ary_new();
|
54
|
+
|
55
|
+
return self;
|
56
|
+
}
|
57
|
+
|
58
|
+
/*
|
59
|
+
* call-seq:
|
60
|
+
* parse_stylesheet_doc(document)
|
61
|
+
*
|
62
|
+
* Parse a stylesheet from +document+.
|
63
|
+
*/
|
64
|
+
static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
|
65
|
+
{
|
66
|
+
xmlDocPtr xml, xml_cpy;
|
67
|
+
VALUE errstr, exception;
|
68
|
+
xsltStylesheetPtr ss ;
|
69
|
+
Data_Get_Struct(xmldocobj, xmlDoc, xml);
|
70
|
+
exsltRegisterAll();
|
71
|
+
|
72
|
+
errstr = rb_str_new(0, 0);
|
73
|
+
xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
|
74
|
+
|
75
|
+
xml_cpy = xmlCopyDoc(xml, 1); /* 1 => recursive */
|
76
|
+
ss = xsltParseStylesheetDoc(xml_cpy);
|
77
|
+
|
78
|
+
xsltSetGenericErrorFunc(NULL, NULL);
|
79
|
+
|
80
|
+
if (!ss) {
|
81
|
+
xmlFreeDoc(xml_cpy);
|
82
|
+
exception = rb_exc_new3(rb_eRuntimeError, errstr);
|
83
|
+
rb_exc_raise(exception);
|
84
|
+
}
|
85
|
+
|
86
|
+
return Nokogiri_wrap_xslt_stylesheet(ss);
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
/*
|
91
|
+
* call-seq:
|
92
|
+
* serialize(document)
|
93
|
+
*
|
94
|
+
* Serialize +document+ to an xml string.
|
95
|
+
*/
|
96
|
+
static VALUE serialize(VALUE self, VALUE xmlobj)
|
97
|
+
{
|
98
|
+
xmlDocPtr xml ;
|
99
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
100
|
+
xmlChar* doc_ptr ;
|
101
|
+
int doc_len ;
|
102
|
+
VALUE rval ;
|
103
|
+
|
104
|
+
Data_Get_Struct(xmlobj, xmlDoc, xml);
|
105
|
+
Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
|
106
|
+
xsltSaveResultToString(&doc_ptr, &doc_len, xml, wrapper->ss);
|
107
|
+
rval = NOKOGIRI_STR_NEW(doc_ptr, doc_len);
|
108
|
+
xmlFree(doc_ptr);
|
109
|
+
return rval ;
|
110
|
+
}
|
111
|
+
|
112
|
+
/*
|
113
|
+
* call-seq:
|
114
|
+
* transform(document, params = [])
|
115
|
+
*
|
116
|
+
* Apply an XSLT stylesheet to an XML::Document.
|
117
|
+
* +params+ is an array of strings used as XSLT parameters.
|
118
|
+
* returns Nokogiri::XML::Document
|
119
|
+
*
|
120
|
+
* Example:
|
121
|
+
*
|
122
|
+
* doc = Nokogiri::XML(File.read(ARGV[0]))
|
123
|
+
* xslt = Nokogiri::XSLT(File.read(ARGV[1]))
|
124
|
+
* puts xslt.transform(doc, ['key', 'value'])
|
125
|
+
*
|
126
|
+
*/
|
127
|
+
static VALUE transform(int argc, VALUE* argv, VALUE self)
|
128
|
+
{
|
129
|
+
VALUE xmldoc, paramobj, errstr, exception ;
|
130
|
+
xmlDocPtr xml ;
|
131
|
+
xmlDocPtr result ;
|
132
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
133
|
+
const char** params ;
|
134
|
+
long param_len, j ;
|
135
|
+
int parse_error_occurred ;
|
136
|
+
|
137
|
+
rb_scan_args(argc, argv, "11", &xmldoc, ¶mobj);
|
138
|
+
if (NIL_P(paramobj)) { paramobj = rb_ary_new2(0L) ; }
|
139
|
+
if (!rb_obj_is_kind_of(xmldoc, cNokogiriXmlDocument))
|
140
|
+
rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::Document");
|
141
|
+
|
142
|
+
/* handle hashes as arguments. */
|
143
|
+
if(T_HASH == TYPE(paramobj)) {
|
144
|
+
paramobj = rb_funcall(paramobj, rb_intern("to_a"), 0);
|
145
|
+
paramobj = rb_funcall(paramobj, rb_intern("flatten"), 0);
|
146
|
+
}
|
147
|
+
|
148
|
+
Check_Type(paramobj, T_ARRAY);
|
149
|
+
|
150
|
+
Data_Get_Struct(xmldoc, xmlDoc, xml);
|
151
|
+
Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
|
152
|
+
|
153
|
+
param_len = RARRAY_LEN(paramobj);
|
154
|
+
params = calloc((size_t)param_len+1, sizeof(char*));
|
155
|
+
for (j = 0 ; j < param_len ; j++) {
|
156
|
+
VALUE entry = rb_ary_entry(paramobj, j);
|
157
|
+
const char * ptr = StringValueCStr(entry);
|
158
|
+
params[j] = ptr;
|
159
|
+
}
|
160
|
+
params[param_len] = 0 ;
|
161
|
+
|
162
|
+
errstr = rb_str_new(0, 0);
|
163
|
+
xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
|
164
|
+
xmlSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
|
165
|
+
|
166
|
+
result = xsltApplyStylesheet(wrapper->ss, xml, params);
|
167
|
+
free(params);
|
168
|
+
|
169
|
+
xsltSetGenericErrorFunc(NULL, NULL);
|
170
|
+
xmlSetGenericErrorFunc(NULL, NULL);
|
171
|
+
|
172
|
+
parse_error_occurred = (Qfalse == rb_funcall(errstr, rb_intern("empty?"), 0));
|
173
|
+
|
174
|
+
if (parse_error_occurred) {
|
175
|
+
exception = rb_exc_new3(rb_eRuntimeError, errstr);
|
176
|
+
rb_exc_raise(exception);
|
177
|
+
}
|
178
|
+
|
179
|
+
return Nokogiri_wrap_xml_document((VALUE)0, result) ;
|
180
|
+
}
|
181
|
+
|
182
|
+
static void method_caller(xmlXPathParserContextPtr ctxt, int nargs)
|
183
|
+
{
|
184
|
+
VALUE handler;
|
185
|
+
const char *function_name;
|
186
|
+
xsltTransformContextPtr transform;
|
187
|
+
const xmlChar *functionURI;
|
188
|
+
|
189
|
+
transform = xsltXPathGetTransformContext(ctxt);
|
190
|
+
functionURI = ctxt->context->functionURI;
|
191
|
+
handler = (VALUE)xsltGetExtData(transform, functionURI);
|
192
|
+
function_name = (const char*)(ctxt->context->function);
|
193
|
+
|
194
|
+
Nokogiri_marshal_xpath_funcall_and_return_values(ctxt, nargs, handler, (const char*)function_name);
|
195
|
+
}
|
196
|
+
|
197
|
+
static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri)
|
198
|
+
{
|
199
|
+
VALUE modules = rb_iv_get(xslt, "@modules");
|
200
|
+
VALUE obj = rb_hash_aref(modules, rb_str_new2((const char *)uri));
|
201
|
+
VALUE args = { Qfalse };
|
202
|
+
VALUE methods = rb_funcall(obj, rb_intern("instance_methods"), 1, args);
|
203
|
+
VALUE inst;
|
204
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
205
|
+
int i;
|
206
|
+
|
207
|
+
for(i = 0; i < RARRAY_LEN(methods); i++) {
|
208
|
+
VALUE method_name = rb_obj_as_string(rb_ary_entry(methods, i));
|
209
|
+
xsltRegisterExtFunction(ctxt,
|
210
|
+
(unsigned char *)StringValueCStr(method_name), uri, method_caller);
|
211
|
+
}
|
212
|
+
|
213
|
+
Data_Get_Struct((VALUE)ctxt->style->_private, nokogiriXsltStylesheetTuple,
|
214
|
+
wrapper);
|
215
|
+
inst = rb_class_new_instance(0, NULL, obj);
|
216
|
+
rb_ary_push(wrapper->func_instances, inst);
|
217
|
+
|
218
|
+
return (void *)inst;
|
219
|
+
}
|
220
|
+
|
221
|
+
static void shutdownFunc(xsltTransformContextPtr ctxt,
|
222
|
+
const xmlChar *uri, void *data)
|
223
|
+
{
|
224
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
225
|
+
|
226
|
+
Data_Get_Struct((VALUE)ctxt->style->_private, nokogiriXsltStylesheetTuple,
|
227
|
+
wrapper);
|
228
|
+
|
229
|
+
rb_ary_clear(wrapper->func_instances);
|
230
|
+
}
|
231
|
+
|
232
|
+
/*
|
233
|
+
* call-seq:
|
234
|
+
* register(uri, custom_handler_class)
|
235
|
+
*
|
236
|
+
* Register a class that implements custom XSLT transformation functions.
|
237
|
+
*/
|
238
|
+
static VALUE registr(VALUE self, VALUE uri, VALUE obj)
|
239
|
+
{
|
240
|
+
VALUE modules = rb_iv_get(self, "@modules");
|
241
|
+
if(NIL_P(modules)) rb_raise(rb_eRuntimeError, "wtf! @modules isn't set");
|
242
|
+
|
243
|
+
rb_hash_aset(modules, uri, obj);
|
244
|
+
xsltRegisterExtModule((unsigned char *)StringValueCStr(uri), initFunc, shutdownFunc);
|
245
|
+
return self;
|
246
|
+
}
|
247
|
+
|
248
|
+
VALUE cNokogiriXsltStylesheet ;
|
249
|
+
void init_xslt_stylesheet()
|
250
|
+
{
|
251
|
+
VALUE nokogiri;
|
252
|
+
VALUE klass;
|
253
|
+
|
254
|
+
nokogiri = rb_define_module("Nokogiri");
|
255
|
+
xslt = rb_define_module_under(nokogiri, "XSLT");
|
256
|
+
klass = rb_define_class_under(xslt, "Stylesheet", rb_cObject);
|
257
|
+
|
258
|
+
rb_iv_set(xslt, "@modules", rb_hash_new());
|
259
|
+
|
260
|
+
cNokogiriXsltStylesheet = klass;
|
261
|
+
|
262
|
+
rb_define_singleton_method(klass, "parse_stylesheet_doc", parse_stylesheet_doc, 1);
|
263
|
+
rb_define_singleton_method(xslt, "register", registr, 2);
|
264
|
+
rb_define_method(klass, "serialize", serialize, 1);
|
265
|
+
rb_define_method(klass, "transform", transform, -1);
|
266
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#ifndef NOKOGIRI_XSLT_STYLESHEET
|
2
|
+
#define NOKOGIRI_XSLT_STYLESHEET
|
3
|
+
|
4
|
+
#include <nokogiri.h>
|
5
|
+
|
6
|
+
void init_xslt_stylesheet();
|
7
|
+
|
8
|
+
extern VALUE cNokogiriXsltStylesheet ;
|
9
|
+
|
10
|
+
typedef struct _nokogiriXsltStylesheetTuple {
|
11
|
+
xsltStylesheetPtr ss;
|
12
|
+
VALUE func_instances;
|
13
|
+
} nokogiriXsltStylesheetTuple;
|
14
|
+
#endif
|
data/lib/nokogiri.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
# Modify the PATH on windows so that the external DLLs will get loaded.
|
4
|
+
|
5
|
+
require 'rbconfig'
|
6
|
+
|
7
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
|
8
|
+
require 'nokogiri/jruby/dependencies'
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
RUBY_VERSION =~ /(\d+\.\d+)/
|
13
|
+
require "nokogiri/#{$1}/nokogiri"
|
14
|
+
rescue LoadError
|
15
|
+
require 'nokogiri/nokogiri'
|
16
|
+
end
|
17
|
+
require 'nokogiri/version'
|
18
|
+
require 'nokogiri/syntax_error'
|
19
|
+
require 'nokogiri/xml'
|
20
|
+
require 'nokogiri/xslt'
|
21
|
+
require 'nokogiri/html'
|
22
|
+
require 'nokogiri/decorators/slop'
|
23
|
+
require 'nokogiri/css'
|
24
|
+
require 'nokogiri/html/builder'
|
25
|
+
|
26
|
+
# Nokogiri parses and searches XML/HTML very quickly, and also has
|
27
|
+
# correctly implemented CSS3 selector support as well as XPath 1.0
|
28
|
+
# support.
|
29
|
+
#
|
30
|
+
# Parsing a document returns either a Nokogiri::XML::Document, or a
|
31
|
+
# Nokogiri::HTML::Document depending on the kind of document you parse.
|
32
|
+
#
|
33
|
+
# Here is an example:
|
34
|
+
#
|
35
|
+
# require 'nokogiri'
|
36
|
+
# require 'open-uri'
|
37
|
+
#
|
38
|
+
# # Get a Nokogiri::HTML:Document for the page we’re interested in...
|
39
|
+
#
|
40
|
+
# doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
|
41
|
+
#
|
42
|
+
# # Do funky things with it using Nokogiri::XML::Node methods...
|
43
|
+
#
|
44
|
+
# ####
|
45
|
+
# # Search for nodes by css
|
46
|
+
# doc.css('h3.r a.l').each do |link|
|
47
|
+
# puts link.content
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# See Nokogiri::XML::Searchable#css for more information about CSS searching.
|
51
|
+
# See Nokogiri::XML::Searchable#xpath for more information about XPath searching.
|
52
|
+
module Nokogiri
|
53
|
+
class << self
|
54
|
+
###
|
55
|
+
# Parse an HTML or XML document. +string+ contains the document.
|
56
|
+
def parse string, url = nil, encoding = nil, options = nil
|
57
|
+
if string.respond_to?(:read) ||
|
58
|
+
/^\s*<(?:!DOCTYPE\s+)?html[\s>]/i === string[0, 512]
|
59
|
+
# Expect an HTML indicator to appear within the first 512
|
60
|
+
# characters of a document. (<?xml ?> + <?xml-stylesheet ?>
|
61
|
+
# shouldn't be that long)
|
62
|
+
Nokogiri.HTML(string, url, encoding,
|
63
|
+
options || XML::ParseOptions::DEFAULT_HTML)
|
64
|
+
else
|
65
|
+
Nokogiri.XML(string, url, encoding,
|
66
|
+
options || XML::ParseOptions::DEFAULT_XML)
|
67
|
+
end.tap { |doc|
|
68
|
+
yield doc if block_given?
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
###
|
73
|
+
# Create a new Nokogiri::XML::DocumentFragment
|
74
|
+
def make input = nil, opts = {}, &blk
|
75
|
+
if input
|
76
|
+
Nokogiri::HTML.fragment(input).children.first
|
77
|
+
else
|
78
|
+
Nokogiri(&blk)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
###
|
83
|
+
# Parse a document and add the Slop decorator. The Slop decorator
|
84
|
+
# implements method_missing such that methods may be used instead of CSS
|
85
|
+
# or XPath. For example:
|
86
|
+
#
|
87
|
+
# doc = Nokogiri::Slop(<<-eohtml)
|
88
|
+
# <html>
|
89
|
+
# <body>
|
90
|
+
# <p>first</p>
|
91
|
+
# <p>second</p>
|
92
|
+
# </body>
|
93
|
+
# </html>
|
94
|
+
# eohtml
|
95
|
+
# assert_equal('second', doc.html.body.p[1].text)
|
96
|
+
#
|
97
|
+
def Slop(*args, &block)
|
98
|
+
Nokogiri(*args, &block).slop!
|
99
|
+
end
|
100
|
+
|
101
|
+
def install_default_aliases
|
102
|
+
# Make sure to support some popular encoding aliases not known by
|
103
|
+
# all iconv implementations.
|
104
|
+
{
|
105
|
+
'Windows-31J' => 'CP932', # Windows-31J is the IANA registered name of CP932.
|
106
|
+
}.each { |alias_name, name|
|
107
|
+
EncodingHandler.alias(name, alias_name) if EncodingHandler[alias_name].nil?
|
108
|
+
}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
Nokogiri.install_default_aliases
|
113
|
+
end
|
114
|
+
|
115
|
+
###
|
116
|
+
# Parser a document contained in +args+. Nokogiri will try to guess what
|
117
|
+
# type of document you are attempting to parse. For more information, see
|
118
|
+
# Nokogiri.parse
|
119
|
+
#
|
120
|
+
# To specify the type of document, use Nokogiri.XML or Nokogiri.HTML.
|
121
|
+
def Nokogiri(*args, &block)
|
122
|
+
if block_given?
|
123
|
+
Nokogiri::HTML::Builder.new(&block).doc.root
|
124
|
+
else
|
125
|
+
Nokogiri.parse(*args)
|
126
|
+
end
|
127
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/nokogiri/css.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'nokogiri/css/node'
|
3
|
+
require 'nokogiri/css/xpath_visitor'
|
4
|
+
x = $-w
|
5
|
+
$-w = false
|
6
|
+
require 'nokogiri/css/parser'
|
7
|
+
$-w = x
|
8
|
+
|
9
|
+
require 'nokogiri/css/tokenizer'
|
10
|
+
require 'nokogiri/css/syntax_error'
|
11
|
+
|
12
|
+
module Nokogiri
|
13
|
+
module CSS
|
14
|
+
class << self
|
15
|
+
###
|
16
|
+
# Parse this CSS selector in +selector+. Returns an AST.
|
17
|
+
def parse selector
|
18
|
+
Parser.new.parse selector
|
19
|
+
end
|
20
|
+
|
21
|
+
###
|
22
|
+
# Get the XPath for +selector+.
|
23
|
+
def xpath_for selector, options={}
|
24
|
+
Parser.new(options[:ns] || {}).xpath_for selector, options
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|