ALLOWED_TAGS = %w(redpre pre code)
def escape_html_tags(text)
- text.gsub!(%r{<(\/?(\w+)[^>\n]*)(>?)}) {|m| ALLOWED_TAGS.include?($2) ? "<#{$1}#{$3}" : "<#{$1}#{'>' if $3}" }
+ text.gsub!(%r{<(\/?([!\w]+)[^<>\n]*)(>?)}) {|m| ALLOWED_TAGS.include?($2) ? "<#{$1}#{$3}" : "<#{$1}#{'>' unless $3.blank?}" }
end
end
"<pre>\nline 1\nline2</pre>" => "<pre>\nline 1\nline2</pre>",
"<pre><code>\nline 1\nline2</code></pre>" => "<pre><code>\nline 1\nline2</code></pre>",
"<pre><div>content</div></pre>" => "<pre><div>content</div></pre>",
+ "HTML comment: <!-- no comments -->" => "<p>HTML comment: <!-- no comments --></p>",
+ "<!-- opening comment" => "<p><!-- opening comment</p>"
}
to_test.each { |text, result| assert_equal result, textilizable(text) }
end