diff --git a/app/views/posts/_single.html.haml b/app/views/posts/_single.html.haml
index dc22fc6aa..bd6122d0f 100644
--- a/app/views/posts/_single.html.haml
+++ b/app/views/posts/_single.html.haml
@@ -18,7 +18,7 @@
= post.created_at
.post-body
- :markdown
+ :growstuff_markdown
#{ strip_tags post.body }
- unless defined?(hide_comments)
diff --git a/lib/haml/filters/growstuff_markdown.rb b/lib/haml/filters/growstuff_markdown.rb
index 2670d7f81..e438ac271 100644
--- a/lib/haml/filters/growstuff_markdown.rb
+++ b/lib/haml/filters/growstuff_markdown.rb
@@ -5,11 +5,9 @@ module Haml::Filters
include Haml::Filters::Base
def render(text)
- bc = BlueCloth.new(text)
- orig = bc.text
# turn [tomato](crop) into [tomato](http://growstuff.org/crops/tomato)
- return orig.gsub(/\[(.*?)\]\(crop\)/) do |m|
+ expanded = text.gsub(/\[(.*?)\]\(crop\)/) do |m|
crop_str = $1
crop = Crop.find_by_name(crop_str)
if crop
@@ -19,6 +17,9 @@ module Haml::Filters
crop_str
end
end
+
+ return BlueCloth.new(expanded).to_html
+
end
end
diff --git a/spec/lib/haml/filters/growstuff_markdown_spec.rb b/spec/lib/haml/filters/growstuff_markdown_spec.rb
index b8a2a57c6..6218c54d4 100644
--- a/spec/lib/haml/filters/growstuff_markdown_spec.rb
+++ b/spec/lib/haml/filters/growstuff_markdown_spec.rb
@@ -7,7 +7,8 @@ def input_link(name)
end
def output_link(crop)
- return "[#{crop.name}](#{Rails.application.routes.url_helpers.crop_url(crop, :host => Growstuff::Application.config.host)})"
+ url = Rails.application.routes.url_helpers.crop_url(crop, :host => Growstuff::Application.config.host)
+ return "#{crop.name}"
end
describe 'Haml::Filters::Growstuff_Markdown' do
@@ -19,12 +20,12 @@ describe 'Haml::Filters::Growstuff_Markdown' do
it 'converts quick crop links' do
@crop = FactoryGirl.create(:crop)
rendered = Haml::Filters::GrowstuffMarkdown.render(input_link(@crop.name))
- rendered.should eq output_link(@crop)
+ rendered.should match /#{output_link(@crop)}/
end
it "doesn't convert nonexistent crops" do
rendered = Haml::Filters::GrowstuffMarkdown.render(input_link("not a crop"))
- rendered.should eq "not a crop"
+ rendered.should match /not a crop/
end
it "handles multiple crop links" do
@@ -32,7 +33,13 @@ describe 'Haml::Filters::Growstuff_Markdown' do
maize = FactoryGirl.create(:maize)
string = "#{input_link(tomato)} #{input_link(maize)}"
rendered = Haml::Filters::GrowstuffMarkdown.render(string)
- rendered.should eq "#{output_link(tomato)} #{output_link(maize)}"
+ rendered.should match /#{output_link(tomato)} #{output_link(maize)}/
+ end
+
+ it "converts normal markdown" do
+ string = "**foo**"
+ rendered = Haml::Filters::GrowstuffMarkdown.render(string)
+ rendered.should match /foo<\/strong>/
end
end