Top > Movable Type > モディファイア [全て開く]
2010年5月11日

strip_tagsモディファイアとremove_htmlモディファイアの違い

May 11,2010 11:55 PM
Tag:[, , ]
Permalink

Twitterでriatwさんの次のつぶやきをみつけたので本エントリーにて紹介します。

strip_tagsモディファイアとremove_htmlモディファイアの違い

Movable Typeのstrip_tagsモディファイアとremove_htmlモディファイアは、どちらもテンプレートタグの出力結果からHTMLタグを取り除く機能があります。次のように記述すれば、ブログ記事本文のHTMLタグを取り除きます。

<mt:EntryBody remove_html="1" />

または

<mt:EntryBody strip_tags="1" />

そして、それぞれのモディファイアの機能は全く同じです。どちらもMT::Util::remove_htmlを起動しています。「strip_tagsはremove_htmlのエイリアスです」とコメントにも記載されています。

remove_htmlモディファイアのソースコード

###########################################################################
 
=head2 remove_html
 
Removes any HTML markup from the input.
 
=cut
 
sub _fltr_remove_html {
    my ($str, $val, $ctx) = @_;
    MT::Util::remove_html($str);
}

strip_tagsモディファイアのソースコード

###########################################################################
 
=head2 strip_tags
 
An alias for L<remove_html>. Removes all HTML markup from the input.
 
=cut
 
sub _fltr_strip_tags {
    my ($str, $val, $ctx) = @_;
    return MT::Util::remove_html($str);
}

MT::Util::remove_htmlは、次の実装になっています。

sub remove_html {
    my($text) = @_;
    return '' if !defined $text;  # suppress warnings
    {
        use bytes;
        $text =~ s/(<\!\[CDATA\[(.*?)\]\]>)|(<[^>]+>)/
            defined $1 ? $1 : ''
            /geisx;
        $text =~ s/<(?!\!\[CDATA\[)/&lt;/gis;
    }
    return $text;
}

これだけでは何なので、それぞれのモディファイアがどのバージョンで実装されたかを調べました。

  • remove_html:Movable Type 1.4 あたりで追加
  • strip_tags:Movable Type 4.0 で追加

ということで、remove_htmlが大先輩でした。

Comments [0] | Trackbacks [0]
Now loading...
Introduction
List of "モディファイア"
Recent Entries
Recent Comments
Recent Trackbacks
QRcode

現在停止中です
携帯電話からこのQRcodeを撮影することで携帯用URLを取得することができます

URI for cellular phones
ギターに入った猫
Styles
Font Size
Default
For defective color vision
Gray Scale
RGB Color
Search this site

このブログをメールで購読する by:FeedBurner

loading ...
Categories
Monthly Archives
BlogPeople
Syndicate this site
FeedBurner(RSS1.0/RSS2.0/Atom)
Counter
これまでのアクセス
クリエイティブ・コモンズ・ライセンス
Powered by
Movable Type 5.04