diff options
| author | Daniel Stenberg <daniel@haxx.se> | 2002-08-21 14:15:53 +0000 |
|---|---|---|
| committer | Daniel Stenberg <daniel@haxx.se> | 2002-08-21 14:15:53 +0000 |
| commit | 86d31112d0839ede9b1ec6d828a5b2f188070be7 (patch) | |
| tree | 660417dfab7de067c922ca97b7bc67ad96a5a395 | |
| parent | 9af59727b36f841f5554558ae48107358bda4968 (diff) | |
| download | rockbox-86d31112d0839ede9b1ec6d828a5b2f188070be7.zip rockbox-86d31112d0839ede9b1ec6d828a5b2f188070be7.tar.gz rockbox-86d31112d0839ede9b1ec6d828a5b2f188070be7.tar.bz2 rockbox-86d31112d0839ede9b1ec6d828a5b2f188070be7.tar.xz | |
better use of <p> for plain texts
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1886 a1c6a512-1295-4272-9138-f99709370657
| -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 287e878..c34f94e 100755 --- a/www/txt2plain.pl +++ b/www/txt2plain.pl @@ -8,33 +8,93 @@ sub fixline { $_ =~ s/(http:\/\/([a-zA-Z0-9_.\/-]*)[^\) .\n])/\<a href=\"$1\"\>$1\<\/a\>/g; - $_ =~ s/^\s*$/\ \n/g; # empty lines are nbsp $_ =~ s/(\\|\/)$/$1 /g; # clobber backslash on end of line } +sub show { + if(@q) { + print @q; + undef @q; + } + if(@a) { + print @a; + undef @a; + print "</blockquote>\n"; + } + if(@p) { + print "<pre>\n"; + print @p; + print "</pre>\n"; + undef @p; + } +} + while(<STDIN>) { fixline($_); # detect and mark Q-sections - if( $_ =~ /^Q(\d*)/) { - print "</pre>\n<a name=\"$1\"></a><div class=\"faqq\">$_"; + if( $_ =~ /^(Q(\d*)[.:] )(.*)/) { + + show(); + + # collect the full Q + push @q, "<a name=\"$2\"></a><p class=\"faqq\">"; + push @q, "$2. $3"; my $line; + + $indent = length($1); + $first = " " x $indent; + + #print "$indent|$first|$1|\n"; + while(<STDIN>) { fixline($_); $line = $_; + if($_ !~ /^A/) { - print "$_"; + push @q, "$_"; } else { last; } } - print "</div>\n<pre class=\"faqa\">$line"; + # first line of A + $line =~ s/^A(\d*)[.:] *//g; # cut off the "A[num]." + push @a, "<blockquote><p class=\"faqa\">"; + push @a, $line; + + $prev='a'; next; } + # print "$_ matches '$first'?\n"; + + if($_ =~ /^$first(\S)/) { + + + if($prev ne 'a') { + show(); + push @a, "<blockquote><p class=\"faqa\">"; + } - print $_; + push @a, $_; + $prev='a'; + } + else { + if($prev ne 'p') { + show(); + } + if(@p) { + # if we have data, we fix blank lines + $_ =~ s/^\s*$/\ \n/g; # empty lines are nbsp + push @p, $_; # add it + } + elsif($_ !~ /^\s*$/) { + # this is not a blank line, add it + push @p, $_; + } + $prev = 'p'; + } } |