ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pod2wiki
Revision: 1.13
Committed: Sun Mar 30 04:59:43 2008 UTC (16 years, 1 month ago) by root
Branch: MAIN
Changes since 1.12: +2 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl
2
3 # convert given .pod files to wiki style
4
5 # base path of arch tree, only used for new arch graphics
6 my $ARCH = "/root/devel/cvs/cf.schmorp.de/arch";
7
8 use strict;
9
10 use Storable;
11 use Pod::POM;
12
13 our @result;
14 our $indent;
15 our $level;
16
17 my $MA_BEG = "\x{fcd0}";
18 my $MA_SEP = "\x{fcd1}";
19 my $MA_END = "\x{fcd2}";
20
21 sub asxml($) {
22 local $_ = $_[0];
23
24 s/&/&/g;
25 s/>/>/g;
26 s/</&lt;/g;
27
28 $_
29 }
30
31 sub flatten($) {
32 local $_ = $_[0];
33
34 s/<[^>]+>//g;
35 s/^\s+//;
36 s/\s+$//;
37 s/\s+/ /g;
38
39 $_
40 }
41
42 sub special {
43 $MA_BEG . (join $MA_SEP, @_) . $MA_END
44 }
45
46 package AsParagraphs;
47
48 use strict;
49
50 use base "Pod::POM::View";
51
52 # nodes (order must stay as it is)
53 sub N_PARENT (){ 0 }
54 sub N_PAR (){ 1 }
55 sub N_LEVEL (){ 2 }
56 sub N_KW (){ 3 }
57 sub N_DOC (){ 4 }
58
59 # paragraphs (order must stay as it is)
60 sub P_INDENT (){ 0 }
61 sub P_LEVEL (){ 1 }
62 sub P_MARKUP (){ 2 }
63 sub P_INDEX (){ 3 }
64
65 *view_seq_file =
66 *view_seq_code =
67 *view_seq_bold = sub { "<b>$_[1]</b>" };
68 *view_seq_italic = sub { "<i>$_[1]</i>" };
69 *view_seq_zero = sub { };
70 *view_seq_space = sub { my $text = $_[1]; $text =~ s/ /&#160;/g; $text };
71 *view_seq_index = sub { push @{ $result[-1][P_INDEX] }, $_[1]; "" };
72
73 sub view_seq_text {
74 my $text = $_[1];
75 $text =~ s/\s+/ /g;
76 ::asxml $text
77 }
78
79 sub view_seq_link {
80 my (undef, $link) = @_;
81
82 my $text = $link =~ s/^(.*)\|// ? $1 : $link;
83
84 if ($link =~ /http:/) {
85 "<u>" . (::asxml $link) . "</u>"
86 } elsif ($link =~ /^\$ARCH\/(.+)$/) {
87 my $path = $1;
88 (my $base = $path) =~ s/.*\///;
89 -f "$ARCH/$path" && system "rsync -av -c \Q$ARCH/$path\E \Qresources/arch/$base";
90 ::special image => "arch/$base", 1;
91 } else {
92 ::special link => $text, $link
93 }
94 }
95
96 sub view_verbatim {
97 push @result, [ $indent * 16, $level, "<tt>" . (::asxml $_[1]) . "</tt>\n" ];
98 ()
99 }
100
101 sub view_textblock {
102 push @result, [ $indent * 16, $level, "$_[1]\n" ];
103 ()
104 }
105
106 sub view_head1 {
107 push @result, [ $indent * 16, $level ];
108 my $title = $_[1]->title->present ($_[0]);
109 $result[-1][P_MARKUP] = "\n\n<span foreground='#ffff00' size='x-large'>$title</span>\n" if length $title;
110 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title;
111 local $level = $level + 1;
112 $_[1]->content->present ($_[0]);
113 ()
114 };
115
116 sub view_head2 {
117 push @result, [ $indent * 16, $level ];
118 my $title = $_[1]->title->present ($_[0]);
119 $result[-1][P_MARKUP] = "\n\n<span foreground='#ccccff' size='large'>$title</span>\n" if length $title;
120 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title;
121 local $level = $level + 1;
122 $_[1]->content->present ($_[0]);
123 ()
124 };
125
126 sub view_head3 {
127 push @result, [ $indent * 16, $level ];
128 my $title = $_[1]->title->present ($_[0]);
129 $result[-1][P_MARKUP] = "\n\n<span size='large'>$title</span>\n" if length $title;
130 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title;
131 local $level = $level + 1;
132 $_[1]->content->present ($_[0]);
133 ()
134 };
135
136 sub view_over {
137 local $indent = $indent + $_[1]->indent;
138 push @result, [ $indent, $level ];
139 $_[1]->content->present ($_[0]);
140 ()
141 }
142
143 sub view_item {
144 push @result, [ $indent * 8, $level ];
145 my $title = $_[1]->title->present ($_[0]);
146 $result[-1][P_MARKUP] = "$title\n" if length $title;
147 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title;
148 local $level = $level + 1;
149 $_[1]->content->present ($_[0]);
150 ()
151 }
152
153 sub view_for {
154 if ($_[1]->format eq "image") {
155 push @result, [
156 $indent * 16,
157 $level,
158 (::special image => "pod/" . $_->text),
159 ];
160 }
161 ()
162 }
163
164 sub view_begin {
165 ()
166 }
167
168 sub view {
169 my ($self, $type, $item) = @_;
170
171 $item->content->present ($self);
172 }
173
174 #############################################################################
175
176 sub as_paragraphs($) {
177 my ($pom) = @_;
178
179 local $indent = 0;
180 local $level = 2;
181 local @result = ( [] );
182
183 $pom->present ("AsParagraphs");
184
185 [grep $_->[P_INDEX] || defined $_->[P_MARKUP], @result]
186 }
187
188 #############################################################################
189
190 my %wiki;
191
192 sub add_node($) {
193 my ($node) = @_;
194
195 for (@{ $node->[N_KW] || {} }) {
196 push @{$wiki{lc $_}}, $node;
197 }
198 }
199
200 my $root;
201 $root->[N_KW] = ["pod"];
202
203 for my $path (@ARGV) {
204 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname";
205 my $base = $1;
206 my $pom = Pod::POM->new->parse_text (do {
207 local $/;
208 open my $pod, "<:utf8", $path
209 or die "$path: $!";
210 <$pod>
211 });
212
213 my $para = as_paragraphs $pom;
214
215 my $pod;
216 $pod->[N_PARENT] = $root;
217 $pod->[N_PAR] = 0;
218 $pod->[N_LEVEL] = 1;
219 $pod->[N_KW] = [$base];
220 $pod->[N_DOC] = $para;
221
222 my @parent = ($pod);
223 add_node $pod;
224
225 for my $idx (0 .. $#$para) {
226 my $par = $para->[$idx];
227
228 while ($parent[-1][N_LEVEL] >= $par->[P_LEVEL]) {
229 pop @parent;
230 }
231
232 if ($par->[P_INDEX]) {
233 my $node;
234 $node->[N_PARENT] = $parent[-1];
235 $node->[N_PAR] = $idx;
236 $node->[N_LEVEL] = $par->[P_LEVEL];
237 $node->[N_KW] = $par->[P_INDEX];
238 $node->[N_DOC] = $para;
239 push @parent, $node;
240 add_node $node;
241 }
242 }
243 }
244
245 Storable::nstore \%wiki, "docwiki.pst";
246
247 add_node $root;