From f5c7a4a4208c9c146544b4498de3a08761cbc55a Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sun, 11 Aug 2019 05:01:37 +0000 Subject: 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 --- lib/redmine/wiki_formatting/html_parser.rb | 5 ++++- lib/redmine/wiki_formatting/markdown/html_parser.rb | 3 ++- lib/redmine/wiki_formatting/textile/html_parser.rb | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'lib/redmine/wiki_formatting') 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 -- cgit v1.2.3