Skip to content

Instantly share code, notes, and snippets.

@blindFS
Created October 23, 2013 03:08
Show Gist options
  • Save blindFS/7112026 to your computer and use it in GitHub Desktop.
Save blindFS/7112026 to your computer and use it in GitHub Desktop.
module Jekyll
class ColoredTag< Liquid::Tag
Syntax = /^\s*(#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3}|rgb[a]{0,1}\([ .0-9,]{5,}\))\s*(#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3}|rgb[a]{0,1}\([ .0-9,]{5,}\))?\s*"([^"]*)"\s*$/
def initialize(tagName, markup, tokens)
if markup =~ Syntax then
@bg = $1
if $3.nil? then
@fg = "#ffffff"
@text = $2
else
@fg = $2
@text = $3
end
else
raise "Invalid colors"
end
end
def render(context)
"<div style=\"display: inline;background-color:#{@bg};color:#{@fg}\">#{@text}</div>"
end
Liquid::Template.register_tag('colored', Jekyll::ColoredTag)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment