Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created September 22, 2009 16:00
Show Gist options
  • Save thinkerbot/191179 to your computer and use it in GitHub Desktop.
Save thinkerbot/191179 to your computer and use it in GitHub Desktop.
Custom RedCloth formatting
require 'rubygems'
require 'redcloth'
module CustomHTML
include RedCloth::Formatters::HTML
def custom(opts)
"<em>#{opts[:text].sub("hard.", "easy!")}</em>"
end
end
require 'test/unit'
require 'formatter'
class FormatterTest < Test::Unit::TestCase
def test_output_is_formatted
input = RedCloth.new %q{
h1. RedCloth Custom Tags
custom. Making a custom tag is hard.
}
standard = %Q{<h1>RedCloth Custom Tags</h1>\n<p>custom. Making a custom tag is hard.</p>}
assert_equal standard, input.to_html
custom = %Q{<h1>RedCloth Custom Tags</h1>\n<em>Making a custom tag is easy!</em>}
assert_equal custom, input.to(CustomHTML)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment