エディタのデータをP要素で挟む(TextFilterTest01)

構成

$MT_DIR/
|__ plugins/
|  |__ TextFilterTest01/
|     |__ config.yaml
|     |__ lib/                    
|     |  |__ TextFilterTest01
|     |      |__ L10N
|     |      |   |__ ja.pm
|     |      |   |__ en_us.pm
|     |      |__ Filter.pm
 
 
 

ソース

config.yaml

# プラグイン情報
id: TextFilterTest01
key: TextFilterTest01
name: TextFilterTest01
version: 1.0
description: <__trans phrase="_PLUGIN_DESCRIPTION">
author_name: <__trans phrase="_PLUGIN_AUTHOR">
author_link: http://www.example.com/about/
doc_link: http://www.example.com/docs/
 
# 言語対応
l10n_class: TextFilterTest01::L10N
 
# テキストフィルタ
text_filters:
    Add_Paragraph:
        # ラベル
        label: _Add_Paragraph_
        # 順番
        order: 100
        # コード
        handler: $TextFilterTest01::TextFilterTest01::Filter::_hdlr_text_filter01
 
 

lib/TextFilterTest01/L10N.pm

package TextFilterTest01::L10N;
use strict;
use base 'MT::Plugin::L10N';
 
1;
 
 

lib/TextFilterTest01/L10N/ja.pm

package TextFilterTest01::L10N::ja;
 
use strict;
use base 'TextFilterTest01::L10N::en_us';
use vars qw( %Lexicon );
 
%Lexicon = (
    '_PLUGIN_NAME_' => 'TextFilterTest01',
    '_PLUGIN_DESCRIPTION' => 'TextFilterTest01 Test',
    '_PLUGIN_AUTHOR' => 'TextFilterTest01 author',
 
    '_Add_Paragraph_' => 'パラグラフ要素で囲む',
);
 
1;
 
 

lib/TextFilterTest01/L10N/en_us.pm

package TextFilterTest01::L10N::en_us;
 
use strict;
use base 'TextFilterTest01::L10N';
use vars qw( %Lexicon );
 
%Lexicon = (
    '_PLUGIN_NAME_' => 'TextFilterTest01',
    '_PLUGIN_DESCRIPTION' => 'TextFilterTest01 Test',
    '_PLUGIN_AUTHOR' => 'TextFilterTest01 author',
 
    '_Add_Paragraph_' => 'Add Paragraph',
);
 
1;
 
 

lib/TextFilterTest01/Filter.pm

package TextFilterTest01::Filter;
 
use strict;
 
# パラグラフで囲む
sub _hdlr_text_filter01{
 
    # 引数
    my ($text, $ctx) = @_;
 
    # 置き換え
    $text =~ s/(.*)/<p>$1<\/p>/;
 
    # 返却
    return $text;
}
 
1;
 
 

結果

ウェブページ編集画面

ウェブページ編集画面でパラグラフ要素を選択












最終更新:2012年03月10日 09:41