Created
September 22, 2009 16:00
-
-
Save thinkerbot/191179 to your computer and use it in GitHub Desktop.
Custom RedCloth formatting
This file contains hidden or 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
require 'rubygems' | |
require 'redcloth' | |
module CustomHTML | |
include RedCloth::Formatters::HTML | |
def custom(opts) | |
"<em>#{opts[:text].sub("hard.", "easy!")}</em>" | |
end | |
end |
This file contains hidden or 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
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