PATCH: perldoc in MAINT branch (probably unstable too)
[p5sagit/p5-mst-13.2.git] / lib / Pod / Html.pm
index 1ae81c9..61152af 100644 (file)
@@ -369,6 +369,25 @@ sub pod2html {
     $/ = "";
     my @poddata  = <POD>;
     close(POD);
+
+    # be eol agnostic
+    for (@poddata) {
+       if (/\r/) {
+           if (/\r\n/) {
+               @poddata = map { s/\r\n/\n/g;
+                                /\n\n/ ?
+                                    map { "$_\n\n" } split /\n\n/ :
+                                    $_ } @poddata;
+           } else {
+               @poddata = map { s/\r/\n/g;
+                                /\n\n/ ?
+                                    map { "$_\n\n" } split /\n\n/ :
+                                    $_ } @poddata;
+           }
+           last;
+       }
+    }
+
     clean_data( \@poddata );
 
     # scan the pod for =head[1-6] directives and build an index
@@ -961,9 +980,8 @@ sub scan_headings {
         ($tag, $which_head, $otitle) = ($1,$2,$3);
 
         my $title = depod( $otitle );
-        my $name = htmlify( $title );
+        my $name = anchorify( $title );
         $$sections{$name} = 1;
-        $name =~ s/\s/_/g; # htmlify keeps spaces but we don't want them here..
         $title = process_text( \$otitle );
 
            while ($which_head != $listdepth) {
@@ -1255,9 +1273,9 @@ sub process_pre {
     $rest = $$text;
 
     # insert spaces in place of tabs
-    $rest =~ s#.*#
-           my $line = $&;
-           1 while $line =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
+    $rest =~ s#(.+)#
+           my $line = $1;
+            1 while $line =~ s/(\t+)/' ' x ((length($1) * 8) - $-[0] % 8)/e;
            $line;
        #eg;
 
@@ -1318,23 +1336,25 @@ sub process_pre {
     my $any  = "${ltrs}${gunk}${punc}";
 
     $rest =~ s{
-        \b                          # start at word boundary
-        (                           # begin $1  {
-          $urls     :               # need resource and a colon
-         (?!:)                     # Ignore File::, among others.
-          [$any] +?                 # followed by one or more of any valid
-                                    #   character, but be conservative and
-                                    #   take only what you need to....
-        )                           # end   $1  }
-        (?=                         # look-ahead non-consumptive assertion
-                [$punc]*            # either 0 or more punctuation
-                (?:                 #   followed
-                    [^$any]         #   by a non-url char
-                    |               #   or
-                    $               #   end of the string
-                )                   #
-            |                       # or else
-                $                   #   then end of the string
+       \b                      # start at word boundary
+       (                       # begin $1  {
+           $urls :             # need resource and a colon
+           (?!:)               # Ignore File::, among others.
+           [$any] +?           # followed by one or more of any valid
+                               #   character, but be conservative and
+                               #   take only what you need to....
+       )                       # end   $1  }
+       (?=
+           &quot; &gt;         # maybe pre-quoted '<a href="...">'
+       |                       # or:
+           [$punc]*            # 0 or more punctuation
+           (?:                 #   followed
+               [^$any]         #   by a non-url char
+           |                   #   or
+               $               #   end of the string
+           )                   #
+       |                       # or else
+           $                   #   then end of the string
         )
       }{<a href="$1">$1</a>}igox;
 
@@ -1694,7 +1714,8 @@ sub html_escape {
     $rest   =~ s/</&lt;/g;
     $rest   =~ s/>/&gt;/g;
     $rest   =~ s/"/&quot;/g;
-    $rest   =~ s/'/&apos;/g;
+    # &apos; is only in XHTML, not HTML4.  Be conservative
+    #$rest   =~ s/'/&apos;/g;
     return $rest;
 }
 
@@ -1883,7 +1904,7 @@ sub coderef($$){
             if( exists $pages{$page} and $pages{$page} =~ /([^:.]*)\.[^:]*:/){
                $page = $1 . '.html';
            }
-           my $link = "$htmlroot/$page#item_$fid";
+           my $link = "$htmlroot/$page#item_" . anchorify($fid);
 
            # Here, we take advantage of the knowledge that $htmlfileurl
            # ne '' implies $htmlroot eq ''.
@@ -1894,7 +1915,7 @@ sub coderef($$){
                $url = $link ;
            }
        } else {
-           $url = "#item_" . $fid;
+           $url = "#item_" . anchorify($fid);
        }
 
        confess "url has space: $url" if $url =~ /"[^"]*\s[^"]*"/;