--- deliantra/server/lib/cf/pod.pm 2007/04/18 17:32:07 1.5 +++ deliantra/server/lib/cf/pod.pm 2008/09/07 23:02:40 1.15 @@ -12,12 +12,15 @@ use base "Pod::POM::View"; -sub asxml($) { +my %E = ( + "<" => "E", + ">" => "E", +); + +sub aspod($) { local $_ = $_[0]; - s/&/&/g; - s/>/>/g; - s/]/$E{$1}/g; $_ } @@ -25,7 +28,6 @@ sub flatten($) { local $_ = $_[0]; - s/<[^>]+>//g; s/^\s+//; s/\s+$//; s/\s+/ /g; @@ -33,18 +35,18 @@ $_ } -*view_seq_file = -*view_seq_code = -*view_seq_bold = sub { "$_[1]" }; -*view_seq_italic = sub { "$_[1]" }; -*view_seq_zero = sub { }; +*view_seq_file = sub { "B<$_[1]>" }; +*view_seq_code = sub { "B<$_[1]>" }; +*view_seq_bold = sub { "B<$_[1]>" }; +*view_seq_italic = sub { "I<$_[1]>" }; +*view_seq_zero = sub { "Z<>" }; *view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text }; *view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; sub view_seq_text { my $text = $_[1]; $text =~ s/\s+/ /g; - asxml $text + aspod $text } sub view_seq_link { @@ -53,7 +55,7 @@ my $text = $link =~ s/^(.*)\|// ? $1 : $link; if ($link =~ /http:/) { - "" . (asxml $link) . "" + "U<" . (aspod $link) . ">" } else { () } @@ -78,7 +80,7 @@ type => "verbatim", indent => $indent * 16, level => $level, - markup => asxml $_[1], + markup => $_[1], }; () } @@ -87,7 +89,7 @@ push @result, { indent => $indent * 16, level => $level, - markup => "$_[1]\n", + markup => flatten $_[1], }; () } @@ -185,15 +187,37 @@ my ($path) = @_; Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path], - 1 => sub { + 5 => sub { my ($src) = @_; + cf::fork_call { my $pod = $src->[0]; utf8::decode $pod; - Coro::Storable::freeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod)) + Coro::Storable::blocking_nfreeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod)) } }; } +# format as cfpod-style text +sub as_cfpod($) { + my ($pars) = @_; + + my $res; + + for my $par (@$pars) { + if ($par->{type} =~ /^head\d+$/) { + $res .= "B<$par->{markup}>\n\n"; + } elsif ($par->{type} eq "verbatim") { + $res .= "\n$par->{markup}\n\n"; + } elsif ($par->{type} eq "item") { + $res .= "\n* I<$par->{markup}>\n\n"; + } else { + $res .= "$par->{markup}\n\n"; + } + } + + $res +} + 1;