cvs commit: perlfaq/bin perlfaq.cgi

[email protected]
Newsgroups perl.cvs.perlfaq
Message-ID <[email protected]>
cvsuser     02/04/24 10:03:48

  Modified:    bin      perlfaq.cgi
  Log:
  * added some more to the HTML munging routines.  i don't think i'll
  be able to use Pod::HTML (or pod2html) since so much of the behaviour
  is hard-coded and inflexible.  it's really a single-purpose script
  masquerading as a module -- not much reusable code there.
  
  * i think these changes get me most of the way there:
  	+ put PRE tags around non-filled paragraphs
  	+ make links for L<> and some C<> tokens
  	+ remove some POD artifacts
  
  * To Do:
  	+ escape HTML entities
  
  Revision  Changes    Path
  1.2       +25 -2     perlfaq/bin/perlfaq.cgi
  
  Index: perlfaq.cgi
  ===================================================================
  RCS file: /cvs/public/perlfaq/bin/perlfaq.cgi,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- perlfaq.cgi	15 Apr 2002 17:20:30 -0000	1.1
  +++ perlfaq.cgi	24 Apr 2002 17:03:48 -0000	1.2
  @@ -1,5 +1,5 @@
   #!/usr/bin/perl -wT
  -# $Id: perlfaq.cgi,v 1.1 2002/04/15 17:20:30 comdog Exp $
  +# $Id: perlfaq.cgi,v 1.2 2002/04/24 17:03:48 comdog Exp $
   
   use strict;
   
  @@ -54,6 +54,9 @@
   	}
   	1 .. 9;
   
  +@links{ qw(srand rand) } = map {
  +	qq|<a href="$_">$_</a>| } qw(srand rand);
  +	
   my $terms = param( 'terms' );
   
   # collapse all whitespace to a single space
  @@ -80,10 +83,30 @@
   
   my $text_result = `$PERLDOC $PERLDOC_OPTS $terms 2> /dev/null`;
   
  -# rudimentary HTML munging
  +# rudimentary HTML munging -- once this is nice-nice we should 
  +# refactor it
  +
  +# munge headings
   $text_result =~ s|^=head1\s+Found in .*/perlfaq(\d)\.pod$|$links{"perlfaq$1"}|mg;
   $text_result =~ s|^=head2(.*)|<b>$1</b>|mg;
   
  +# remove trailing whitespace
  +$text_result =~ s|\s+$||m;
  +
  +# wrap PRE tags around sections that start with whitespace
  +$text_result =~ s|^([\t ]+\S.*?)$/(?=\S)|\n<pre>\n$1</pre>\n\n|gms;
  +
  +# munge links
  +	# URLs in text flow
  +$text_result =~ s|(http://\S+)|<a href="$1">$1</a>|gi;
  +$text_result =~ s|L<(.*?)>|<a href="$1">$1</a>|g;
  +$text_result =~ s|C<(.*?)>| $links{$1} or "<tt>$1</tt>" |eg;
  +
  +# remove remaining POD artifacts
  +$text_result =~ s|^=over\s+\d+.*$||mg;
  +$text_result =~ s|^=back.*$||mg;
  +
  +#
   print $text_result;
   
   sub error
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.