-
-
Save BjornFJohansson/a8a2b246f22012d3f2a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Jekyll | |
class RenderImgTag < Liquid::Tag | |
def initialize(tag_name, text, tokens) | |
super | |
@url , *@val= text.split(/ /) | |
if @val.length > 0 | |
@width , *@height = @val[0].split(/x/) | |
end | |
@img_style = "width:#{@width}px;" | |
if @height.length > 0 | |
@img_style = @img_style + "height:#{@height[0]}px;" | |
end | |
end | |
def render(context) | |
"<img src=\"#{@url}\" style=\"#{@img_style}\">" | |
end | |
end | |
end | |
Liquid::Template.register_tag('img', Jekyll::RenderImgTag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment