From 85d5ede2cf9355a76e9d05e6843a86dcc63c34c2 Mon Sep 17 00:00:00 2001 From: ironbishop Date: Thu, 17 Jul 2014 14:47:55 +0200 Subject: [PATCH 1/2] support for space in file name This regular expression enable spaces in file names. See test [before](http://rubular.com/r/DXcgehTAEV) and [after](http://rubular.com/r/INFxSJKXTe). --- plugins/image_tag.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/image_tag.rb b/plugins/image_tag.rb index 4567000707c..35b18640dd4 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 From c4e073d215cb2e4e03692db6b2b863de5560d1ae Mon Sep 17 00:00:00 2001 From: ironbishop <ironbishop@fsfe.org> Date: Fri, 18 Jul 2014 12:05:42 +0200 Subject: [PATCH 2/2] support for percent in dimensions New regexp, [tested](http://rubular.com/r/326X87G40B), adding % for width/height. Using style property, since in HTML5 the <img> width/height must be in pixels. --- plugins/image_tag.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/image_tag.rb b/plugins/image_tag.rb index 35b18640dd4..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 =~ /(?<class>\S.*\s+)?(?<src>(?:https?:\/\/|\/|\S+\/)\S+( +\S+)*\.\S+)(?:\s+(?<width>\d+))?(?:\s+(?<height>\d+))?(?<title>\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