Defect #31232 » fix-31232-v3.patch
| lib/redmine/wiki_formatting/html_parser.rb | ||
|---|---|---|
|
}
|
||
|
def self.to_text(html)
|
||
|
html = html.gsub(/[\n\r]/, '').squeeze(' ')
|
||
|
html = html.gsub(/[\n\r]/, ' ')
|
||
|
|
||
|
doc = Loofah.document(html)
|
||
|
doc.scrub!(WikiTags.new(tags))
|
||
|
doc.scrub!(:newline_block_elements)
|
||
|
|
||
|
Loofah.remove_extraneous_whitespace(doc.text).strip
|
||
|
Loofah.remove_extraneous_whitespace(doc.text).strip.squeeze(' ').gsub(/^ +/, '')
|
||
|
end
|
||
|
class WikiTags < ::Loofah::Scrubber
|
||
| test/unit/lib/redmine/wiki_formatting/html_parser_test.rb | ||
|---|---|---|
|
assert_equal "Text",
|
||
|
@parser.to_text('<html><body><style>body {font-size: 0.8em;}</style>Text</body></html>')
|
||
|
end
|
||
|
def test_should_remove_preceding_whitespaces
|
||
|
to_test = {
|
||
|
"<div> blocks with</div>\n<p>\n preceding whitespaces\n</p>" => "blocks with\n\npreceding whitespaces",
|
||
|
"<div>blocks without</div>\n<p>\npreceding whitespaces\n</p>" => "blocks without\n\npreceding whitespaces",
|
||
|
"<span> span with</span>\n<span> preceding whitespaces</span>" => "span with preceding whitespaces",
|
||
|
"<span>span without</span>\n<span>preceding whitespaces</span>" => "span without preceding whitespaces"
|
||
|
}
|
||
|
to_test.each do |html, expected|
|
||
|
assert_equal expected, @parser.to_text(html)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »