ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pod2wiki
Revision: 1.6
Committed: Mon Aug 14 02:08:30 2006 UTC (17 years, 9 months ago) by root
Branch: MAIN
Changes since 1.5: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

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