ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pod2wiki
Revision: 1.1
Committed: Sun Aug 13 02:43:23 2006 UTC (17 years, 9 months ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

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