diff --git a/lib/redmine/wiki_formatting/markdown/html_parser.rb b/lib/redmine/wiki_formatting/markdown/html_parser.rb index ff25a0bd2..636a3443e 100644 --- a/lib/redmine/wiki_formatting/markdown/html_parser.rb +++ b/lib/redmine/wiki_formatting/markdown/html_parser.rb @@ -37,7 +37,15 @@ module Redmine 'h6' => {:pre => "\n\n###### ", :post => "\n\n"}, 'th' => {:pre => '*', :post => "*\n"}, 'td' => {:pre => '', :post => "\n"}, - 'a' => lambda {|node| node.content.present? ? %| [#{node.content}](#{node.attributes['href'].value}) | : %| #{node.attributes['href'].value} |} + 'a' => lambda do |node| + if node.content.present? && node.attributes.key?('href') + %| [#{node.content}](#{node.attributes['href'].value}) | + elsif node.attributes.key?('href') + %| #{node.attributes['href'].value} | + else + node.content + end + end ) end end diff --git a/lib/redmine/wiki_formatting/textile/html_parser.rb b/lib/redmine/wiki_formatting/textile/html_parser.rb index 8623c2068..27dc5f975 100644 --- a/lib/redmine/wiki_formatting/textile/html_parser.rb +++ b/lib/redmine/wiki_formatting/textile/html_parser.rb @@ -37,7 +37,15 @@ module Redmine 'h6' => {:pre => "\n\nh6. ", :post => "\n\n"}, 'th' => {:pre => '*', :post => "*\n"}, 'td' => {:pre => '', :post => "\n"}, - 'a' => lambda {|node| node.content.present? ? %| "#{node.content}":#{node.attributes['href'].value} | : %| #{node.attributes['href'].value} |} + 'a' => lambda do |node| + if node.content.present? && node.attributes.key?('href') + %| "#{node.content}":#{node.attributes['href'].value} | + elsif node.attributes.key?('href') + %| #{node.attributes['href'].value} | + else + node.content + end + end ) 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 45a5a52f9..55ca3f9c1 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 @@ -31,8 +31,15 @@ class Redmine::WikiFormatting::MarkdownHtmlParserTest < ActiveSupport::TestCase assert_equal 'foo [bar](http://example.com/) baz', @parser.to_text('foobarbaz') + assert_equal 'foo http://example.com/ baz', @parser.to_text('foobaz') + + assert_equal 'foobarbaz', + @parser.to_text('foobarbaz') + + assert_equal 'foobaz', + @parser.to_text('foobaz') end def test_html_tables_conversion 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 86d7e66d2..17221989d 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 @@ -31,8 +31,15 @@ class Redmine::WikiFormatting::TextileHtmlParserTest < ActiveSupport::TestCase assert_equal 'foo "bar":http://example.com/ baz', @parser.to_text('foobarbaz') + assert_equal 'foo http://example.com/ baz', @parser.to_text('foobaz') + + assert_equal 'foobarbaz', + @parser.to_text('foobarbaz') + + assert_equal 'foobaz', + @parser.to_text('foobaz') end def test_html_tables_conversion