added support for width and height to image tag plugin

This commit is contained in:
Brandon Mathis 2011-07-29 18:29:39 -04:00
parent d6744967fa
commit c837acd497

View File

@ -17,12 +17,20 @@ module Jekyll
@img = nil @img = nil
@title = nil @title = nil
@class = '' @class = ''
@width = ''
@height = ''
def initialize(tag_name, markup, tokens) def initialize(tag_name, markup, tokens)
if markup =~ /(\S.*\s+)?(https?:\/\/|\/)(\S+)(\s+.+)?/i if markup =~ /(\S.*\s+)?(https?:\/\/|\/)(\S+)(\s+\d+\s+\d+)?(\s+.+)?/i
@class = $1 @class = $1 || ''
@img = $2 + $3 @img = $2 + $3
@title = $4 if $5
@title = $5.strip
end
if $4 =~ /\s*(\d+)\s+(\d+)/
@width = $1
@height = $2
end
end end
super super
end end
@ -30,9 +38,9 @@ module Jekyll
def render(context) def render(context)
output = super output = super
if @img if @img
"<img class='#{@class}' src='#{@img}' alt='#{@title}' title='#{@title}'>" "<img class='#{@class}' src='#{@img}' width='#{@width}' height='#{@height}' alt='#{@title}' title='#{@title}'>"
else else
"Error processing input, expected syntax: {% img [class name(s)] /url/to/image [title text] %}" "Error processing input, expected syntax: {% img [class name(s)] /url/to/image [width height] [title text] %}"
end end
end end
end end