Sanitize gemを使用して、いくつかのHTMLをクリーンアップしています。アンカータグのhref属性で、以下を解析したいと思います。
<a href="#fn:1">1</a>
これは、Kramdowngemを使用して脚注を実装するために必要です。
ただし、Sanitizeはhref属性内のコロンを好まないようです。<a>1</a>
代わりに、href属性を完全にスキップして出力するだけです。
私のサニタイズコードは次のようになります。
# Setup whitelist of html elements, attributes, and protocols that are allowed.
allowed_elements = ['h2', 'a', 'img', 'p', 'ul', 'ol', 'li', 'strong', 'em', 'cite',
'blockquote', 'code', 'pre', 'dl', 'dt', 'dd', 'br', 'hr', 'sup', 'div']
allowed_attributes = {'a' => ['href', 'rel', 'rev'], 'img' => ['src', 'alt'],
'sup' => ['id'], 'div' => ['class'], 'li' => ['id']}
allowed_protocols = {'a' => {'href' => ['http', 'https', 'mailto', :relative]}}
# Clean text of any unwanted html tags.
html = Sanitize.clean(html, :elements => allowed_elements, :attributes => allowed_attributes,
:protocols => allowed_protocols)
Sanitizeにhref属性のコロンを受け入れるようにする方法はありますか?