Defect #20841
closed
  
Bare URLs in Markdown don't have "external" class
 
        
        Added by Go MAEDA about 10 years ago.
        Updated about 4 years ago.
        
  
  
  
  Description
  
  expected:
http://www.redmine.org/ =>
<a href="http://www.redmine.org/" class="external">http://www.redmine.org/</a>
	actual:
http://www.redmine.org/ =>
<a href="http://www.redmine.org/">http://www.redmine.org/</a>
	No problem in Textile formatter. Probably all versions that support Markdown are affected.
   
 
 
  
  
  
  
    
    
    
    
       - Target version set to Candidate for next minor release
The following patch fixes this issue.
Index: lib/redmine/wiki_formatting/markdown/formatter.rb
===================================================================
--- lib/redmine/wiki_formatting/markdown/formatter.rb    (revision 17445)
+++ lib/redmine/wiki_formatting/markdown/formatter.rb    (working copy)
@@ -123,7 +123,8 @@
           @@formatter ||= Redcarpet::Markdown.new(
             Redmine::WikiFormatting::Markdown::HTML.new(
               :filter_html => true,
-              :hard_wrap => true
+              :hard_wrap => true,
+              :link_attributes => {:class => 'external'}
             ),
             :autolink => true,
             :fenced_code_blocks => true,
 
   
  
  
    
    
    
    
       - Subject changed from No "external" class when bare url is used in Markdown formatter to Bare URLs in Markdown don't have "external" class
Go MAEDA wrote:
	The following patch fixes this issue.
	Unfortunately, it breaks some tests.
Failure:
ApplicationHelperTest#test_attachment_links_to_images_with_email_format_should_not_be_parsed [test/helpers/application_helper_test.rb:709]:
Expected /<p><a class="attachment" href="\/attachments\/75">image@2x.png<\/a> should not be parsed in image@2x.png<\/p>/ to match "<p><a class=\"attachment\" href=\"/attachments/75\">image@2x.png</a>\" class=\"external should not be parsed in <a href=\"mailto:image@2x.png\" class=\"external\">image@2x.png</a></p>\n".
bin/rails test test/helpers/application_helper_test.rb:698
.................................F
Failure:
ApplicationHelperTest#test_user_links_with_email_as_login_name_should_not_be_parsed_markdown [test/helpers/application_helper_test.rb:430]:
Expected /<p><a class=\"user active\".*>Bob Doe<\/a> should not be parsed in <a href=\"mailto:jsmith@somenet.foo\">jsmith@somenet.foo<\/a><\/p>/ to match "<p><a class=\"user active\" href=\"/users/14\">Bob Doe</a>\" class=\"external should not be parsed in <a href=\"mailto:jsmith@somenet.foo\" class=\"external\">jsmith@somenet.foo</a></p>\n".
bin/rails test test/helpers/application_helper_test.rb:424
 
   
  
  
    
    
    
    
       - Target version deleted (Candidate for next minor release)
 
   
  
  
  
  
    
    
    
    
       - Status changed from New to Closed
- Resolution set to Wont fix
The CommonMark formatter that will be available in Redmine 5.0.0 (#32424) correctly adds an "external" class. The existing RedCarpet based Markdown formatter still has this bug, but I don't think we need to make any effort to fix it because it is going to be dropped in the near future.
 
   
  
  
    
    
    
    
       - Has duplicate Feature #39003: Add css class to external links in markdown added
 
   
  
 
  
  
 
Also available in:  Atom
  PDF