nokogiri 1.0.0-x86-mswin32-60
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.
- data/History.txt +6 -0
- data/Manifest.txt +120 -0
- data/README.ja.txt +86 -0
- data/README.txt +87 -0
- data/Rakefile +264 -0
- data/ext/nokogiri/extconf.rb +59 -0
- data/ext/nokogiri/html_document.c +83 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_sax_parser.c +32 -0
- data/ext/nokogiri/html_sax_parser.h +11 -0
- data/ext/nokogiri/iconv.dll +0 -0
- data/ext/nokogiri/libexslt.dll +0 -0
- data/ext/nokogiri/libxml2.dll +0 -0
- data/ext/nokogiri/libxslt.dll +0 -0
- data/ext/nokogiri/native.c +40 -0
- data/ext/nokogiri/native.h +51 -0
- data/ext/nokogiri/native.so +0 -0
- data/ext/nokogiri/xml_cdata.c +52 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_document.c +159 -0
- data/ext/nokogiri/xml_document.h +10 -0
- data/ext/nokogiri/xml_dtd.c +117 -0
- data/ext/nokogiri/xml_dtd.h +8 -0
- data/ext/nokogiri/xml_node.c +709 -0
- data/ext/nokogiri/xml_node.h +15 -0
- data/ext/nokogiri/xml_node_set.c +124 -0
- data/ext/nokogiri/xml_node_set.h +9 -0
- data/ext/nokogiri/xml_reader.c +429 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_sax_parser.c +174 -0
- data/ext/nokogiri/xml_sax_parser.h +10 -0
- data/ext/nokogiri/xml_syntax_error.c +194 -0
- data/ext/nokogiri/xml_syntax_error.h +11 -0
- data/ext/nokogiri/xml_text.c +29 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath.c +46 -0
- data/ext/nokogiri/xml_xpath.h +11 -0
- data/ext/nokogiri/xml_xpath_context.c +81 -0
- data/ext/nokogiri/xml_xpath_context.h +9 -0
- data/ext/nokogiri/xslt_stylesheet.c +108 -0
- data/ext/nokogiri/xslt_stylesheet.h +9 -0
- data/ext/nokogiri/zlib1.dll +0 -0
- data/lib/nokogiri.rb +51 -0
- data/lib/nokogiri/css.rb +6 -0
- data/lib/nokogiri/css/generated_parser.rb +653 -0
- data/lib/nokogiri/css/generated_tokenizer.rb +159 -0
- data/lib/nokogiri/css/node.rb +95 -0
- data/lib/nokogiri/css/parser.rb +24 -0
- data/lib/nokogiri/css/parser.y +198 -0
- data/lib/nokogiri/css/tokenizer.rb +9 -0
- data/lib/nokogiri/css/tokenizer.rex +63 -0
- data/lib/nokogiri/css/xpath_visitor.rb +165 -0
- data/lib/nokogiri/decorators.rb +1 -0
- data/lib/nokogiri/decorators/hpricot.rb +3 -0
- data/lib/nokogiri/decorators/hpricot/node.rb +58 -0
- data/lib/nokogiri/decorators/hpricot/node_set.rb +14 -0
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +17 -0
- data/lib/nokogiri/hpricot.rb +47 -0
- data/lib/nokogiri/html.rb +95 -0
- data/lib/nokogiri/html/builder.rb +9 -0
- data/lib/nokogiri/html/document.rb +9 -0
- data/lib/nokogiri/html/sax/parser.rb +21 -0
- data/lib/nokogiri/version.rb +3 -0
- data/lib/nokogiri/xml.rb +67 -0
- data/lib/nokogiri/xml/after_handler.rb +18 -0
- data/lib/nokogiri/xml/before_handler.rb +32 -0
- data/lib/nokogiri/xml/builder.rb +79 -0
- data/lib/nokogiri/xml/cdata.rb +9 -0
- data/lib/nokogiri/xml/document.rb +30 -0
- data/lib/nokogiri/xml/dtd.rb +6 -0
- data/lib/nokogiri/xml/element.rb +6 -0
- data/lib/nokogiri/xml/entity_declaration.rb +9 -0
- data/lib/nokogiri/xml/node.rb +195 -0
- data/lib/nokogiri/xml/node_set.rb +183 -0
- data/lib/nokogiri/xml/notation.rb +6 -0
- data/lib/nokogiri/xml/reader.rb +14 -0
- data/lib/nokogiri/xml/sax.rb +9 -0
- data/lib/nokogiri/xml/sax/document.rb +59 -0
- data/lib/nokogiri/xml/sax/parser.rb +33 -0
- data/lib/nokogiri/xml/syntax_error.rb +21 -0
- data/lib/nokogiri/xml/text.rb +6 -0
- data/lib/nokogiri/xml/xpath.rb +6 -0
- data/lib/nokogiri/xml/xpath_context.rb +14 -0
- data/lib/nokogiri/xslt.rb +11 -0
- data/lib/nokogiri/xslt/stylesheet.rb +6 -0
- data/nokogiri.gemspec +34 -0
- data/test/css/test_nthiness.rb +159 -0
- data/test/css/test_parser.rb +224 -0
- data/test/css/test_tokenizer.rb +162 -0
- data/test/css/test_xpath_visitor.rb +54 -0
- data/test/files/staff.xml +59 -0
- data/test/files/staff.xslt +32 -0
- data/test/files/tlm.html +850 -0
- data/test/helper.rb +70 -0
- data/test/hpricot/files/basic.xhtml +17 -0
- data/test/hpricot/files/boingboing.html +2266 -0
- data/test/hpricot/files/cy0.html +3653 -0
- data/test/hpricot/files/immob.html +400 -0
- data/test/hpricot/files/pace_application.html +1320 -0
- data/test/hpricot/files/tenderlove.html +16 -0
- data/test/hpricot/files/uswebgen.html +220 -0
- data/test/hpricot/files/utf8.html +1054 -0
- data/test/hpricot/files/week9.html +1723 -0
- data/test/hpricot/files/why.xml +19 -0
- data/test/hpricot/load_files.rb +7 -0
- data/test/hpricot/test_alter.rb +67 -0
- data/test/hpricot/test_builder.rb +27 -0
- data/test/hpricot/test_parser.rb +423 -0
- data/test/hpricot/test_paths.rb +15 -0
- data/test/hpricot/test_preserved.rb +78 -0
- data/test/hpricot/test_xml.rb +30 -0
- data/test/html/sax/test_parser.rb +27 -0
- data/test/html/test_builder.rb +78 -0
- data/test/html/test_document.rb +86 -0
- data/test/test_convert_xpath.rb +180 -0
- data/test/test_nokogiri.rb +36 -0
- data/test/test_reader.rb +222 -0
- data/test/test_xslt_transforms.rb +29 -0
- data/test/xml/sax/test_parser.rb +93 -0
- data/test/xml/test_builder.rb +16 -0
- data/test/xml/test_cdata.rb +18 -0
- data/test/xml/test_document.rb +171 -0
- data/test/xml/test_dtd.rb +43 -0
- data/test/xml/test_node.rb +223 -0
- data/test/xml/test_node_set.rb +116 -0
- data/test/xml/test_text.rb +13 -0
- metadata +217 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module CSS
|
3
|
+
class GeneratedTokenizer
|
4
|
+
|
5
|
+
macro
|
6
|
+
nl \n|\r\n|\r|\f
|
7
|
+
w [\s\r\n\f]*
|
8
|
+
nonascii [^\\\\0-\\\\177]
|
9
|
+
num -?([0-9]+|[0-9]*\.[0-9]+)
|
10
|
+
unicode \\\\\\\\\[0-9a-f]{1,6}(\r\n|[\s\n\r\t\f])?
|
11
|
+
|
12
|
+
escape {unicode}|\\\\\\\[^\n\r\f0-9a-f]
|
13
|
+
nmchar [_a-z0-9-]|{nonascii}|{escape}
|
14
|
+
nmstart [_a-z]|{nonascii}|{escape}
|
15
|
+
ident [-]?({nmstart})({nmchar})*
|
16
|
+
name ({nmchar})+
|
17
|
+
string1 "([^\n\r\f"]|\\{nl}|{nonascii}|{escape})*"
|
18
|
+
string2 '([^\n\r\f']|\\{nl}|{nonascii}|{escape})*'
|
19
|
+
string {string1}|{string2}
|
20
|
+
invalid1 \"([^\n\r\f\\"]|\\{nl}|{nonascii}|{escape})*
|
21
|
+
invalid2 \'([^\n\r\f\\']|\\{nl}|{nonascii}|{escape})*
|
22
|
+
invalid {invalid1}|{invalid2}
|
23
|
+
Comment \/\*(.|[\r\n])*?\*\/
|
24
|
+
|
25
|
+
rule
|
26
|
+
|
27
|
+
# [:state] pattern [actions]
|
28
|
+
|
29
|
+
~= { [:INCLUDES, text] }
|
30
|
+
\|= { [:DASHMATCH, text] }
|
31
|
+
\^= { [:PREFIXMATCH, text] }
|
32
|
+
\$= { [:SUFFIXMATCH, text] }
|
33
|
+
\*= { [:SUBSTRINGMATCH, text] }
|
34
|
+
!= { [:NOT_EQUAL, text] }
|
35
|
+
{ident}\(\s* { [:FUNCTION, text] }
|
36
|
+
@{ident} { [:IDENT, text] }
|
37
|
+
{ident} { [:IDENT, text] }
|
38
|
+
{num} { [:NUMBER, text] }
|
39
|
+
\#{name} { [:HASH, text] }
|
40
|
+
{w}\+ { [:PLUS, text] }
|
41
|
+
{w}> { [:GREATER, text] }
|
42
|
+
{w}, { [:COMMA, text] }
|
43
|
+
{w}~ { [:TILDE, text] }
|
44
|
+
\:not\( { [:NOT, text] }
|
45
|
+
@{ident} { [:ATKEYWORD, text] }
|
46
|
+
{num}% { [:PERCENTAGE, text] }
|
47
|
+
{num}{ident} { [:DIMENSION, text] }
|
48
|
+
<!-- { [:CDO, text] }
|
49
|
+
--> { [:CDC, text] }
|
50
|
+
{w}\/\/ { [:DOUBLESLASH, text] }
|
51
|
+
{w}\/ { [:SLASH, text] }
|
52
|
+
|
53
|
+
U\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})? {[:UNICODE_RANGE, text] }
|
54
|
+
|
55
|
+
{Comment} /* ignore comments */
|
56
|
+
[\s\t\r\n\f]+ { [:S, text] }
|
57
|
+
[\.*:\[\]=\)] { [text, text] }
|
58
|
+
{string} { [:STRING, text] }
|
59
|
+
{invalid} { [:INVALID, text] }
|
60
|
+
. { [text, text] }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module CSS
|
3
|
+
class XPathVisitor
|
4
|
+
def visit_function node
|
5
|
+
# note that nth-child and nth-last-child are preprocessed in css/node.rb.
|
6
|
+
msg = :"visit_function_#{node.value.first.gsub(/[(]/, '')}"
|
7
|
+
return self.send(msg, node) if self.respond_to?(msg)
|
8
|
+
|
9
|
+
case node.value.first
|
10
|
+
when /^text\(/
|
11
|
+
'child::text()'
|
12
|
+
when /^self\(/
|
13
|
+
"self::#{node.value[1]}"
|
14
|
+
when /^(eq|nth|nth-of-type|nth-child)\(/
|
15
|
+
if node.value[1].is_a?(Nokogiri::CSS::Node) and node.value[1].type == :AN_PLUS_B
|
16
|
+
an_plus_b(node.value[1])
|
17
|
+
else
|
18
|
+
"position() = " + node.value[1]
|
19
|
+
end
|
20
|
+
when /^(first|first-of-type)\(/
|
21
|
+
"position() = 1"
|
22
|
+
when /^(last|last-of-type)\(/
|
23
|
+
"position() = last()"
|
24
|
+
when /^(nth-last-child|nth-last-of-type)\(/
|
25
|
+
"position() = last() - #{node.value[1]}"
|
26
|
+
when /^contains\(/
|
27
|
+
"contains(., #{node.value[1]})"
|
28
|
+
when /^gt\(/
|
29
|
+
"position() > #{node.value[1]}"
|
30
|
+
when /^only-child\(/
|
31
|
+
"last() = 1"
|
32
|
+
else
|
33
|
+
node.value.first + ')'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def visit_not node
|
38
|
+
'not(' + node.value.first.accept(self) + ')'
|
39
|
+
end
|
40
|
+
|
41
|
+
def visit_preceding_selector node
|
42
|
+
node.value.last.accept(self) +
|
43
|
+
'[preceding-sibling::' +
|
44
|
+
node.value.first.accept(self) +
|
45
|
+
']'
|
46
|
+
end
|
47
|
+
|
48
|
+
def visit_direct_adjacent_selector node
|
49
|
+
node.value.first.accept(self) +
|
50
|
+
"/following-sibling::*[1]/self::" +
|
51
|
+
node.value.last.accept(self)
|
52
|
+
end
|
53
|
+
|
54
|
+
def visit_id node
|
55
|
+
node.value.first =~ /^#(.*)$/
|
56
|
+
"@id = '#{$1}'"
|
57
|
+
end
|
58
|
+
|
59
|
+
def visit_attribute_condition node
|
60
|
+
attribute = if (node.value.first.type == :FUNCTION) or (node.value.first.value.first =~ /::/)
|
61
|
+
''
|
62
|
+
else
|
63
|
+
'@'
|
64
|
+
end
|
65
|
+
attribute += node.value.first.accept(self)
|
66
|
+
|
67
|
+
# Support non-standard css
|
68
|
+
attribute.gsub!(/^@@/, '@')
|
69
|
+
|
70
|
+
return attribute unless node.value.length == 3
|
71
|
+
|
72
|
+
value = node.value.last
|
73
|
+
value = "'#{value}'" if value !~ /^['"]/
|
74
|
+
|
75
|
+
case node.value[1]
|
76
|
+
when '*='
|
77
|
+
"contains(#{attribute}, #{value})"
|
78
|
+
when '^='
|
79
|
+
"starts-with(#{attribute}, #{value})"
|
80
|
+
when '|='
|
81
|
+
"#{attribute} = #{value} or starts-with(#{attribute}, concat(#{value}, '-'))"
|
82
|
+
when '~='
|
83
|
+
"contains(concat(\" \", #{attribute}, \" \"),concat(\" \", #{value}, \" \"))"
|
84
|
+
when '$='
|
85
|
+
"substring(#{attribute}, string-length(#{attribute}) - " +
|
86
|
+
"string-length(#{value}) + 1, string-length(#{value})) = #{value}"
|
87
|
+
else
|
88
|
+
attribute + " #{node.value[1]} " + "#{value}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def visit_pseudo_class node
|
93
|
+
if node.value.first.is_a?(Nokogiri::CSS::Node) and node.value.first.type == :FUNCTION
|
94
|
+
node.value.first.accept(self)
|
95
|
+
else
|
96
|
+
msg = :"visit_pseudo_class_#{node.value.first.gsub(/[(]/, '')}"
|
97
|
+
return self.send(msg, node) if self.respond_to?(msg)
|
98
|
+
|
99
|
+
case node.value.first
|
100
|
+
when "first" then "position() = 1"
|
101
|
+
when "last" then "position() = last()"
|
102
|
+
when "first-of-type" then "position() = 1"
|
103
|
+
when "last-of-type" then "position() = last()"
|
104
|
+
when "only-of-type" then "last() = 1"
|
105
|
+
when "empty" then "not(node())"
|
106
|
+
when "parent" then "node()"
|
107
|
+
when "root" then "not(parent::*)"
|
108
|
+
else
|
109
|
+
'1 = 1'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def visit_class_condition node
|
115
|
+
"contains(concat(' ', @class, ' '), ' #{node.value.first} ')"
|
116
|
+
end
|
117
|
+
|
118
|
+
def visit_combinator node
|
119
|
+
node.value.first.accept(self) + ' and ' +
|
120
|
+
node.value.last.accept(self)
|
121
|
+
end
|
122
|
+
|
123
|
+
def visit_conditional_selector node
|
124
|
+
node.value.first.accept(self) + '[' +
|
125
|
+
node.value.last.accept(self) + ']'
|
126
|
+
end
|
127
|
+
|
128
|
+
def visit_descendant_selector node
|
129
|
+
node.value.first.accept(self) +
|
130
|
+
'//' +
|
131
|
+
node.value.last.accept(self)
|
132
|
+
end
|
133
|
+
|
134
|
+
def visit_child_selector node
|
135
|
+
node.value.first.accept(self) +
|
136
|
+
'/' +
|
137
|
+
node.value.last.accept(self)
|
138
|
+
end
|
139
|
+
|
140
|
+
def visit_element_name node
|
141
|
+
node.value.first
|
142
|
+
end
|
143
|
+
|
144
|
+
def accept node
|
145
|
+
node.accept(self)
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
def an_plus_b node
|
150
|
+
raise ArgumentError, "expected an+b node to contain 4 tokens, but is #{node.value.inspect}" unless node.value.size == 4
|
151
|
+
|
152
|
+
a = node.value[0].to_i
|
153
|
+
b = node.value[3].to_i
|
154
|
+
|
155
|
+
if (b == 0)
|
156
|
+
return "(position() mod #{a}) = 0"
|
157
|
+
else
|
158
|
+
compare = (a < 0) ? "<=" : ">="
|
159
|
+
return "(position() #{compare} #{b}) and (((position()-#{b}) mod #{a.abs}) = 0)"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'nokogiri/decorators/hpricot'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module Decorators
|
3
|
+
module Hpricot
|
4
|
+
module Node
|
5
|
+
def search *paths
|
6
|
+
ns = paths.last.is_a?(Hash) ? paths.pop : {}
|
7
|
+
converted = paths.map { |path|
|
8
|
+
convert_to_xpath(path)
|
9
|
+
}.flatten.uniq
|
10
|
+
|
11
|
+
namespaces = document.xml? ? document.namespaces.merge(ns) : ns
|
12
|
+
super(*converted + [namespaces])
|
13
|
+
end
|
14
|
+
def /(path); search(path) end
|
15
|
+
|
16
|
+
def xpath *args
|
17
|
+
return super if args.length > 0
|
18
|
+
path
|
19
|
+
end
|
20
|
+
|
21
|
+
def raw_attributes; self end
|
22
|
+
|
23
|
+
def get_element_by_id element_id
|
24
|
+
search("//*[@id='#{element_id}']").first
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_elements_by_tag_name tag
|
28
|
+
search("//#{tag}")
|
29
|
+
end
|
30
|
+
|
31
|
+
def convert_to_xpath(rule)
|
32
|
+
rule = rule.to_s
|
33
|
+
case rule
|
34
|
+
when %r{^//}
|
35
|
+
[".#{rule}"]
|
36
|
+
when %r{^/}
|
37
|
+
[rule]
|
38
|
+
when %r{^.//}
|
39
|
+
[rule]
|
40
|
+
else
|
41
|
+
ctx = CSS::Parser.parse(rule)
|
42
|
+
visitor = CSS::XPathVisitor.new
|
43
|
+
visitor.extend(Hpricot::XPathVisitor)
|
44
|
+
ctx.map { |ast| './/' + visitor.accept(ast.preprocess!) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def target
|
49
|
+
name
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_original_html
|
53
|
+
to_html
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module Decorators
|
3
|
+
module Hpricot
|
4
|
+
module NodeSet
|
5
|
+
def filter rule
|
6
|
+
ctx = CSS::Parser.parse(rule.to_s)
|
7
|
+
visitor = CSS::XPathVisitor.new
|
8
|
+
visitor.extend(Hpricot::XPathVisitor)
|
9
|
+
search('.//self::' + visitor.accept(ctx.first))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module Decorators
|
3
|
+
module Hpricot
|
4
|
+
####
|
5
|
+
# This mixin does custom adjustments to deal with _whyML
|
6
|
+
module XPathVisitor
|
7
|
+
def visit_attribute_condition node
|
8
|
+
unless (node.value.first.type == :FUNCTION) or (node.value.first.value.first =~ /^@/)
|
9
|
+
node.value.first.value[0] = "child::" +
|
10
|
+
node.value.first.value[0]
|
11
|
+
end
|
12
|
+
super(node).gsub(/child::text\(\)/, 'normalize-space(child::text())')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Nokogiri
|
4
|
+
module Hpricot
|
5
|
+
STag = String
|
6
|
+
Elem = XML::Node
|
7
|
+
NamedCharacters = Nokogiri::HTML::NamedCharacters
|
8
|
+
class << self
|
9
|
+
def parse(*args)
|
10
|
+
doc = Nokogiri.parse(*args)
|
11
|
+
add_decorators(doc)
|
12
|
+
end
|
13
|
+
|
14
|
+
def XML(string)
|
15
|
+
doc = Nokogiri::XML.parse(string)
|
16
|
+
add_decorators(doc)
|
17
|
+
end
|
18
|
+
|
19
|
+
def make string
|
20
|
+
ns = XML::NodeSet.new
|
21
|
+
ns << XML::Text.new(string)
|
22
|
+
ns
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_decorators(doc)
|
26
|
+
doc.decorators['node'] << Decorators::Hpricot::Node
|
27
|
+
doc.decorators['element'] << Decorators::Hpricot::Node
|
28
|
+
doc.decorators['document'] << Decorators::Hpricot::Node
|
29
|
+
doc.decorators['nodeset'] << Decorators::Hpricot::NodeSet
|
30
|
+
doc.decorate!
|
31
|
+
doc
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class << self
|
37
|
+
def Hpricot(*args, &block)
|
38
|
+
if block_given?
|
39
|
+
builder = Nokogiri::HTML::Builder.new(&block)
|
40
|
+
Nokogiri::Hpricot.add_decorators(builder.doc)
|
41
|
+
else
|
42
|
+
doc = Nokogiri::HTML.parse(*args)
|
43
|
+
Nokogiri::Hpricot.add_decorators(doc)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'nokogiri/html/document'
|
2
|
+
require 'nokogiri/html/sax/parser'
|
3
|
+
|
4
|
+
module Nokogiri
|
5
|
+
class << self
|
6
|
+
def HTML thing, url = nil, encoding = nil, options = 2145
|
7
|
+
Nokogiri::HTML.parse(thing, url, encoding, options)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module HTML
|
12
|
+
# Parser options
|
13
|
+
PARSE_NOERROR = 1 << 5 # No error reports
|
14
|
+
PARSE_NOWARNING = 1 << 6 # No warnings
|
15
|
+
PARSE_PEDANTIC = 1 << 7 # Pedantic errors
|
16
|
+
PARSE_NOBLANKS = 1 << 8 # Remove blanks nodes
|
17
|
+
PARSE_NONET = 1 << 11 # No network access
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def parse string_or_io, url = nil, encoding = nil, options = 2145
|
21
|
+
if string_or_io.respond_to?(:read)
|
22
|
+
url ||= string_or_io.respond_to?(:path) ? string_or_io.path : nil
|
23
|
+
string_or_io = string_or_io.read
|
24
|
+
end
|
25
|
+
|
26
|
+
Document.read_memory(string_or_io, url, encoding, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
####
|
30
|
+
# Parse a fragment from +string+ in to a NodeSet.
|
31
|
+
def fragment string
|
32
|
+
doc = parse(string)
|
33
|
+
finder = lambda { |children, f|
|
34
|
+
children.each do |child|
|
35
|
+
return children if string =~ /<#{child.name}/
|
36
|
+
finder.call(child.children, f)
|
37
|
+
end
|
38
|
+
}
|
39
|
+
finder.call(doc.children, finder)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
NamedCharacters =
|
44
|
+
{"AElig"=>198, "Aacute"=>193, "Acirc"=>194, "Agrave"=>192, "Alpha"=>913,
|
45
|
+
"Aring"=>197, "Atilde"=>195, "Auml"=>196, "Beta"=>914, "Ccedil"=>199,
|
46
|
+
"Chi"=>935, "Dagger"=>8225, "Delta"=>916, "ETH"=>208, "Eacute"=>201,
|
47
|
+
"Ecirc"=>202, "Egrave"=>200, "Epsilon"=>917, "Eta"=>919, "Euml"=>203,
|
48
|
+
"Gamma"=>915, "Iacute"=>205, "Icirc"=>206, "Igrave"=>204, "Iota"=>921,
|
49
|
+
"Iuml"=>207, "Kappa"=>922, "Lambda"=>923, "Mu"=>924, "Ntilde"=>209, "Nu"=>925,
|
50
|
+
"OElig"=>338, "Oacute"=>211, "Ocirc"=>212, "Ograve"=>210, "Omega"=>937,
|
51
|
+
"Omicron"=>927, "Oslash"=>216, "Otilde"=>213, "Ouml"=>214, "Phi"=>934,
|
52
|
+
"Pi"=>928, "Prime"=>8243, "Psi"=>936, "Rho"=>929, "Scaron"=>352, "Sigma"=>931,
|
53
|
+
"THORN"=>222, "Tau"=>932, "Theta"=>920, "Uacute"=>218, "Ucirc"=>219,
|
54
|
+
"Ugrave"=>217, "Upsilon"=>933, "Uuml"=>220, "Xi"=>926, "Yacute"=>221,
|
55
|
+
"Yuml"=>376, "Zeta"=>918, "aacute"=>225, "acirc"=>226, "acute"=>180,
|
56
|
+
"aelig"=>230, "agrave"=>224, "alefsym"=>8501, "alpha"=>945, "amp"=>38,
|
57
|
+
"and"=>8743, "ang"=>8736, "apos"=>39, "aring"=>229, "asymp"=>8776,
|
58
|
+
"atilde"=>227, "auml"=>228, "bdquo"=>8222, "beta"=>946, "brvbar"=>166,
|
59
|
+
"bull"=>8226, "cap"=>8745, "ccedil"=>231, "cedil"=>184, "cent"=>162,
|
60
|
+
"chi"=>967, "circ"=>710, "clubs"=>9827, "cong"=>8773, "copy"=>169,
|
61
|
+
"crarr"=>8629, "cup"=>8746, "curren"=>164, "dArr"=>8659, "dagger"=>8224,
|
62
|
+
"darr"=>8595, "deg"=>176, "delta"=>948, "diams"=>9830, "divide"=>247,
|
63
|
+
"eacute"=>233, "ecirc"=>234, "egrave"=>232, "empty"=>8709, "emsp"=>8195,
|
64
|
+
"ensp"=>8194, "epsilon"=>949, "equiv"=>8801, "eta"=>951, "eth"=>240,
|
65
|
+
"euml"=>235, "euro"=>8364, "exist"=>8707, "fnof"=>402, "forall"=>8704,
|
66
|
+
"frac12"=>189, "frac14"=>188, "frac34"=>190, "frasl"=>8260, "gamma"=>947,
|
67
|
+
"ge"=>8805, "gt"=>62, "hArr"=>8660, "harr"=>8596, "hearts"=>9829,
|
68
|
+
"hellip"=>8230, "iacute"=>237, "icirc"=>238, "iexcl"=>161, "igrave"=>236,
|
69
|
+
"image"=>8465, "infin"=>8734, "int"=>8747, "iota"=>953, "iquest"=>191,
|
70
|
+
"isin"=>8712, "iuml"=>239, "kappa"=>954, "lArr"=>8656, "lambda"=>955,
|
71
|
+
"lang"=>9001, "laquo"=>171, "larr"=>8592, "lceil"=>8968, "ldquo"=>8220,
|
72
|
+
"le"=>8804, "lfloor"=>8970, "lowast"=>8727, "loz"=>9674, "lrm"=>8206,
|
73
|
+
"lsaquo"=>8249, "lsquo"=>8216, "lt"=>60, "macr"=>175, "mdash"=>8212,
|
74
|
+
"micro"=>181, "middot"=>183, "minus"=>8722, "mu"=>956, "nabla"=>8711,
|
75
|
+
"nbsp"=>160, "ndash"=>8211, "ne"=>8800, "ni"=>8715, "not"=>172, "notin"=>8713,
|
76
|
+
"nsub"=>8836, "ntilde"=>241, "nu"=>957, "oacute"=>243, "ocirc"=>244,
|
77
|
+
"oelig"=>339, "ograve"=>242, "oline"=>8254, "omega"=>969, "omicron"=>959,
|
78
|
+
"oplus"=>8853, "or"=>8744, "ordf"=>170, "ordm"=>186, "oslash"=>248,
|
79
|
+
"otilde"=>245, "otimes"=>8855, "ouml"=>246, "para"=>182, "part"=>8706,
|
80
|
+
"permil"=>8240, "perp"=>8869, "phi"=>966, "pi"=>960, "piv"=>982,
|
81
|
+
"plusmn"=>177, "pound"=>163, "prime"=>8242, "prod"=>8719, "prop"=>8733,
|
82
|
+
"psi"=>968, "quot"=>34, "rArr"=>8658, "radic"=>8730, "rang"=>9002,
|
83
|
+
"raquo"=>187, "rarr"=>8594, "rceil"=>8969, "rdquo"=>8221, "real"=>8476,
|
84
|
+
"reg"=>174, "rfloor"=>8971, "rho"=>961, "rlm"=>8207, "rsaquo"=>8250,
|
85
|
+
"rsquo"=>8217, "sbquo"=>8218, "scaron"=>353, "sdot"=>8901, "sect"=>167,
|
86
|
+
"shy"=>173, "sigma"=>963, "sigmaf"=>962, "sim"=>8764, "spades"=>9824,
|
87
|
+
"sub"=>8834, "sube"=>8838, "sum"=>8721, "sup"=>8835, "sup1"=>185, "sup2"=>178,
|
88
|
+
"sup3"=>179, "supe"=>8839, "szlig"=>223, "tau"=>964, "there4"=>8756,
|
89
|
+
"theta"=>952, "thetasym"=>977, "thinsp"=>8201, "thorn"=>254, "tilde"=>732,
|
90
|
+
"times"=>215, "trade"=>8482, "uArr"=>8657, "uacute"=>250, "uarr"=>8593,
|
91
|
+
"ucirc"=>251, "ugrave"=>249, "uml"=>168, "upsih"=>978, "upsilon"=>965,
|
92
|
+
"uuml"=>252, "weierp"=>8472, "xi"=>958, "yacute"=>253, "yen"=>165,
|
93
|
+
"yuml"=>255, "zeta"=>950, "zwj"=>8205, "zwnj"=>8204}
|
94
|
+
end
|
95
|
+
end
|