Permalink
Browse files

Textile → Markdown

  • Loading branch information...
1 parent c7dcad7 commit bd0135757b2e995bc5d358c0d1a3bee6de9e2963 @mislav mislav committed Apr 20, 2010
View
@@ -14,7 +14,7 @@ gem 'SystemTimer', '~> 1.2.0', :require => 'system_timer'
gem 'whenever', '~> 0.4.1', :require => nil
gem 'icalendar', '~> 1.1.3'
gem 'libxml-ruby', '~> 1.1.3', :require => 'libxml'
-gem 'RedCloth', '~> 4.2.3'
+gem 'rdiscount', '~> 1.6.3'
gem 'haml', '~> 3.0.0.beta1'
gem 'mysql', '~> 2.8.1'
gem 'aws-s3', '~> 0.6.2', :require => 'aws/s3'
View
@@ -110,6 +110,10 @@ dependencies:
group:
- :testing
version: ~> 0.2.1
+ rdiscount:
+ group:
+ - :default
+ version: ~> 1.6.3
i18n:
group:
- :rails
@@ -118,10 +122,6 @@ dependencies:
group:
- :default
version: ~> 0.8.2
- RedCloth:
- group:
- - :default
- version: ~> 4.2.3
builder:
group:
- :rails
@@ -139,8 +139,6 @@ dependencies:
specs:
- rake:
version: 0.8.7
-- RedCloth:
- version: 4.2.3
- SystemTimer:
version: "1.2"
- activesupport:
@@ -227,6 +225,8 @@ specs:
version: 0.2.8
- rails:
version: 2.3.5
+- rdiscount:
+ version: 1.6.3
- rspec:
version: 1.3.0
- rspec-rails:
@@ -251,7 +251,7 @@ specs:
version: 0.3.19
- whenever:
version: 0.4.1
-hash: 9e2b04dc2b15335a4fc78e85ff2e93a23ebc57ea
+hash: 38bc99b5d418e31bbd105cc90ebf012674c413eb
sources:
- Rubygems:
uri: http://gemcutter.org
@@ -290,8 +290,8 @@ def link_to_public_page(name)
end
end
- def textile_documentation_link
- link_to t('.text_styling'), 'http://help.teambox.com/faqs/advanced-features/textile', :target => '_blank'
+ def formatting_documentation_link
+ link_to t('.text_styling'), 'http://daringfireball.net/projects/markdown/', :target => '_blank'
end
def host_with_protocol
@@ -12,7 +12,7 @@
# Invalid or malformed emails will be ignored
#
# TODO: Enhance mime and plain messages treatment
-# Parse html to textile
+# Parse HTML to Markdown
# Strip the quoted text from email replies
class Emailer
@@ -19,9 +19,9 @@ def find_or_create_example_project
example_comment(@project, @dagny, "Hey guys, I'm setting up a project on Teambox to build the John Galt line. Hope it helps!")
example_comment(@project, @ellis, "Cool, Dagny. Let's learn how to use this.")
example_comment(@project, @hank, "@ellis, you'll get a hold of it in no time. My guys at the coal and steel places use it to work closely in teams.")
- example_comment(@project, @dagny, "The way I use it is creating a *Project* for each event, department or project we have. Then I *invite* all the people concerned with it, so they can post and receive updates.\n\nProjects have:\n\n* Conversations\n* Task lists\n* Pages\n* Files")
- example_comment(@project, @hank, "I like to use the project *wall* to leave interesting links that don't require much attention.\n\nEmail is too intrusive, so the wall is the perfect place to leave comments and advice.\n\nhttp://www.teambox.com")
- example_comment(@project, @dagny, "You can also post using HTML styles and sexy \"Textile\":www.redcloth.org/textile markup!")
+ example_comment(@project, @dagny, "The way I use it is creating a **Project** for each event, department or project we have. Then I *invite* all the people concerned with it, so they can post and receive updates.\n\nProjects have:\n\n* Conversations\n* Task lists\n* Pages\n* Files")
+ example_comment(@project, @hank, "I like to use the project **wall** to leave interesting links that don't require much attention.\n\nEmail is too intrusive, so the wall is the perfect place to leave comments and advice.\n\nhttp://www.teambox.com")
+ example_comment(@project, @dagny, "You can also format your text using [Markdown](http://daringfireball.net/projects/markdown/).")
example_comment(@project, @ellis, "Very nice! I also noticed I can post files to a project wall. I can use this to call attention on images or quick ideas.")
example_comment(@project, @ellis, "I'm going to invite #{name} to the project, too.\nHey, @#{login}, read below to learn how Teambox works! Also take a look at \"Conversations\":#{project_conversations_path(@project)}, \"Task lists\":#{project_task_lists_path(@project)}, \"Pages\":#{project_pages_path(@project)} and \"Files\":#{project_uploads_path(@project)} to learn more about how each section works.")
example_comment(@project, @dagny, "Welcome, @#{login}! This is the project wall, try posting a comment with the box on top. You can also attach files!\nIn this page you will find updated to your conversations, tasks and pages, so taking a look here will let you know what's new in your project.")
@@ -1,5 +1,5 @@
.documentation
- = textile_documentation_link
+ = formatting_documentation_link
.name.text_field
= f.label :name, t('.title'), :size => 74
= f.text_field :name, :class => 'focus'
@@ -8,7 +8,7 @@
%h2
= t('.update_your_status')
%span.help
- = textile_documentation_link
+ = formatting_documentation_link
= new_comment_form(@current_project,@current_project.comments.new)
@@ -10,7 +10,7 @@ def format_attributes
self["#{attr}_html"] = if text.blank?
nil
else
- text = format_textile(text)
+ text = format_text(text)
text = format_usernames(text)
text = format_links(text)
white_list_sanitizer.sanitize(text)
@@ -38,15 +38,13 @@ def format_usernames(body)
end
end
- def format_textile(text)
- textilized = RedCloth.new(text, [:hard_breaks, :no_span_caps])
- textilized.hard_breaks = true if textilized.respond_to?("hard_breaks=")
+ def format_text(text)
+ textilized = RDiscount.new(text)
textilized.to_html
end
def format_links(text)
linked = auto_link(text) { |text| truncate(text, :length => 40) }
- linked.gsub(/href=\"www/i) { |s| "href=\"http://www" }
end
end
@@ -94,39 +94,39 @@
end
it "should format text" do
- body = "She *used* to _mean_ so much to ME!"
+ body = "She **used** to _mean_ so much to ME!"
comment = Factory.create(:comment, :body => body, :project => @project, :user => @user, :target => @project)
- comment.body_html.should == "<p>She <strong>used</strong> to <em>mean</em> so much to ME!</p>"
+ comment.body_html.should == "<p>She <strong>used</strong> to <em>mean</em> so much to ME!</p>\n"
end
it "should format lists" do
- body = "She used to mean:\n* So\n* much\n* to\n * me!"
+ body = "She used to mean:\n\n* So\n* much\n* to\n * me!"
comment = Factory.create(:comment, :body => body, :project => @project, :user => @user, :target => @project)
- comment.body_html.should == "<p>She used to mean:</p>\n<ul>\n\t<li>So</li>\n\t<li>much</li>\n\t<li>to</li>\n\t<li>me!</li>\n</ul>"
+ comment.body_html.should == "<p>She used to mean:</p>\n\n<ul>\n<li>So</li>\n<li>much</li>\n<li>to</li>\n<li>me!</li>\n</ul>\n\n"
end
it "should format emails and links" do
body = 'she@couchsurfing.org used to mean so much to www.teambox.com'
comment = Factory.create(:comment, :body => body, :project => @project, :user => @user, :target => @project)
- comment.body_html.should == "<p><a href=\"mailto:she@couchsurfing.org\">she@couchsurfing.org</a> used to mean so much to <a href=\"http://www.teambox.com\">www.teambox.com</a></p>"
+ comment.body_html.should == "<p><a href=\"mailto:she@couchsurfing.org\">she@couchsurfing.org</a> used to mean so much to <a href=\"http://www.teambox.com\">www.teambox.com</a></p>\n"
end
- it "should turn to links textile links" do
- body = 'I loved that quote: "I like the Divers, but they want me want to go to a war":http://www.shmoop.com/tender-is-the-night/tommy-barban.html. Great page, too.'
+ it "should convert markdown links" do
+ body = 'I loved that quote: ["I like the Divers, but they want me want to go to a war."](http://www.shmoop.com/tender-is-the-night/tommy-barban.html) Great page, too.'
comment = Factory.create(:comment, :body => body, :project => @project, :user => @user, :target => @project)
- comment.body_html.should == "<p>I loved that quote: <a href=\"http://www.shmoop.com/tender-is-the-night/tommy-barban.html\">I like the Divers, but they want me want to go to a war</a>. Great page, too.</p>"
+ comment.body_html.should == %Q{<p>I loved that quote: <a href="http://www.shmoop.com/tender-is-the-night/tommy-barban.html">"I like the Divers, but they want me want to go to a war."</a> Great page, too.</p>\n}
end
it "should add http:// in front of links to www.site.com" do
- body = "I'd link my competitors' \"mistakes\":www.failblog.org, but that'd give them free traffic. So instead I link www.google.com."
+ body = "I'd link my competitors' mistakes (www.failblog.org) but that'd give them free traffic. So instead I link www.google.com."
comment = Factory.create(:comment, :body => body, :project => @project, :user => @user, :target => @project)
- comment.body_html.should == "<p>I&#8217;d link my competitors&#8217; <a href=\"http://www.failblog.org\">mistakes</a>, but that&#8217;d give them free traffic. So instead I link <a href=\"http://www.google.com\">www.google.com</a>.</p>"
+ comment.body_html.should == %Q{<p>I'd link my competitors' mistakes (<a href="http://www.failblog.org">www.failblog.org</a>) but that'd give them free traffic. So instead I link <a href="http://www.google.com">www.google.com</a>.</p>\n}
end
it "should preserve html links and images" do
body = 'Did you know the logo from Teambox has <a href="http://en.wikipedia.org/wiki/Color_theory">carefully selected colors</a>? <img src="http://app.teambox.com/images/header_logo_large.jpg"/>'
comment = Factory.create(:comment, :body => body, :project => @project, :user => @user, :target => @project)
- comment.body_html.should == "<p>Did you know the logo from Teambox has <a href=\"http://en.wikipedia.org/wiki/Color_theory\">carefully selected colors</a>? <img src=\"http://app.teambox.com/images/header_logo_large.jpg\" /></p>"
+ comment.body_html.should == %Q{<p>Did you know the logo from Teambox has <a href="http://en.wikipedia.org/wiki/Color_theory">carefully selected colors</a>? <img src="http://app.teambox.com/images/header_logo_large.jpg" /></p>\n}
end
it "should preserve blocks of code and pre"
@@ -142,7 +142,7 @@
@project.add_user(@user)
body = "@existing, hey, @existing"
comment = Factory(:comment, :body => body, :project => @project, :user => @project.user, :target => @project)
- comment.body_html.should == "<p>@<a href=\"/users/existing\">existing</a>, hey, @<a href=\"/users/existing\">existing</a></p>"
+ comment.body_html.should == %Q{<p>@<a href="/users/existing">existing</a>, hey, @<a href="/users/existing">existing</a></p>\n}
comment.mentioned.should == [@user]
end
@@ -153,7 +153,7 @@
@project.add_user(james)
body = "@pablo @james Check this out!"
comment = Factory(:comment, :body => body, :project => @project, :user => @project.user, :target => @project)
- comment.body_html.should == "<p>@<a href=\"/users/pablo\">pablo</a> @<a href=\"/users/james\">james</a> Check this out!</p>"
+ comment.body_html.should == %Q{<p>@<a href="/users/pablo">pablo</a> @<a href="/users/james">james</a> Check this out!</p>\n}
comment.mentioned.should include(pablo)
comment.mentioned.should include(james)
end
@@ -165,7 +165,7 @@
@project.add_user(james)
body = "@all hands on deck this Friday"
comment = Factory(:comment, :body => body, :project => @project, :user => @project.user, :target => @project)
- comment.body_html.should == '<p><span class="mention_all">@all</span> hands on deck this Friday</p>'
+ comment.body_html.should == %Q{<p><span class="mention_all">@all</span> hands on deck this Friday</p>\n}
comment.mentioned.should include(pablo)
comment.mentioned.should include(james)
comment.mentioned.should_not include(@user)
@@ -213,14 +213,14 @@
it "should not link to users page when mentioning @existing if they are not in the project" do
body = "@existing is a cool guy, but he is not in this project"
comment = Factory.create(:comment, :body => body, :project => @project, :user => @project.user, :target => @project)
- comment.body_html.should == "<p>@existing is a cool guy, but he is not in this project</p>"
+ comment.body_html.should == "<p>@existing is a cool guy, but he is not in this project</p>\n"
comment.mentioned.should == nil
end
it "should not link to users page when typing @unexisting" do
body = "Hey, @unexisting, take a look at this!"
comment = Factory.create(:comment, :body => body, :project => @project, :user => @project.user, :target => @project)
- comment.body_html.should == "<p>Hey, @unexisting, take a look at this!</p>"
+ comment.body_html.should == "<p>Hey, @unexisting, take a look at this!</p>\n"
comment.mentioned.should == nil
end
end

0 comments on commit bd01357

Please sign in to comment.