strip_tagsモディファイアとremove_htmlモディファイアの違い
Twitterでriatwさんの次のつぶやきをみつけたので本エントリーにて紹介します。
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\[)/</gis;
    }
    return $text;
}これだけでは何なので、それぞれのモディファイアがどのバージョンで実装されたかを調べました。
- remove_html:Movable Type 1.4 あたりで追加
- strip_tags:Movable Type 4.0 で追加
ということで、remove_htmlが大先輩でした。
Posted by yujiro   このページの先頭に戻る
- MTのEntryBodyタグのwordsモディファイアについて
- MTテンプレートタグのlastnモディファイアとlimitモディファイアの違い
トラックバックURL
コメントする
greeting

 



