Defect #31695 » fixed-31695.patch
| lib/redmine/wiki_formatting/html_parser.rb | ||
|---|---|---|
|
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
|
||
| ... | ... | |
|
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
|
||
| lib/redmine/wiki_formatting/markdown/html_parser.rb | ||
|---|---|---|
|
'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? ? %Q| [#{node.content}](#{node.attributes['href'].value}) | : %Q| #{node.attributes['href'].value} |}
|
||
|
)
|
||
|
end
|
||
|
end
|
||
| lib/redmine/wiki_formatting/textile/html_parser.rb | ||
|---|---|---|
|
'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? ? %Q| "#{node.content}":#{node.attributes['href'].value} | : %Q| #{node.attributes['href'].value} |}
|
||
|
)
|
||
|
end
|
||
|
end
|
||
| test/unit/lib/redmine/wiki_formatting/markdown_html_parser_test.rb | ||
|---|---|---|
|
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
|
||
| test/unit/lib/redmine/wiki_formatting/textile_html_parser_test.rb | ||
|---|---|---|
|
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
|
||