オリジナルは開始行番号に+/-を許容しないが、これを+1/-1とした場合に、前回の最終行番号+1/-1からの開始とする仕様にしてみる。 同様に+/-nの場合最終業番号+/-nからの開始としておく。 現在パッチ作成中。今の所作業中。 {{code Perl,8, 1 ############################################################ # #

ソースコードを整形出力するプラグインです。

#
# {{code コード種別,タブ桁数,開始行番号,WIDTHxHEIGHT]
# ソースコード
# }}
# 
#

# 開始行番号をブランク、もしくは "0" にすれば行番号は表示されません。 #

# ############################################################ package plugin::code::Code; use strict; #=========================================================== # コンストラクタ #=========================================================== sub new { my $class = shift; my $self = {}; return bless $self,$class; } }} グローバル変数宣言と、mod_perl時のためにinitializeフックでの初期化が必要。 {{code Perl,8,0 use vars qw($maxline $place); #=========================================================== # フックメソッド(initialize用) #=========================================================== sub hook { $maxline = 1; $place = 1; } }} {{code Perl,8,+2 #=========================================================== # ブロックプラグイン #=========================================================== sub block { my $self = shift; my $wiki = shift; my $source = shift; my $type = shift; my $tab = shift; my $line = shift; my $size = shift; my ($width,$height) = ("",""); if ( $size ne "" && $size ne " " && $size =~ /^([0-9]+%?)?x?([0-9]+%?)?$/ ) { $width = "width:$1;" if ( $1 ne "" ); $height = "height:$2;" if ( $2 ne "" ); } my $html = ""; my $formatter = "plugin::code::Format::".$type; $type =~ /\W/ and $@ = "対応していないコード種別です。\"".&Util::escapeHTML($type)."\"" or eval ("use ".$formatter); # エラーが発生した場合クリーンアップ処理 if ( $@ ) { my $error = $@; $html = "

".&Util::escapeHTML($formatter) ."の作成に失敗しました。発生したエラーは以下のとおりです。

$error
"; } else { my $cf = $formatter->new($self); $html .= "\n
\n\n"; $source = $cf->format($wiki, $source); # タブの桁数 my $tabspace = ""; for (my $i=0; $i<$tab; $i++) { $tabspace .= " "; }; }} 以下から行番号関係の処理。 {{code Perl,8,+ # 行番号表示 if ($line eq 'false') {$line='0';} elsif ($line eq 'true' || $line =~ /^ *$/ ) {$line='1';} }} {{code Perl,8,+ if ($line !~ /[^ 0-9]/ && $line !~ /^ *0$/){ }} * +-を許容するように変更 {{code Perl,8,- if ($line !~ /[^-+ 0-9]/ && $line !~ /^ *0$/){ }} * +/-があれば保存してある最終行を元に開始行を計算 {{code Perl,8,0 if ($line =~ /[+-]/){ if ($line < 0 or $line =~ /\+/ and $line == 0){ $line++; } $line = $pre_maxline+$line; $line = " "x($place - length $line) . $line; } }} * 表示幅を$placeに保存しておく {{code Perl,8,0 $place = length $line; }} {{code Perl,8,+ my $maxline = split(/\n/,$source) + $line-1; }} * $maxlineはグローバル変数化してある {{code Perl,8,- $maxline = split(/\n/,$source) + $line-1; }} {{code Perl,8,+ $html .= "\n"; } }} 以上、行番号処理 {{code Perl,8,+ # ソース表示 $source =~ s/\t/$tabspace/g; $html .= "\n"; $html .= "
";
			for(my $i=$line;$i<=$maxline;$i++){
				$html .= "$i
"; } $html .= "
$source
\n
\n"; } return $html; } 1; }}