summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2019-08-11 05:01:37 +0000
committerGo MAEDA <maeda@farend.jp>2019-08-11 05:01:37 +0000
commitf5c7a4a4208c9c146544b4498de3a08761cbc55a (patch)
tree8612620b530885d8e69b3c122281312b35255e31
parent3c91a3d5b2f9a2ce55b941ee68fbaa596b5b3052 (diff)
downloadredmine-f5c7a4a4208c9c146544b4498de3a08761cbc55a.tar.gz
redmine-f5c7a4a4208c9c146544b4498de3a08761cbc55a.zip
Convert HTML links to Textile/Markdown links when creating an issue from an email (#31695).
Patch by Yuichi HARADA. git-svn-id: http://svn.redmine.org/redmine/trunk@18361 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--lib/redmine/wiki_formatting/html_parser.rb5
-rw-r--r--lib/redmine/wiki_formatting/markdown/html_parser.rb3
-rw-r--r--lib/redmine/wiki_formatting/textile/html_parser.rb3
-rw-r--r--test/unit/lib/redmine/wiki_formatting/markdown_html_parser_test.rb5
-rw-r--r--test/unit/lib/redmine/wiki_formatting/textile_html_parser_test.rb5
5 files changed, 18 insertions, 3 deletions
diff --git a/lib/redmine/wiki_formatting/html_parser.rb b/lib/redmine/wiki_formatting/html_parser.rb
index 80f15b72c..f6f9639e0 100644
--- a/lib/redmine/wiki_formatting/html_parser.rb
+++ b/lib/redmine/wiki_formatting/html_parser.rb
@@ -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
diff --git a/lib/redmine/wiki_formatting/markdown/html_parser.rb b/lib/redmine/wiki_formatting/markdown/html_parser.rb
index 8cc0eaccd..c9f83ffe6 100644
--- a/lib/redmine/wiki_formatting/markdown/html_parser.rb
+++ b/lib/redmine/wiki_formatting/markdown/html_parser.rb
@@ -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
diff --git a/lib/redmine/wiki_formatting/textile/html_parser.rb b/lib/redmine/wiki_formatting/textile/html_parser.rb
index 72890871e..7d9173478 100644
--- a/lib/redmine/wiki_formatting/textile/html_parser.rb
+++ b/lib/redmine/wiki_formatting/textile/html_parser.rb
@@ -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
diff --git a/test/unit/lib/redmine/wiki_formatting/markdown_html_parser_test.rb b/test/unit/lib/redmine/wiki_formatting/markdown_html_parser_test.rb
index 63fc4ae5c..6a4b77387 100644
--- a/test/unit/lib/redmine/wiki_formatting/markdown_html_parser_test.rb
+++ b/test/unit/lib/redmine/wiki_formatting/markdown_html_parser_test.rb
@@ -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
diff --git a/test/unit/lib/redmine/wiki_formatting/textile_html_parser_test.rb b/test/unit/lib/redmine/wiki_formatting/textile_html_parser_test.rb
index 8d6f78689..a338ed528 100644
--- a/test/unit/lib/redmine/wiki_formatting/textile_html_parser_test.rb
+++ b/test/unit/lib/redmine/wiki_formatting/textile_html_parser_test.rb
@@ -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