meteor 0.9.33 → 0.9.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog +8 -0
- data/Gemfile.lock +1 -1
- data/lib/meteor/core/kernel.rb +97 -96
- data/lib/meteor/core/util/pattern_cache.rb +1 -1
- data/lib/meteor/element.rb +34 -27
- data/lib/meteor/elements.rb +1 -1
- data/lib/meteor/ml/html/parser_impl.rb +30 -35
- data/lib/meteor/ml/html4/parser_impl.rb +68 -65
- data/lib/meteor/ml/xhtml/parser_impl.rb +31 -34
- data/lib/meteor/ml/xhtml4/parser_impl.rb +50 -50
- data/lib/meteor/ml/xml/parser_impl.rb +5 -4
- data/lib/meteor.rb +2 -2
- metadata +1 -1
|
@@ -7,18 +7,18 @@ module Meteor
|
|
|
7
7
|
#
|
|
8
8
|
# XHTML4 parser (XHTML4パーサ)
|
|
9
9
|
#
|
|
10
|
-
class ParserImpl < Meteor::Core::Kernel
|
|
10
|
+
class ParserImpl < Meteor::Core::Kernel # rubocop:disable Metrics/ClassLength
|
|
11
11
|
# KAIGYO_CODE = "\r?\n|\r"
|
|
12
12
|
KAIGYO_CODE = ["\r\n", "\n", "\r"].freeze
|
|
13
13
|
BR = '<br/>'
|
|
14
14
|
BR_RE = '<br\\/>'
|
|
15
15
|
|
|
16
|
-
#
|
|
16
|
+
# MATCH_TAG_TWO = "textarea|option|pre"
|
|
17
17
|
# [Array] elements where line breaks do not need to be converted to <br> (改行を<br/>に変換する必要のない要素)
|
|
18
|
-
|
|
18
|
+
MATCH_TAG_TWO = %w[textarea option pre].freeze
|
|
19
19
|
|
|
20
20
|
# [Array] boolean attributes (論理値で指定する属性)
|
|
21
|
-
|
|
21
|
+
ATTR_BOOL = %w[disabled readonly checked selected multiple].freeze
|
|
22
22
|
|
|
23
23
|
# DISABLE_ELEMENT = "input|textarea|select|optgroup"
|
|
24
24
|
# [Array] element with disablled attribute (disabled属性のある要素)
|
|
@@ -48,24 +48,24 @@ module Meteor
|
|
|
48
48
|
MULTIPLE_R = 'multiple="[^"]*"'
|
|
49
49
|
MULTIPLE_U = 'multiple="multiple"'
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
#
|
|
68
|
-
#
|
|
51
|
+
RE_SELECTED_M = Regexp.new(SELECTED_M)
|
|
52
|
+
RE_SELECTED_M1 = Regexp.new(SELECTED_M1)
|
|
53
|
+
RE_SELECTED_R = Regexp.new(SELECTED_R)
|
|
54
|
+
RE_CHECKED_M = Regexp.new(CHECKED_M)
|
|
55
|
+
RE_CHECKED_M1 = Regexp.new(CHECKED_M1)
|
|
56
|
+
RE_CHECKED_R = Regexp.new(CHECKED_R)
|
|
57
|
+
RE_DISABLED_M = Regexp.new(DISABLED_M)
|
|
58
|
+
RE_DISABLED_M1 = Regexp.new(DISABLED_M1)
|
|
59
|
+
RE_DISABLED_R = Regexp.new(DISABLED_R)
|
|
60
|
+
RE_READONLY_M = Regexp.new(READONLY_M)
|
|
61
|
+
RE_READONLY_M1 = Regexp.new(READONLY_M1)
|
|
62
|
+
RE_READONLY_R = Regexp.new(READONLY_R)
|
|
63
|
+
RE_MULTIPLE_M = Regexp.new(MULTIPLE_M)
|
|
64
|
+
RE_MULTIPLE_M1 = Regexp.new(MULTIPLE_M1)
|
|
65
|
+
RE_MULTIPLE_R = Regexp.new(MULTIPLE_R)
|
|
66
|
+
|
|
67
|
+
# RE_MATCH_TAG = Regexp.new(MATCH_TAG)
|
|
68
|
+
# RE_MATCH_TAG_TWO = Regexp.new(MATCH_TAG_TWO)
|
|
69
69
|
|
|
70
70
|
#
|
|
71
71
|
# initializer (イニシャライザ)
|
|
@@ -172,18 +172,18 @@ module Meteor
|
|
|
172
172
|
private :analyze_newline
|
|
173
173
|
|
|
174
174
|
def edit_attrs_(elm, attr_name, attr_value)
|
|
175
|
-
if
|
|
176
|
-
edit_attrs_five(elm, attr_value,
|
|
177
|
-
elsif
|
|
178
|
-
edit_attrs_five(elm, attr_value,
|
|
179
|
-
elsif
|
|
180
|
-
edit_attrs_five(elm, attr_value,
|
|
181
|
-
elsif
|
|
182
|
-
edit_attrs_five(elm, attr_value,
|
|
183
|
-
elsif
|
|
184
|
-
(
|
|
185
|
-
|
|
186
|
-
edit_attrs_five(elm, attr_value,
|
|
175
|
+
if match?('selected', attr_name) && match?('option', elm.name)
|
|
176
|
+
edit_attrs_five(elm, attr_value, RE_SELECTED_M, RE_SELECTED_R, SELECTED_U)
|
|
177
|
+
elsif match?('multiple', attr_name) && match?('select', elm.name)
|
|
178
|
+
edit_attrs_five(elm, attr_value, RE_MULTIPLE_M, RE_MULTIPLE_R, MULTIPLE_U)
|
|
179
|
+
elsif match?('disabled', attr_name) && match?(DISABLE_ELEMENT, elm.name)
|
|
180
|
+
edit_attrs_five(elm, attr_value, RE_DISABLED_M, RE_DISABLED_R, DISABLED_U)
|
|
181
|
+
elsif match?('checked', attr_name) && match?('input', elm.name) && match?('radio', get_type(elm))
|
|
182
|
+
edit_attrs_five(elm, attr_value, RE_CHECKED_M, RE_CHECKED_R, CHECKED_U)
|
|
183
|
+
elsif match?('readonly', attr_name) &&
|
|
184
|
+
(match?('textarea',
|
|
185
|
+
elm.name) || (match?('input', elm.name) && match?(READONLY_TYPE, get_type(elm))))
|
|
186
|
+
edit_attrs_five(elm, attr_value, RE_READONLY_M, RE_READONLY_R, READONLY_U)
|
|
187
187
|
else
|
|
188
188
|
super(elm, attr_name, attr_value)
|
|
189
189
|
end
|
|
@@ -194,7 +194,7 @@ module Meteor
|
|
|
194
194
|
def edit_attrs_five(elm, attr_value, match_p, replace_regex, replace_update)
|
|
195
195
|
# attr_value = escape(attr_value)
|
|
196
196
|
|
|
197
|
-
if true.equal?(attr_value) ||
|
|
197
|
+
if true.equal?(attr_value) || match?('true', attr_value)
|
|
198
198
|
@res = match_p.match(elm.attributes)
|
|
199
199
|
|
|
200
200
|
if !@res
|
|
@@ -209,7 +209,7 @@ module Meteor
|
|
|
209
209
|
# replace attribute (属性の置換)
|
|
210
210
|
elm.attributes.gsub!(replace_regex, replace_update)
|
|
211
211
|
end
|
|
212
|
-
elsif false.equal?(attr_value) ||
|
|
212
|
+
elsif false.equal?(attr_value) || match?('false', attr_value)
|
|
213
213
|
# delete if attribute_name attrubute exeists (attr_name属性が存在するなら削除)
|
|
214
214
|
# replace attribute (属性の置換)
|
|
215
215
|
elm.attributes.gsub!(replace_regex, '')
|
|
@@ -219,18 +219,18 @@ module Meteor
|
|
|
219
219
|
private :edit_attrs_five
|
|
220
220
|
|
|
221
221
|
def get_attr_value_(elm, attr_name)
|
|
222
|
-
if
|
|
223
|
-
get_attr_value_r(elm, attr_name,
|
|
224
|
-
elsif
|
|
225
|
-
get_attr_value_r(elm, attr_name,
|
|
226
|
-
elsif
|
|
227
|
-
get_attr_value_r(elm, attr_name,
|
|
228
|
-
elsif
|
|
229
|
-
get_attr_value_r(elm, attr_name,
|
|
230
|
-
elsif
|
|
231
|
-
(
|
|
232
|
-
|
|
233
|
-
get_attr_value_r(elm, attr_name,
|
|
222
|
+
if match?('selected', attr_name) && match?('option', elm.name)
|
|
223
|
+
get_attr_value_r(elm, attr_name, RE_SELECTED_M1)
|
|
224
|
+
elsif match?('multiple', attr_name) && match?('select', elm.name)
|
|
225
|
+
get_attr_value_r(elm, attr_name, RE_MULTIPLE_M1)
|
|
226
|
+
elsif match?('diabled', attr_name) && match?(DISABLE_ELEMENT, elm.name)
|
|
227
|
+
get_attr_value_r(elm, attr_name, RE_DISABLED_M1)
|
|
228
|
+
elsif match?('checked', attr_name) && match?('input', elm.name) && match?('radio', get_type(elm))
|
|
229
|
+
get_attr_value_r(elm, attr_name, RE_CHECKED_M1)
|
|
230
|
+
elsif match?('readonly', attr_name) &&
|
|
231
|
+
(match?('textarea',
|
|
232
|
+
elm.name) || (match?('input', elm.name) && match?(READONLY_TYPE, get_type(elm))))
|
|
233
|
+
get_attr_value_r(elm, attr_name, RE_READONLY_M1)
|
|
234
234
|
else
|
|
235
235
|
super(elm, attr_name)
|
|
236
236
|
end
|
|
@@ -293,8 +293,8 @@ module Meteor
|
|
|
293
293
|
def get_attr_map(elm)
|
|
294
294
|
attrs = Meteor::AttributeMap.new
|
|
295
295
|
|
|
296
|
-
elm.attributes.scan(
|
|
297
|
-
if
|
|
296
|
+
elm.attributes.scan(RE_GET_ATTRS_MAP) do |a, b|
|
|
297
|
+
if match?(ATTR_BOOL, a) && a == b
|
|
298
298
|
attrs.store(a, 'true')
|
|
299
299
|
else
|
|
300
300
|
attrs.store(a, unescape(b))
|
|
@@ -20,10 +20,11 @@ module Meteor
|
|
|
20
20
|
}.freeze
|
|
21
21
|
|
|
22
22
|
PATTERN_ESCAPE = "[&\\\"'<>]"
|
|
23
|
-
@@pattern_escape = Regexp.new(PATTERN_ESCAPE)
|
|
24
23
|
|
|
25
24
|
PATTERN_UNESCAPE = '&(amp|quot|apos|gt|lt);'
|
|
26
|
-
|
|
25
|
+
|
|
26
|
+
RE_ESCAPE = Regexp.new(PATTERN_ESCAPE)
|
|
27
|
+
RE_UNESCAPE = Regexp.new(PATTERN_UNESCAPE)
|
|
27
28
|
|
|
28
29
|
#
|
|
29
30
|
# initializer (イニシャライザ)
|
|
@@ -119,7 +120,7 @@ module Meteor
|
|
|
119
120
|
|
|
120
121
|
def escape(content)
|
|
121
122
|
# replace special character (特殊文字の置換)
|
|
122
|
-
content.gsub(
|
|
123
|
+
content.gsub(RE_ESCAPE, TABLE_FOR_ESCAPE_)
|
|
123
124
|
end
|
|
124
125
|
|
|
125
126
|
private :escape
|
|
@@ -137,7 +138,7 @@ module Meteor
|
|
|
137
138
|
# 「"」<-「"」
|
|
138
139
|
# 「'」<-「'」
|
|
139
140
|
# 「&」<-「&」
|
|
140
|
-
content.gsub(
|
|
141
|
+
content.gsub(RE_UNESCAPE) do
|
|
141
142
|
case ::Regexp.last_match(1)
|
|
142
143
|
when 'amp'
|
|
143
144
|
'&'
|
data/lib/meteor.rb
CHANGED
|
@@ -37,11 +37,11 @@ require 'meteor/ml/xml/parser_impl'
|
|
|
37
37
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
38
38
|
#
|
|
39
39
|
# @author Yasumasa Ashida
|
|
40
|
-
# @version 0.9.
|
|
40
|
+
# @version 0.9.35
|
|
41
41
|
#
|
|
42
42
|
|
|
43
43
|
module Meteor
|
|
44
|
-
VERSION = '0.9.
|
|
44
|
+
VERSION = '0.9.35'
|
|
45
45
|
|
|
46
46
|
# require 'fileutils'
|
|
47
47
|
|