mirror of
https://github.com/meineerde/redmine.git
synced 2026-01-03 06:09:41 +00:00
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
This commit is contained in:
parent
3c91a3d5b2
commit
f5c7a4a420
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user