More improvements to URL recognizer.
[sw-tools] / perl / SWInfo.pm
index 276ac05..42c4119 100644 (file)
@@ -1,6 +1,6 @@
 # -*-perl-*-
 #
-# $Id: SWInfo.pm,v 1.2 1999/08/18 17:10:07 mdw Exp $
+# $Id: SWInfo.pm,v 1.3 1999/08/19 12:11:10 mdw Exp $
 #
 # Read and output GNU Info files
 #
@@ -28,6 +28,9 @@
 #----- Revision history -----------------------------------------------------
 #
 # $Log: SWInfo.pm,v $
+# Revision 1.3  1999/08/19 12:11:10  mdw
+# More improvements to URL recognizer.
+#
 # Revision 1.2  1999/08/18 17:10:07  mdw
 # Slight improvements to URL and email address parsing.
 #
@@ -109,8 +112,8 @@ sub info {
   # --- Now translate the node into HTML, first line first ---
 
   $n =~ s/\&/&/;
-  $n =~ s/\</&lt;/;
-  $n =~ s/\>/&gt;/;
+  $n =~ s/\</&lt;</;
+  $n =~ s/\>/>&gt;/;
   $n =~ s/\A( [^\n]* Next:\ *) ([^,\n]*) / $1 . subst($2, $file, $i) /eix;
   $n =~ s/\A( [^\n]* Prev:\ *) ([^,\n]*) / $1 . subst($2, $file, $i) /eix;
   $n =~ s/\A( [^\n]* Up:\ *) ([^,\n]*) / $1 . subst($2, $file, $i) /eix;
@@ -144,9 +147,29 @@ sub info {
   }
   $out .= $n;
 
-  $out =~ s!\b(https?|ftp|file|news):[^]&)\s]*[^]&).,\s\'\"]!<a href="$&">$&</a>!g;
-  $out =~ s!(?:\bmailto:)?([^\s()&;:{}.,\`\"][^\s()&;:{}\`\"]*\@[^\s()&;:{}\'\"]*[^\s()&;:{}.,\'\"])!<a href="mailto:$1">$&</a>!g;
-  $out =~ s!([-_.\w]+)\((\d+\w*)\)!SWMan::subst("$1($2)", $1, $2)!eg;
+  # --- Spot URLs (except `mailto') ---
+
+  $out =~ s! \b (http s? | ftp | file | news) :
+            [^]<>)\s]* [^]<>).,\s\']
+          !urlsubst($&, $&)!egx;
+
+  # --- Spot email addresses (including `mailto' URLs) ---
+
+  $out =~ s! (?:\bmailto:)?
+            ([^\s()<>&;:{}.,\`\'\"] [^\s()<>&;:{}\`\'\"]*
+             \@
+             [^\s()<>&;:{}\'\"]* [^\s()<>&;:{}.,\'\"])
+          !<a href="mailto:$1">$&</a>!gx;
+
+  # --- Spot manpage references ---
+
+  $out =~ s! ([-_.\w]+) \( (\d+\w*) \)
+          !SWMan::subst("$1($2)", $1, $2)!egx;
+
+  # --- Fix up the HTML ---
+
+  $out =~ s/\&lt;\</&lt;/g;
+  $out =~ s/\>\&gt;/&gt;/g;
 
   header("Info: ($file)$node");
   print("<pre>\n$out</pre>\n");