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