]> source.dussan.org Git - redmine.git/commitdiff
Convert HTML links to Textile/Markdown links when creating an issue from an email...
authorGo MAEDA <maeda@farend.jp>
Sun, 11 Aug 2019 05:01:37 +0000 (05:01 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 11 Aug 2019 05:01:37 +0000 (05:01 +0000)
Patch by Yuichi HARADA.

git-svn-id: http://svn.redmine.org/redmine/trunk@18361 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/wiki_formatting/html_parser.rb
lib/redmine/wiki_formatting/markdown/html_parser.rb
lib/redmine/wiki_formatting/textile/html_parser.rb
test/unit/lib/redmine/wiki_formatting/markdown_html_parser_test.rb
test/unit/lib/redmine/wiki_formatting/textile_html_parser_test.rb

index 80f15b72ca90e2d89b366df0777b38d2e0c7feb4..f6f9639e001ef3f497980f6bb15d8e299fb2743d 100644 (file)
@@ -36,7 +36,7 @@ module Redmine
         doc.scrub!(WikiTags.new(tags))
         doc.scrub!(:newline_block_elements)
 
-        Loofah.remove_extraneous_whitespace(doc.text).strip.squeeze(' ').gsub(/^ +/, '')
+        Loofah.remove_extraneous_whitespace(doc.text(:encode_special_chars => false)).strip.squeeze(' ').gsub(/^ +/, '')
       end
 
       class WikiTags < ::Loofah::Scrubber
@@ -54,6 +54,9 @@ module Redmine
           when String
             node.add_next_sibling Nokogiri::XML::Text.new(formatting, node.document)
             node.remove
+          when Proc
+            node.add_next_sibling formatting.call(node)
+            node.remove
           else
             CONTINUE
           end
index 8cc0eaccdddf22fcdbd3dc88563c2203ae480453..c9f83ffe69b94350cc21497d8cb24344609537d6 100644 (file)
@@ -34,7 +34,8 @@ module Redmine
           'h3' => {:pre => "\n\n### ", :post => "\n\n"},
           'h4' => {:pre => "\n\n#### ", :post => "\n\n"},
           'h5' => {:pre => "\n\n##### ", :post => "\n\n"},
-          'h6' => {:pre => "\n\n###### ", :post => "\n\n"}
+          'h6' => {:pre => "\n\n###### ", :post => "\n\n"},
+          'a' => lambda {|node| node.content.present? ? %| [#{node.content}](#{node.attributes['href'].value}) | : %| #{node.attributes['href'].value} |}
         )
       end
     end
index 72890871e449c1701777a2ba71ce29d2a63a5361..7d91734785002a2d27c532ff824a4cb576408d4c 100644 (file)
@@ -34,7 +34,8 @@ module Redmine
           'h3' => {:pre => "\n\nh3. ", :post => "\n\n"},
           'h4' => {:pre => "\n\nh4. ", :post => "\n\n"},
           'h5' => {:pre => "\n\nh5. ", :post => "\n\n"},
-          'h6' => {:pre => "\n\nh6. ", :post => "\n\n"}
+          'h6' => {:pre => "\n\nh6. ", :post => "\n\n"},
+          'a' => lambda {|node| node.content.present? ? %| "#{node.content}":#{node.attributes['href'].value} | : %| #{node.attributes['href'].value} |}
         )
       end
     end
index 63fc4ae5c3419618470302ff61afeec7266ca6b5..6a4b77387cbe116f316d4b9f0951afaa1a5b49be 100644 (file)
@@ -28,5 +28,10 @@ class Redmine::WikiFormatting::MarkdownHtmlParserTest < ActiveSupport::TestCase
   def test_should_convert_tags
     assert_equal 'A **simple** html snippet.',
       @parser.to_text('<p>A <b>simple</b> html snippet.</p>')
+
+    assert_equal 'foo [bar](http://example.com/) baz',
+      @parser.to_text('foo<a href="http://example.com/">bar</a>baz')
+    assert_equal 'foo http://example.com/ baz',
+      @parser.to_text('foo<a href="http://example.com/"></a>baz')
   end
 end
index 8d6f786891fe508248bf50303b36b58a8a607620..a338ed528b6cbec7c6277eb6226228f81715ba83 100644 (file)
@@ -28,5 +28,10 @@ class Redmine::WikiFormatting::TextileHtmlParserTest < ActiveSupport::TestCase
   def test_should_convert_tags
     assert_equal 'A *simple* html snippet.',
       @parser.to_text('<p>A <b>simple</b> html snippet.</p>')
+
+    assert_equal 'foo "bar":http://example.com/ baz',
+      @parser.to_text('foo<a href="http://example.com/">bar</a>baz')
+    assert_equal 'foo http://example.com/ baz',
+      @parser.to_text('foo<a href="http://example.com/"></a>baz')
   end
 end