diff --git a/plugins/image_tag.rb b/plugins/image_tag.rb index 4567000707c..818581b1482 100644 --- a/plugins/image_tag.rb +++ b/plugins/image_tag.rb @@ -24,7 +24,7 @@ class ImageTag < Liquid::Tag def initialize(tag_name, markup, tokens) attributes = ['class', 'src', 'width', 'height', 'title'] - if markup =~ /(?\S.*\s+)?(?(?:https?:\/\/|\/|\S+\/)\S+)(?:\s+(?\d+))?(?:\s+(?\d+))?(?\s+.+)?/i + if markup =~ /(?<class>\S.*\s+)?(?<src>(?:https?:\/\/|\/|\S+\/)\S+( +\S+)*\.\S+)(?:\s+(?<width>\d+%?))?(?:\s+(?<height>\d+%?))?(?<title>\s+.+)?/i @img = attributes.reduce({}) { |img, attr| img[attr] = $~[attr].strip if $~[attr]; img } if /(?:"|')(?<title>[^"']+)?(?:"|')\s+(?:"|')(?<alt>[^"']+)?(?:"|')/ =~ @img['title'] @img['title'] = title @@ -32,6 +32,14 @@ def initialize(tag_name, markup, tokens) else @img['alt'] = @img['title'].gsub!(/"/, '"') if @img['title'] end + if /\d+%/ =~ @img['width'] + @img['style'] = "width: #{@img['width']};" + @img.delete('width') + end + if /\d+%/ =~ @img['height'] + @img['style'] = "#{@img['style']} height: #{@img['height']};" + @img.delete('height') + end @img['class'].gsub!(/"/, '') if @img['class'] end super