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.
- checksums.yaml +7 -0
- data/LICENSE-DEPENDENCIES.md +1682 -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 +477 -0
- data/ext/nokogiri/extconf.rb +819 -0
- data/ext/nokogiri/html_document.c +171 -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/include/libexslt/exslt.h +102 -0
- data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
- data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +126 -0
- data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
- data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
- data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
- data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
- data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
- data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1241 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
- data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
- data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
- data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
- data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +366 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +945 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +153 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +566 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
- data/ext/nokogiri/include/libxslt/attributes.h +38 -0
- data/ext/nokogiri/include/libxslt/documents.h +93 -0
- data/ext/nokogiri/include/libxslt/extensions.h +262 -0
- data/ext/nokogiri/include/libxslt/extra.h +72 -0
- data/ext/nokogiri/include/libxslt/functions.h +78 -0
- data/ext/nokogiri/include/libxslt/imports.h +75 -0
- data/ext/nokogiri/include/libxslt/keys.h +53 -0
- data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
- data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
- data/ext/nokogiri/include/libxslt/pattern.h +84 -0
- data/ext/nokogiri/include/libxslt/preproc.h +43 -0
- data/ext/nokogiri/include/libxslt/security.h +104 -0
- data/ext/nokogiri/include/libxslt/templates.h +77 -0
- data/ext/nokogiri/include/libxslt/transform.h +207 -0
- data/ext/nokogiri/include/libxslt/variables.h +118 -0
- data/ext/nokogiri/include/libxslt/xslt.h +110 -0
- data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
- data/ext/nokogiri/nokogiri.c +135 -0
- data/ext/nokogiri/nokogiri.h +130 -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 +622 -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 +63 -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 +657 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +179 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +305 -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 +276 -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 +374 -0
- data/ext/nokogiri/xml_xpath_context.h +10 -0
- data/ext/nokogiri/xslt_stylesheet.c +263 -0
- data/ext/nokogiri/xslt_stylesheet.h +14 -0
- data/lib/nokogiri.rb +127 -0
- data/lib/nokogiri/2.5/nokogiri.bundle +0 -0
- data/lib/nokogiri/2.6/nokogiri.bundle +0 -0
- data/lib/nokogiri/2.7/nokogiri.bundle +0 -0
- data/lib/nokogiri/3.0/nokogiri.bundle +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 +94 -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 +260 -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 +322 -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 +3 -0
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +182 -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 +290 -0
- data/lib/nokogiri/xml/document_fragment.rb +159 -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 +1240 -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 +127 -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 +37 -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 +72 -0
- data/lib/nokogiri/xml/searchable.rb +239 -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 +565 -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,263 @@
|
|
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
|
+
static void mark(nokogiriXsltStylesheetTuple *wrapper)
|
11
|
+
{
|
12
|
+
rb_gc_mark(wrapper->func_instances);
|
13
|
+
}
|
14
|
+
|
15
|
+
static void dealloc(nokogiriXsltStylesheetTuple *wrapper)
|
16
|
+
{
|
17
|
+
xsltStylesheetPtr doc = wrapper->ss;
|
18
|
+
|
19
|
+
NOKOGIRI_DEBUG_START(doc);
|
20
|
+
xsltFreeStylesheet(doc); /* commented out for now. */
|
21
|
+
NOKOGIRI_DEBUG_END(doc);
|
22
|
+
|
23
|
+
free(wrapper);
|
24
|
+
}
|
25
|
+
|
26
|
+
static void xslt_generic_error_handler(void * ctx, const char *msg, ...)
|
27
|
+
{
|
28
|
+
char * message;
|
29
|
+
|
30
|
+
va_list args;
|
31
|
+
va_start(args, msg);
|
32
|
+
vasprintf(&message, msg, args);
|
33
|
+
va_end(args);
|
34
|
+
|
35
|
+
rb_str_cat2((VALUE)ctx, message);
|
36
|
+
|
37
|
+
free(message);
|
38
|
+
}
|
39
|
+
|
40
|
+
VALUE Nokogiri_wrap_xslt_stylesheet(xsltStylesheetPtr ss)
|
41
|
+
{
|
42
|
+
VALUE self;
|
43
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
44
|
+
|
45
|
+
self = Data_Make_Struct(cNokogiriXsltStylesheet, nokogiriXsltStylesheetTuple,
|
46
|
+
mark, dealloc, wrapper);
|
47
|
+
|
48
|
+
ss->_private = (void *)self;
|
49
|
+
wrapper->ss = ss;
|
50
|
+
wrapper->func_instances = rb_ary_new();
|
51
|
+
|
52
|
+
return self;
|
53
|
+
}
|
54
|
+
|
55
|
+
/*
|
56
|
+
* call-seq:
|
57
|
+
* parse_stylesheet_doc(document)
|
58
|
+
*
|
59
|
+
* Parse a stylesheet from +document+.
|
60
|
+
*/
|
61
|
+
static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj)
|
62
|
+
{
|
63
|
+
xmlDocPtr xml, xml_cpy;
|
64
|
+
VALUE errstr, exception;
|
65
|
+
xsltStylesheetPtr ss ;
|
66
|
+
Data_Get_Struct(xmldocobj, xmlDoc, xml);
|
67
|
+
exsltRegisterAll();
|
68
|
+
|
69
|
+
errstr = rb_str_new(0, 0);
|
70
|
+
xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
|
71
|
+
|
72
|
+
xml_cpy = xmlCopyDoc(xml, 1); /* 1 => recursive */
|
73
|
+
ss = xsltParseStylesheetDoc(xml_cpy);
|
74
|
+
|
75
|
+
xsltSetGenericErrorFunc(NULL, NULL);
|
76
|
+
|
77
|
+
if (!ss) {
|
78
|
+
xmlFreeDoc(xml_cpy);
|
79
|
+
exception = rb_exc_new3(rb_eRuntimeError, errstr);
|
80
|
+
rb_exc_raise(exception);
|
81
|
+
}
|
82
|
+
|
83
|
+
return Nokogiri_wrap_xslt_stylesheet(ss);
|
84
|
+
}
|
85
|
+
|
86
|
+
|
87
|
+
/*
|
88
|
+
* call-seq:
|
89
|
+
* serialize(document)
|
90
|
+
*
|
91
|
+
* Serialize +document+ to an xml string.
|
92
|
+
*/
|
93
|
+
static VALUE serialize(VALUE self, VALUE xmlobj)
|
94
|
+
{
|
95
|
+
xmlDocPtr xml ;
|
96
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
97
|
+
xmlChar* doc_ptr ;
|
98
|
+
int doc_len ;
|
99
|
+
VALUE rval ;
|
100
|
+
|
101
|
+
Data_Get_Struct(xmlobj, xmlDoc, xml);
|
102
|
+
Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
|
103
|
+
xsltSaveResultToString(&doc_ptr, &doc_len, xml, wrapper->ss);
|
104
|
+
rval = NOKOGIRI_STR_NEW(doc_ptr, doc_len);
|
105
|
+
xmlFree(doc_ptr);
|
106
|
+
return rval ;
|
107
|
+
}
|
108
|
+
|
109
|
+
/*
|
110
|
+
* call-seq:
|
111
|
+
* transform(document, params = [])
|
112
|
+
*
|
113
|
+
* Apply an XSLT stylesheet to an XML::Document.
|
114
|
+
* +params+ is an array of strings used as XSLT parameters.
|
115
|
+
* returns Nokogiri::XML::Document
|
116
|
+
*
|
117
|
+
* Example:
|
118
|
+
*
|
119
|
+
* doc = Nokogiri::XML(File.read(ARGV[0]))
|
120
|
+
* xslt = Nokogiri::XSLT(File.read(ARGV[1]))
|
121
|
+
* puts xslt.transform(doc, ['key', 'value'])
|
122
|
+
*
|
123
|
+
*/
|
124
|
+
static VALUE transform(int argc, VALUE* argv, VALUE self)
|
125
|
+
{
|
126
|
+
VALUE xmldoc, paramobj, errstr, exception ;
|
127
|
+
xmlDocPtr xml ;
|
128
|
+
xmlDocPtr result ;
|
129
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
130
|
+
const char** params ;
|
131
|
+
long param_len, j ;
|
132
|
+
int parse_error_occurred ;
|
133
|
+
|
134
|
+
rb_scan_args(argc, argv, "11", &xmldoc, ¶mobj);
|
135
|
+
if (NIL_P(paramobj)) { paramobj = rb_ary_new2(0L) ; }
|
136
|
+
if (!rb_obj_is_kind_of(xmldoc, cNokogiriXmlDocument))
|
137
|
+
rb_raise(rb_eArgError, "argument must be a Nokogiri::XML::Document");
|
138
|
+
|
139
|
+
/* handle hashes as arguments. */
|
140
|
+
if(T_HASH == TYPE(paramobj)) {
|
141
|
+
paramobj = rb_funcall(paramobj, rb_intern("to_a"), 0);
|
142
|
+
paramobj = rb_funcall(paramobj, rb_intern("flatten"), 0);
|
143
|
+
}
|
144
|
+
|
145
|
+
Check_Type(paramobj, T_ARRAY);
|
146
|
+
|
147
|
+
Data_Get_Struct(xmldoc, xmlDoc, xml);
|
148
|
+
Data_Get_Struct(self, nokogiriXsltStylesheetTuple, wrapper);
|
149
|
+
|
150
|
+
param_len = RARRAY_LEN(paramobj);
|
151
|
+
params = calloc((size_t)param_len+1, sizeof(char*));
|
152
|
+
for (j = 0 ; j < param_len ; j++) {
|
153
|
+
VALUE entry = rb_ary_entry(paramobj, j);
|
154
|
+
const char * ptr = StringValueCStr(entry);
|
155
|
+
params[j] = ptr;
|
156
|
+
}
|
157
|
+
params[param_len] = 0 ;
|
158
|
+
|
159
|
+
errstr = rb_str_new(0, 0);
|
160
|
+
xsltSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
|
161
|
+
xmlSetGenericErrorFunc((void *)errstr, xslt_generic_error_handler);
|
162
|
+
|
163
|
+
result = xsltApplyStylesheet(wrapper->ss, xml, params);
|
164
|
+
free(params);
|
165
|
+
|
166
|
+
xsltSetGenericErrorFunc(NULL, NULL);
|
167
|
+
xmlSetGenericErrorFunc(NULL, NULL);
|
168
|
+
|
169
|
+
parse_error_occurred = (Qfalse == rb_funcall(errstr, rb_intern("empty?"), 0));
|
170
|
+
|
171
|
+
if (parse_error_occurred) {
|
172
|
+
exception = rb_exc_new3(rb_eRuntimeError, errstr);
|
173
|
+
rb_exc_raise(exception);
|
174
|
+
}
|
175
|
+
|
176
|
+
return Nokogiri_wrap_xml_document((VALUE)0, result) ;
|
177
|
+
}
|
178
|
+
|
179
|
+
static void method_caller(xmlXPathParserContextPtr ctxt, int nargs)
|
180
|
+
{
|
181
|
+
VALUE handler;
|
182
|
+
const char *function_name;
|
183
|
+
xsltTransformContextPtr transform;
|
184
|
+
const xmlChar *functionURI;
|
185
|
+
|
186
|
+
transform = xsltXPathGetTransformContext(ctxt);
|
187
|
+
functionURI = ctxt->context->functionURI;
|
188
|
+
handler = (VALUE)xsltGetExtData(transform, functionURI);
|
189
|
+
function_name = (const char*)(ctxt->context->function);
|
190
|
+
|
191
|
+
Nokogiri_marshal_xpath_funcall_and_return_values(ctxt, nargs, handler, (const char*)function_name);
|
192
|
+
}
|
193
|
+
|
194
|
+
static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri)
|
195
|
+
{
|
196
|
+
VALUE modules = rb_iv_get(xslt, "@modules");
|
197
|
+
VALUE obj = rb_hash_aref(modules, rb_str_new2((const char *)uri));
|
198
|
+
VALUE args = { Qfalse };
|
199
|
+
VALUE methods = rb_funcall(obj, rb_intern("instance_methods"), 1, args);
|
200
|
+
VALUE inst;
|
201
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
202
|
+
int i;
|
203
|
+
|
204
|
+
for(i = 0; i < RARRAY_LEN(methods); i++) {
|
205
|
+
VALUE method_name = rb_obj_as_string(rb_ary_entry(methods, i));
|
206
|
+
xsltRegisterExtFunction(ctxt,
|
207
|
+
(unsigned char *)StringValueCStr(method_name), uri, method_caller);
|
208
|
+
}
|
209
|
+
|
210
|
+
Data_Get_Struct((VALUE)ctxt->style->_private, nokogiriXsltStylesheetTuple,
|
211
|
+
wrapper);
|
212
|
+
inst = rb_class_new_instance(0, NULL, obj);
|
213
|
+
rb_ary_push(wrapper->func_instances, inst);
|
214
|
+
|
215
|
+
return (void *)inst;
|
216
|
+
}
|
217
|
+
|
218
|
+
static void shutdownFunc(xsltTransformContextPtr ctxt,
|
219
|
+
const xmlChar *uri, void *data)
|
220
|
+
{
|
221
|
+
nokogiriXsltStylesheetTuple *wrapper;
|
222
|
+
|
223
|
+
Data_Get_Struct((VALUE)ctxt->style->_private, nokogiriXsltStylesheetTuple,
|
224
|
+
wrapper);
|
225
|
+
|
226
|
+
rb_ary_clear(wrapper->func_instances);
|
227
|
+
}
|
228
|
+
|
229
|
+
/*
|
230
|
+
* call-seq:
|
231
|
+
* register(uri, custom_handler_class)
|
232
|
+
*
|
233
|
+
* Register a class that implements custom XSLT transformation functions.
|
234
|
+
*/
|
235
|
+
static VALUE registr(VALUE self, VALUE uri, VALUE obj)
|
236
|
+
{
|
237
|
+
VALUE modules = rb_iv_get(self, "@modules");
|
238
|
+
if(NIL_P(modules)) rb_raise(rb_eRuntimeError, "wtf! @modules isn't set");
|
239
|
+
|
240
|
+
rb_hash_aset(modules, uri, obj);
|
241
|
+
xsltRegisterExtModule((unsigned char *)StringValueCStr(uri), initFunc, shutdownFunc);
|
242
|
+
return self;
|
243
|
+
}
|
244
|
+
|
245
|
+
VALUE cNokogiriXsltStylesheet ;
|
246
|
+
void init_xslt_stylesheet()
|
247
|
+
{
|
248
|
+
VALUE nokogiri;
|
249
|
+
VALUE klass;
|
250
|
+
|
251
|
+
nokogiri = rb_define_module("Nokogiri");
|
252
|
+
xslt = rb_define_module_under(nokogiri, "XSLT");
|
253
|
+
klass = rb_define_class_under(xslt, "Stylesheet", rb_cObject);
|
254
|
+
|
255
|
+
rb_iv_set(xslt, "@modules", rb_hash_new());
|
256
|
+
|
257
|
+
cNokogiriXsltStylesheet = klass;
|
258
|
+
|
259
|
+
rb_define_singleton_method(klass, "parse_stylesheet_doc", parse_stylesheet_doc, 1);
|
260
|
+
rb_define_singleton_method(xslt, "register", registr, 2);
|
261
|
+
rb_define_method(klass, "serialize", serialize, 1);
|
262
|
+
rb_define_method(klass, "transform", transform, -1);
|
263
|
+
}
|
@@ -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(URI.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
|
+
# Parse 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
|