summaryrefslogtreecommitdiff
path: root/www/faq2html.pl
diff options
context:
space:
mode:
Diffstat (limited to 'www/faq2html.pl')
-rwxr-xr-xwww/faq2html.pl99
1 files changed, 99 insertions, 0 deletions
diff --git a/www/faq2html.pl b/www/faq2html.pl
new file mode 100755
index 0000000000..47018fcf9b
--- /dev/null
+++ b/www/faq2html.pl
@@ -0,0 +1,99 @@
1#!/usr/bin/perl
2
3# this is really a faq2html and should only be used for this purpose
4
5sub fixline {
6 $_ =~ s/\</&lt;/g;
7 $_ =~ s/\>/&gt;/g;
8
9 $_ =~ s/(http:\/\/([a-zA-Z0-9_.\/-]*)[^\) .\n])/\<a href=\"$1\"\>$1\<\/a\>/g;
10
11 $_ =~ s/(\\|\/)$/$1&nbsp;/g; # clobber backslash on end of line
12}
13
14sub show {
15 if(@q) {
16 print @q;
17 undef @q;
18 }
19 if(@a) {
20 print @a;
21 undef @a;
22 }
23 if(@p) {
24 print "<pre>\n";
25 print @p;
26 print "</pre>\n";
27 undef @p;
28 }
29}
30
31while(<STDIN>) {
32
33 fixline($_);
34
35 # detect and mark Q-sections
36 if( $_ =~ /^(Q(\d*)[.:] )(.*)/) {
37
38 show();
39
40 # collect the full Q
41 push @q, "<a name=\"$2\"></a><p class=\"faqq\">";
42 push @q, "$2. $3";
43 my $line;
44
45 $indent = length($1);
46 $first = " " x $indent;
47
48 #print "$indent|$first|$1|\n";
49
50 while(<STDIN>) {
51
52 fixline($_);
53
54 $line = $_;
55
56 if($_ !~ /^A/) {
57 push @q, "$_";
58 }
59 else {
60 last;
61 }
62 }
63 # first line of A
64 $line =~ s/^A(\d*)[.:] *//g; # cut off the "A[num]."
65 push @a, "<p class=\"faqa\">";
66 push @a, $line;
67
68 $prev='a';
69 next;
70 }
71 # print "$_ matches '$first'?\n";
72
73 if($_ =~ /^$first(\S)/) {
74
75
76 if($prev ne 'a') {
77 show();
78 push @a, "<p class=\"faqa\">";
79 }
80
81 push @a, $_;
82 $prev='a';
83 }
84 else {
85 if($prev ne 'p') {
86 show();
87 }
88 if(@p) {
89 # if we have data, we fix blank lines
90 $_ =~ s/^\s*$/\&nbsp;\n/g; # empty lines are nbsp
91 push @p, $_; # add it
92 }
93 elsif($_ !~ /^\s*$/) {
94 # this is not a blank line, add it
95 push @p, $_;
96 }
97 $prev = 'p';
98 }
99}