Extending RedCloth to use custom tags.
After finding the GitHub jQuery Repo Widget I want to embed the widget in my blog posts. The body of which uses RedCloth So I needed to add a custom tag which could turn.
github. JoelSutherland/GitHub-jQuery-Repo-Widget
into
<div class="github-widget" data-repo="JoelSutherland/GitHub-jQuery-Repo-Widget"></div>
You can extend RedCloth’s HTML formatter by placing something like this in config/initializer/redcloth_extensions.rb for example.
require 'redcloth'
module RedCloth
module Extensions
def github(options)
html = %Q{<div class="github-widget" data-repo="#{options[:text]}"></div>\n}
end
end
end
RedCloth::Formatters::HTML.send(:include, RedCloth::Extensions)
And there you have it.
github. JoelSutherland/GitHub-jQuery-Repo-Widget