updated regex for crop in markdown

This commit is contained in:
Shiho Takagi committed 2014-09-18 14:18:18 +10:00
1 parent 374c17c928
commit dd75f2aef9
2 files changed
+11 -1

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ module Haml::Filters
def render(text)
# turn [tomato](crop) into [tomato](http://growstuff.org/crops/tomato)
expanded = text.gsub(/\[(.*?)\]\(crop\)/) do |m|
expanded = text.gsub(/\[([^\[\]]+?)\]\(crop\)/) do |m|
crop_str = $1
# find crop case-insensitively
crop = Crop.where('lower(name) = ?', crop_str.downcase).first
@@ -52,4 +52,14 @@ describe 'Haml::Filters::Growstuff_Markdown' do
rendered.should match /#{output_link(@crop, 'ToMaTo')}/
end
it "doesn't convert when it's not followed by '(crop)'" do
tomato = FactoryGirl.create(:tomato)
maize = FactoryGirl.create(:maize)
string = "[maize](http://example.com) #{input_link(tomato)}"
rendered = Haml::Filters::GrowstuffMarkdown.render(string)
rendered.should match /#{output_link(tomato)}/
rendered.should_not match /#{output_link(maize)}/
rendered.should match "<a href=\"http://example.com\">maize</a>"
end
end