#webliberty::Decoration.pm (2007/03/26) #Copyright(C) 2002-2007 Knight, All rights reserved. package webliberty::Decoration; use strict; ### コンストラクタ sub new { my $class = shift; my $self = { string => shift, article => undef, paragraph => undef, color => undef, heading => 'h1,h2,h3' }; bless $self, $class; return $self; } ### 装飾設定 sub init_decoration { my $self = shift; my %args = @_; if ($args{'article'}) { $self->{article} = $args{'article'}; } if ($args{'paragraph'}) { $self->{paragraph} = $args{'paragraph'}; } if ($args{'color'}) { $self->{color} = " style=\"color:$args{'color'}\""; } if ($args{'heading'}) { $self->{heading} = $args{'heading'}; } return; } ### 装飾実行 sub create_decoration { my $self = shift; my @heading = split(/,/, $self->{heading}); my($text, $flag); foreach (split("\n", $self->{string})) { if ($flag) { if ($_ eq '|<') { $text .= ""; $flag = 0; } elsif ($_ eq '||<') { if ($flag == 3) { $text .= "

"; $flag = 0; } else { $text .= ""; $flag = 0; } } else { if ($flag == 2 or $flag == 3) { $_ =~ s/&/&/g; $_ =~ s//>/g; $_ =~ s/"/"/g; $_ =~ s/\(\(/<\a>/g; $_ =~ s/\)\)/<\/\a>/g; } if ($flag == 3) { $text .= "$_
\t"; } else { $text .= "$_\t"; } } } else { if ($_ eq '>|') { $text .= "
";
				$flag = 1;
			} elsif ($_ eq '>||') {
				$text .= "
";
				$flag = 2;
			} elsif ($_ eq '>|aa|') {
				$text .= "

"; $flag = 3; } elsif ($_ eq '>>') { $text .= "
"; } elsif ($_ eq '<<') { $text .= "
"; } elsif ($_ =~ s/^\|(.+)\|$//) { my $row; foreach my $cel (split(/\|/, $1)) { if ($cel =~ s/^\*(.+)//) { $row .= "{color}>$1"; } else { $row .= "{color}>$cel"; } } $text .= "$row"; } elsif ($_ =~ s/^\:([^\:]+)\:(.+)$//) { $text .= "{color}>$1{color}>$2"; } elsif ($_ =~ s/^\*\*\*(.+)//) { $text .= "<$heading[2]$self->{color}>$1"; } elsif ($_ =~ s/^\*\*(.+)//) { $text .= "<$heading[1]$self->{color}>$1"; } elsif ($_ =~ s/^\*(.+)//) { $text .= "<$heading[0]$self->{color}>$1"; } elsif ($_ =~ s/^\-(.+)//) { $text .= "{color}>$1"; } else { $text .= "$_
"; } } } my $dammy = $text; my $note = 1; my @note; while ($dammy =~ s/(.*)\(\((.+)\)\)(.*)//) { my $dammy1 = $1; my $dammy2 = $2; my $dammy3 = $3; if ($dammy1 !~ s/\)$// or $dammy3 !~ s/^\(//) { $note++; } $dammy = "$dammy1$dammy3"; } while ($text =~ s/(.*)\(\((.+)\)\)(.*)//) { my $text1 = $1; my $text2 = $2; my $text3 = $3; if ($text1 =~ s/\)$// and $text3 =~ s/^\(//) { $text = "$text1(\a($text2)\a)$text3"; } else { $note--; unshift(@note, "{article}text$note\" id=\"$self->{article}note$note\">*$note:$text2"); $text2 =~ s/<[^>]*>//g; $text = "$text1{article}note$note\" id=\"$self->{article}text$note\" title=\"$text2\">*$note$text3"; } } $text =~ s/<\a>/((/g; $text =~ s/<\/\a>/))/g; $text =~ s/\a//g; $text =~ s/\t/\n/g; $text = "{color}>
$text

"; $text =~ s/
/<\/p>
/g;
	$text =~ s/\n<\/pre>/<\/pre>{color}>/g;
	$text =~ s/\n<\/code><\/pre>/<\/code><\/pre>{color}>/g;

	$text =~ s/
/<\/p>
{color}>/g; $text =~ s/<\/blockquote>/<\/p><\/blockquote>{color}>/g; $text =~ s/
/<\/p>/g; $text =~ s/{color}>/
/g; $text =~ s/<\/tr>
/<\/tr><\/table>{color}>/g; $text =~ s/<\/tr><\/p>/<\/tr><\/table>/g; $text =~ s/
{color}>/<\/p>
{color}>/g; $text =~ s/{color}>{color}>/
{color}>/g; $text =~ s/<\/dd>
/<\/dd><\/dl>{color}>/g; $text =~ s/<\/dd><\/p>/<\/dd><\/dl>/g; $text =~ s/<$heading[2]$self->{color}>/<\/p><$heading[2]$self->{color}>/g; $text =~ s/<\/$heading[2]>/<\/$heading[2]>{color}>/g; $text =~ s/<$heading[1]$self->{color}>/<\/p><$heading[1]$self->{color}>/g; $text =~ s/<\/$heading[1]>/<\/$heading[1]>{color}>/g; $text =~ s/<$heading[0]$self->{color}>/<\/p><$heading[0]$self->{color}>/g; $text =~ s/<\/$heading[0]>/<\/$heading[0]>{color}>/g; $text =~ s/
{color}>/<\/p>
    {color}>/g; $text =~ s/{color}>{color}>/
      {color}>/g; $text =~ s/<\/li>
      /<\/li><\/ul>{color}>/g; $text =~ s/<\/li><\/p>/<\/li><\/ul>/g; if ($self->{paragraph}) { $text =~ s/

      /<\/p>{color}>/g; } $text =~ s/{color}>
      /{color}>/g; $text =~ s/
      <\/p>/<\/p>/g; $text =~ s/{color}><\/p>//g; if ($note[0]) { $text .= "{color}>" . join('
      ', @note) . '

      '; } $self->{string} = $text; return $self->{string}; } ### データ取得 sub get_string { my $self = shift; return $self->{string}; } 1;