LoginSignup
1

More than 5 years have passed since last update.

AntisamyでYoutubeの埋め込みに対応する

Last updated at Posted at 2013-07-03

はじめに

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を参照して下さい。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1