diff --git a/Gemfile b/Gemfile index b92ca150c9..96aa3a4585 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index f71cefb8f8..d311f2ff1b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3fea88cfa2..8e6163b672 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/emailer/receive.rb b/app/models/emailer/receive.rb index 546dd186ea..c0cd0abec5 100644 --- a/app/models/emailer/receive.rb +++ b/app/models/emailer/receive.rb @@ -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 diff --git a/app/models/user/example_project.rb b/app/models/user/example_project.rb index cde17e8bf2..804f698e15 100644 --- a/app/models/user/example_project.rb +++ b/app/models/user/example_project.rb @@ -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.") diff --git a/app/views/notes/_fields.haml b/app/views/notes/_fields.haml index e906f50488..0a7f74ca35 100644 --- a/app/views/notes/_fields.haml +++ b/app/views/notes/_fields.haml @@ -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' diff --git a/app/views/projects/show.haml b/app/views/projects/show.haml index 6100c287bf..c30150abb4 100644 --- a/app/views/projects/show.haml +++ b/app/views/projects/show.haml @@ -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) diff --git a/lib/html_formatting.rb b/lib/html_formatting.rb index 7bf6b0368b..6a72f457d2 100644 --- a/lib/html_formatting.rb +++ b/lib/html_formatting.rb @@ -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 \ No newline at end of file diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 25ccdff7c0..a762303d30 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -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 == "

She used to mean so much to ME!

" + comment.body_html.should == "

She used to mean so much to ME!

\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 == "

She used to mean:

\n" + comment.body_html.should == "

She used to mean:

\n\n\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 == "

she@couchsurfing.org used to mean so much to www.teambox.com

" + comment.body_html.should == "

she@couchsurfing.org used to mean so much to www.teambox.com

\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 == "

I loved that quote: I like the Divers, but they want me want to go to a war. Great page, too.

" + comment.body_html.should == %Q{

I loved that quote: "I like the Divers, but they want me want to go to a war." Great page, too.

\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 == "

I’d link my competitors’ mistakes, but that’d give them free traffic. So instead I link www.google.com.

" + comment.body_html.should == %Q{

I'd link my competitors' mistakes (www.failblog.org) but that'd give them free traffic. So instead I link www.google.com.

\n} end it "should preserve html links and images" do body = 'Did you know the logo from Teambox has carefully selected colors? ' comment = Factory.create(:comment, :body => body, :project => @project, :user => @user, :target => @project) - comment.body_html.should == "

Did you know the logo from Teambox has carefully selected colors?

" + comment.body_html.should == %Q{

Did you know the logo from Teambox has carefully selected colors?

\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 == "

@existing, hey, @existing

" + comment.body_html.should == %Q{

@existing, hey, @existing

\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 == "

@pablo @james Check this out!

" + comment.body_html.should == %Q{

@pablo @james Check this out!

\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 == '

@all hands on deck this Friday

' + comment.body_html.should == %Q{

@all hands on deck this Friday

\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 == "

@existing is a cool guy, but he is not in this project

" + comment.body_html.should == "

@existing is a cool guy, but he is not in this project

\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 == "

Hey, @unexisting, take a look at this!

" + comment.body_html.should == "

Hey, @unexisting, take a look at this!

\n" comment.mentioned.should == nil end end