Project

General

Profile

バグ #624 » openimg-20131102-2.diff

hycon miyagi, 2013-11-02 15:43

View differences:

core/plugin/openimg/openimg.rb
86 86

  
87 87
  def get_tag_by_attributes(tag)
88 88
    attribute = {}
89
    tag.each_matches(/([a-zA-Z0-9]+?)=(['"])(.*?)\2/){ |pair, pos|
89
    tag.each_matches(/\s*([^=]+)=(['"])(.*?)\2/){ |pair, pos|
90 90
      key, val = pair[1], pair[3]
91 91
      attribute[key] = val }
92 92
    attribute.freeze end
......
101 101
      attribute = {}
102 102
      catch(:imgtag_match){
103 103
        dom.gsub("\n", ' ').each_matches(Regexp.new("<#{tag_name}.*?>")){ |str, pos|
104
          attr = get_tag_by_attributes(str.to_s)
104
          attr = get_tag_by_attributes(str.to_s[tag_name.length + 1 .. -1])
105 105
          if element_rule.all?{ |k, v| v === attr[k] }
106 106
            attribute = attr.freeze
107 107
            throw :imgtag_match end } }
......
208 208
    t = fetch(url)
209 209
    /^(http:\/\/[^\/]+\/)post(\/\d+)/ =~ t
210 210
    if $~
211
      imgurlresolver($1 + "image" + $2, 'id' => 'content-image')
211
      imgurlresolver($1 + "image" + $2, {'tag' => 'img', 'id' => 'content-image', 'attribute' => 'data-src'})
212 212
    else
213 213
      warn "たんぶらの記事ページじゃないっぽい"
214 214
      nil
core/plugin/openimg/pattern_file.json
104 104
	"Tumblr image": {
105 105
		"url": "^http://[-0-9a-z]+\\.tumblr\\.com/image/\\d+",
106 106
		"attribute": {
107
			"id": "content-image"
107
			"id": "content-image",
108
			"attribute": "data-src",
109
			"tag": "img"
108 110
		}
109 111
	},
110 112
	"はてなフォトライフ": {
(2-2/3)