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