Permalink
Browse files

added Redcarpet filter (Markdown rendering)

  • Loading branch information...
1 parent efb8515 commit 580f187c7ad54c65a51fdbe20ebe7cdcddf3a912 @rbq committed Aug 11, 2011
Showing with 37 additions and 0 deletions.
  1. +2 −0 CHANGELOG.md
  2. +1 −0 auto_html.gemspec
  3. +9 −0 lib/auto_html/filters/redcarpet.rb
  4. +25 −0 test/unit/filters/redcarpet_test.rb
View
@@ -1,3 +1,5 @@
+* added Redcarpet filter (Markdown rendering)
+
## 1.4.1, released 2011-07-09
* AutoHtml gets module method: AutoHtml.auto_html(...)
* on blank filter list return input instead of nil
View
@@ -13,6 +13,7 @@ Gem::Specification.new do |gem|
gem.add_dependency('rinku')
gem.add_dependency('tag_helper')
gem.add_dependency('RedCloth')
+ gem.add_dependency('redcarpet')
# ensure the gem is built out of versioned files
gem.files = Dir['Rakefile', '{bin,lib,man,test,spec}/**/*',
@@ -0,0 +1,9 @@
+require 'redcarpet'
+
+AutoHtml.add_filter(:redcarpet).with({}) do |text, options|
+ result = Redcarpet.new(text).to_html
+ if options and options[:target] and options[:target].to_sym == :_blank
+ result.gsub!(/<a/,'<a target="_blank"')
+ end
+ result
+end
@@ -0,0 +1,25 @@
+require File.expand_path('../../unit_test_helper', __FILE__)
+
+class RedcarpetTest < Test::Unit::TestCase
+
+ def test_transform_strong
+ result = auto_html("This is **my** text.") { redcarpet }
+ assert_equal '<p>This is <strong>my</strong> text.</p>'+"\n", result
+ end
+
+ def test_transform_title
+ result = auto_html("## This is a title ##") { redcarpet }
+ assert_equal '<h2>This is a title</h2>'+"\n", result
+ end
+
+ def test_transform_link
+ result = auto_html('[This is a link](http://example.org/)') { redcarpet }
+ assert_equal '<p><a href="http://example.org/">This is a link</a></p>'+"\n", result
+ end
+
+ def test_transform_link_target_blank
+ result = auto_html('[This is a link](http://example.org/)') { redcarpet :target => :_blank }
+ assert_equal '<p><a target="_blank" href="http://example.org/">This is a link</a></p>'+"\n", result
+ end
+
+end

0 comments on commit 580f187

Please sign in to comment.