はじめに
AntiSamy(v1.4.5)使用時にYoutubeの埋め込みタグに対応してみました。
iOS向けにも表示するので、旧埋め込みタグは無視しています。
旧タグも許可したい場合は、AntiSamy Policy to allow YouTubeVideosを参照してください。
Policyファイルを編集する
最初に、YoutubeのURLを許可するregexpを定義します。
policy.xml
<regexp name = "YouTubeURL"
value = "\s*(?:http\:|https\:)?//www.youtube(?:-nocookie)?.com/embed/([a-zA-Z0-9-]+).*" />
次に、iframeタグの部分を編集します。
policy.xml
<tag name = "iframe" action = "validate">
<attribute name = "height"/>
<attribute name = "width" />
<attribute name = "frameborder">
<regexp-list>
<regexp value = "[0]" />
</regexp-list>
</attribute>
<attribute name = "src">
<regexp-list>
<regexp name = "YouTubeURL" />
</regexp-list>
</attribute>
<attribute name = "allowfullscreen">
<regexp-list>
<regexp value = "?" />
</regexp-list>
</attribute>
</tag>
これで貼り付けられるようになります。
追記
attributenameで設定している、"height", "width"などは事前に定義されているxmlを参照して下さい。