我是一个相对铁杆的新手,并对消毒宝石有疑问。它易于安装和使用,但出于某种原因,当我选择拥有自己的元素数组时,它无法正常工作。它仍在消毒我试图批准的元素。这是我的代码:
def scrub(html)
# Setup whitelist of html elements that are allowed.
allowed_elements = ['b', 'blockquote', 'em', 'i', 'li', 'ol', 'p', 'pre', 'u', 'ul']
Sanitize.clean(html, :elements => allowed_elements)
end
但结果显示如下:
<p> And Some Content... <script>mal</script>
and <em>italics and bold</em></p>
<ol> <li> list</li> <li> list</li> </ol>
<blockquote> <p> blockquote</p> </blockquote>
<ul> <li> bullet</li> <li> bullet</li> </ul>
感谢关于为什么这种简单格式不起作用的任何指示!
答案 0 :(得分:4)
def scrub(html)
# Setup whitelist of html elements that are allowed.
allowed_elements = ['b', 'blockquote', 'em', 'i', 'li', 'ol', 'p', 'pre', 'u', 'ul']
Sanitize.clean(html, :elements => allowed_elements).html_safe
end