|
|
1 | # |
|
|
2 | # This file is part of Deliantra, the Roguelike Realtime MMORPG. |
|
|
3 | # |
|
|
4 | # Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | # |
|
|
6 | # Deliantra is free software: you can redistribute it and/or modify it under |
|
|
7 | # the terms of the Affero GNU General Public License as published by the |
|
|
8 | # Free Software Foundation, either version 3 of the License, or (at your |
|
|
9 | # option) any later version. |
|
|
10 | # |
|
|
11 | # This program is distributed in the hope that it will be useful, |
|
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
14 | # GNU General Public License for more details. |
|
|
15 | # |
|
|
16 | # You should have received a copy of the Affero GNU General Public License |
|
|
17 | # and the GNU General Public License along with this program. If not, see |
|
|
18 | # <http://www.gnu.org/licenses/>. |
|
|
19 | # |
|
|
20 | # The authors can be reached via e-mail to <support@deliantra.net> |
|
|
21 | # |
|
|
22 | |
1 | package cf::pod; |
23 | package cf::pod; |
|
|
24 | |
|
|
25 | use common::sense; |
2 | |
26 | |
3 | use Pod::POM; |
27 | use Pod::POM; |
4 | |
28 | |
5 | our $indent; |
29 | our $indent; |
6 | our $level; |
30 | our $level; |
7 | our @result; |
31 | our @result; |
8 | |
32 | |
9 | package cf::pod::AsParagraphs; |
33 | package cf::pod::AsParagraphs; |
10 | |
34 | |
11 | use strict; |
35 | use common::sense; |
12 | |
36 | |
13 | use base "Pod::POM::View"; |
37 | use base "Pod::POM::View"; |
14 | |
38 | |
|
|
39 | my %E = ( |
|
|
40 | "<" => "E<lt>", |
|
|
41 | ">" => "E<gt>", |
|
|
42 | ); |
|
|
43 | |
15 | sub asxml($) { |
44 | sub aspod($) { |
16 | local $_ = $_[0]; |
45 | local $_ = $_[0]; |
17 | |
46 | |
18 | s/&/&/g; |
47 | s/[<>]/$E{$1}/g; |
19 | s/>/>/g; |
|
|
20 | s/</</g; |
|
|
21 | |
48 | |
22 | $_ |
49 | $_ |
23 | } |
50 | } |
24 | |
51 | |
25 | sub flatten($) { |
52 | sub flatten($) { |
26 | local $_ = $_[0]; |
53 | local $_ = $_[0]; |
27 | |
54 | |
28 | s/<[^>]+>//g; |
|
|
29 | s/^\s+//; |
55 | s/^\s+//; |
30 | s/\s+$//; |
56 | s/\s+$//; |
31 | s/\s+/ /g; |
57 | s/\s+/ /g; |
32 | |
58 | |
33 | $_ |
59 | $_ |
34 | } |
60 | } |
35 | |
61 | |
36 | *view_seq_file = |
62 | *view_seq_file = sub { "C<$_[1]>" }; |
37 | *view_seq_code = |
63 | *view_seq_code = sub { "C<$_[1]>" }; |
38 | *view_seq_bold = sub { "<b>$_[1]</b>" }; |
64 | *view_seq_bold = sub { "B<$_[1]>" }; |
39 | *view_seq_italic = sub { "<i>$_[1]</i>" }; |
65 | *view_seq_italic = sub { "I<$_[1]>" }; |
|
|
66 | *view_seq_T = sub { "T<$_[1]>" }; |
|
|
67 | *view_seq_G = sub { "G<$_[1]>" }; |
40 | *view_seq_zero = sub { }; |
68 | *view_seq_zero = sub { "Z<>" }; |
41 | *view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text }; |
69 | *view_seq_space = sub { my $text = $_[1]; $text =~ s/ /\xa0/g; $text }; |
42 | *view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; |
70 | *view_seq_index = sub { push @{ $result[-1]{index} }, $_[1]; "" }; |
43 | |
71 | |
44 | sub view_seq_text { |
72 | sub view_seq_text { |
45 | my $text = $_[1]; |
73 | my $text = $_[1]; |
46 | $text =~ s/\s+/ /g; |
74 | $text =~ s/\s+/ /g; |
47 | asxml $text |
75 | aspod $text |
48 | } |
76 | } |
49 | |
77 | |
50 | sub view_seq_link { |
78 | sub view_seq_link { |
51 | my (undef, $link) = @_; |
79 | my (undef, $link) = @_; |
52 | |
80 | |
53 | my $text = $link =~ s/^(.*)\|// ? $1 : $link; |
81 | my $text = $link =~ s/^(.*)\|// ? $1 : $link; |
54 | |
82 | |
55 | if ($link =~ /http:/) { |
83 | if ($link =~ /http:/) { |
56 | "<u>" . (asxml $link) . "</u>" |
84 | "U<" . (aspod $link) . ">" |
57 | } else { |
85 | } else { |
58 | () |
86 | () |
59 | } |
87 | } |
60 | } |
88 | } |
61 | |
89 | |
… | |
… | |
76 | sub view_verbatim { |
104 | sub view_verbatim { |
77 | push @result, { |
105 | push @result, { |
78 | type => "verbatim", |
106 | type => "verbatim", |
79 | indent => $indent * 16, |
107 | indent => $indent * 16, |
80 | level => $level, |
108 | level => $level, |
81 | markup => asxml $_[1], |
109 | markup => $_[1], |
82 | }; |
110 | }; |
83 | () |
111 | () |
84 | } |
112 | } |
85 | |
113 | |
86 | sub view_textblock { |
114 | sub view_textblock { |
… | |
… | |
183 | |
211 | |
184 | sub load_pod($) { |
212 | sub load_pod($) { |
185 | my ($path) = @_; |
213 | my ($path) = @_; |
186 | |
214 | |
187 | Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path], |
215 | Coro::Storable::thaw cf::cache "cf::pod::as_paragraphs/$path" => [$path], |
188 | 1 => sub { |
216 | 7 => sub { |
189 | my ($src) = @_; |
217 | my ($src) = @_; |
|
|
218 | |
190 | cf::fork_call { |
219 | cf::fork_call { |
191 | my $pod = $src->[0]; |
220 | my $pod = $src->[0]; |
192 | utf8::decode $pod; |
221 | utf8::decode $pod; |
193 | Coro::Storable::freeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod)) |
222 | Coro::Storable::blocking_nfreeze pom_as_paragraphs +(Pod::POM->new->parse_text ($pod)) |
194 | } |
223 | } |
195 | }; |
224 | }; |
196 | } |
225 | } |
197 | |
226 | |
198 | sub as_text($) { |
227 | # format as cfpod-style text |
|
|
228 | sub as_cfpod($) { |
199 | my ($pars) = @_; |
229 | my ($pars) = @_; |
200 | |
230 | |
201 | my $res; |
231 | my $res; |
202 | |
232 | |
203 | for my $par (@$pars) { |
233 | for my $par (@$pars) { |
204 | if ($par->{type} =~ /^head\d+$/) { |
234 | if ($par->{type} =~ /^head\d+$/) { |
|
|
235 | $res .= "B<$par->{markup}>\n\n"; |
|
|
236 | } elsif ($par->{type} eq "verbatim") { |
205 | $res .= "$par->{markup}\n\n"; |
237 | $res .= "$par->{markup}\n\n"; |
206 | } elsif ($par->{type} eq "verbatim") { |
|
|
207 | $res .= "\n$par->{markup}\n\n"; |
|
|
208 | } elsif ($par->{type} eq "item") { |
238 | } elsif ($par->{type} eq "item") { |
209 | $res .= "\n* $par->{markup}\n\n"; |
239 | $res .= "* I<$par->{markup}>\n\n"; |
210 | } else { |
240 | } else { |
211 | $res .= "$par->{markup}\n"; |
241 | $res .= "$par->{markup}\n\n"; |
212 | } |
242 | } |
213 | } |
243 | } |
214 | |
244 | |
215 | $res =~ s/\n\n+/\n/g; |
|
|
216 | |
|
|
217 | $res |
245 | $res |
218 | } |
246 | } |
219 | |
247 | |
220 | 1; |
248 | 1; |
221 | |
249 | |