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