develooper Front page | perl.perl5.porters | Postings from February 2000

[PATCH Pod/Html.pm]; was Re: [PATCH perlfunc.pod perlop.pod] plain POD readability

Thread Previous
From:
Robin Barker
Date:
February 29, 2000 10:52
Subject:
[PATCH Pod/Html.pm]; was Re: [PATCH perlfunc.pod perlop.pod] plain POD readability
Message ID:
200002291851.SAA07228@tempest.npl.co.uk

> From tchrist@chthon.perl.com  Tue Feb 29 12:39:33 2000
> 
> >I have removed E<...> from perlfunc.pod and perlop.pod
> >using the C<< ... >> stuff.  This should make the plain
> >POD more readable.  
> 
> Have all translators been updated?
> 
> --tom

Good point.

I think only pod2html and pod2latex don't use Pod::Parser.

Here is a patch to Pod/Html.pm which should fix pod2html.
I have tested it on my patched version of perlfunc.pod perlop.pod.

Robin 

--- lib/Pod/Html.pm	2000/02/29 18:27:50	1.1
+++ lib/Pod/Html.pm	2000/02/29 18:46:01	1.2
@@ -1382,7 +1382,9 @@
 # converted to html commands.
 #
 
-sub process_text1($$;$);
+sub process_text1($$;$$);
+sub pattern ($) { $_[0] ? '[^\S\n]+'.('>' x ($_[0] + 1)) : '>' }
+sub closing ($) { local($_) = shift; (defined && s/\s+$//) ? length : 0 }
 
 sub process_text {
     return if $ignore;
@@ -1391,8 +1393,8 @@
     $$tref = $res;
 }
 
-sub process_text1($$;$){
-    my( $lev, $rstr, $func ) = @_;
+sub process_text1($$;$$){
+    my( $lev, $rstr, $func, $closing ) = @_;
     $lev++ unless defined $func;
     my $res = '';
 
@@ -1404,7 +1406,7 @@
     } elsif( $func eq 'C' ){
 	# C<code> - can be a ref or <CODE></CODE>
 	# need to extract text
-	my $par = go_ahead( $rstr, 'C' );
+	my $par = go_ahead( $rstr, 'C', $closing );
 
 	## clean-up of the link target
         my $text = depod( $par );
@@ -1432,7 +1434,7 @@
 	## L<text|cross-ref> => produce text, use cross-ref for linking 
 	## L<cross-ref> => make text from cross-ref
 	## need to extract text
-	my $par = go_ahead( $rstr, 'L' );
+	my $par = go_ahead( $rstr, 'L', $closing );
 
         # some L<>'s that shouldn't be:
 	# a) full-blown URL's are emitted as-is
@@ -1557,15 +1559,16 @@
 	    unless $$rstr =~ s/^>//;
 
     } else {
-	while( $$rstr =~ s/\A(.*?)([BCEFILSXZ]<|>)//s ){
+        my $term = pattern $closing;
+	while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)//s ){
 	    # all others: either recurse into new function or
-	    # terminate at closing angle bracket
+	    # terminate at closing angle bracket(s)
 	    my $pt = $1;
-            $pt .= '>' if $2 eq '>' &&  $lev == 1;
+            $pt .= $2 if !$3 &&  $lev == 1;
 	    $res .= $lev == 1 ? pure_text( $pt ) : inIS_text( $pt );
-	    return $res if $2 eq '>' && $lev > 1;
-            if( $2 ne '>' ){
-		$res .= process_text1( $lev, $rstr, substr($2,0,1) );
+	    return $res if !$3 && $lev > 1;
+            if( $3 ){
+		$res .= process_text1( $lev, $rstr, $3, closing $4 );
 	    }
 
 	}
@@ -1581,16 +1584,18 @@
 #
 # go_ahead: extract text of an IS (can be nested)
 #
-sub go_ahead($$){
-    my( $rstr, $func ) = @_;
+sub go_ahead($$$){
+    my( $rstr, $func, $closing ) = @_;
     my $res = '';
-    my $level = 1;
-    while( $$rstr =~ s/\A(.*?)([BCEFILSXZ]<|>)//s ){
+    my @closing = ($closing);
+    while( $$rstr =~
+      s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|@{[pattern $closing[0]]})//s ){
 	$res .= $1;
-	if( $2 eq '>' ){
-	    return $res if --$level == 0;
+	unless( $3 ){
+	    shift @closing;
+	    return $res unless @closing;
 	} else {
-	    ++$level;
+	    unshift @closing, closing $4;
 	}
 	$res .= $2;
     }
@@ -1889,7 +1894,7 @@
 $E2c{verbar} = '|';
 $E2c{amp}    = '&'; # in Tk's pods
 
-sub depod1($;$);
+sub depod1($;$$);
 
 sub depod($){
     my $string;
@@ -1902,15 +1907,15 @@
     }    
 }
 
-sub depod1($;$){
-  my( $rstr, $func ) = @_;
+sub depod1($;$$){
+  my( $rstr, $func, $closing ) = @_;
   my $res = '';
   return $res unless defined $$rstr;
   if( ! defined( $func ) ){
       # skip to next begin of an interior sequence
-      while( $$rstr =~ s/\A(.*?)([BCEFILSXZ])<// ){
+      while( $$rstr =~ s/\A(.*?)([BCEFILSXZ])<(<+[^\S\n]+)?// ){
          # recurse into its text
-         $res .= $1 . depod1( $rstr, $2 );
+         $res .= $1 . depod1( $rstr, $2, closing $3);
       }
       $res .= $$rstr;
   } elsif( $func eq 'E' ){
@@ -1926,10 +1931,11 @@
   } else {
       # all others: either recurse into new function or
       # terminate at closing angle bracket
-      while( $$rstr =~ s/\A(.*?)([BCEFILSXZ]<|>)// ){
+      my $term = pattern $closing; 
+      while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)// ){
 	  $res .= $1;
-	  last if $2 eq '>';
-          $res .= depod1( $rstr, substr($2,0,1) );
+	  last unless $3;
+          $res .= depod1( $rstr, $3, closing $4 );
       }
       ## If we're here and $3: undelimited interior sequence.
       ## Ignored, as this is called without proper indication of where we are.

-- 
Robin Barker                        | Eail:  Robin.Barker@npl.co.uk
CISE, Building 10,                  | Phone: +44 (0) 20 8943 7090
National Physical Laboratory,       | Fax:   +44 (0) 20 8977 7091
Teddington, Middlesex, UK. TW11 OLW | WWW:   http://www.npl.co.uk

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About