diff options
author | Robert Hak <adiamas@rockbox.org> | 2002-08-22 03:34:09 +0000 |
---|---|---|
committer | Robert Hak <adiamas@rockbox.org> | 2002-08-22 03:34:09 +0000 |
commit | 05256598779d10a331972941c80cf502770de44d (patch) | |
tree | 64c7976cd7c17bc617d56aee816daa186aba9413 /www | |
parent | d421f5b3729367f8345c268adea2b0f7b8e30777 (diff) | |
download | rockbox-05256598779d10a331972941c80cf502770de44d.tar.gz rockbox-05256598779d10a331972941c80cf502770de44d.zip |
renameing txt2plain.pl to faq2html.pl
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1911 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'www')
-rwxr-xr-x | www/faq2html.pl | 99 |
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 | |||
5 | sub fixline { | ||
6 | $_ =~ s/\</</g; | ||
7 | $_ =~ s/\>/>/g; | ||
8 | |||
9 | $_ =~ s/(http:\/\/([a-zA-Z0-9_.\/-]*)[^\) .\n])/\<a href=\"$1\"\>$1\<\/a\>/g; | ||
10 | |||
11 | $_ =~ s/(\\|\/)$/$1 /g; # clobber backslash on end of line | ||
12 | } | ||
13 | |||
14 | sub 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 | |||
31 | while(<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*$/\ \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 | } | ||