'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
'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
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')
+
+ assert_equal 'foobarbaz',
+ @parser.to_text('foo<a name="Header-one">bar</a>baz')
+
+ assert_equal 'foobaz',
+ @parser.to_text('foo<a name="Header-one"/>baz')
end
def test_html_tables_conversion
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')
+
+ assert_equal 'foobarbaz',
+ @parser.to_text('foo<a name="Header-one">bar</a>baz')
+
+ assert_equal 'foobaz',
+ @parser.to_text('foo<a name="Header-one"/>baz')
end
def test_html_tables_conversion