More improvements to URL recognizer.
[sw-tools] / perl / SWDoc.pm
index d519b11..aeedb04 100644 (file)
@@ -1,6 +1,6 @@
 # -*-perl-*-
 #
-# $Id: SWDoc.pm,v 1.2 1999/08/18 17:10:07 mdw Exp $
+# $Id: SWDoc.pm,v 1.3 1999/08/19 12:11:09 mdw Exp $
 #
 # Display documentation files
 #
@@ -28,6 +28,9 @@
 #----- Revision history -----------------------------------------------------
 #
 # $Log: SWDoc.pm,v $
+# Revision 1.3  1999/08/19 12:11:09  mdw
+# More improvements to URL recognizer.
+#
 # Revision 1.2  1999/08/18 17:10:07  mdw
 # Slight improvements to URL and email address parsing.
 #
@@ -59,12 +62,38 @@ sub doc {
   while (my $line = $fh->getline()) {
     last if $line =~ /\f/;
     $line =~ s/\&/&/g;
-    $line =~ s/\</&lt;/g;
-    $line =~ s/\>/&gt;/g;
-    $line =~ s!\b(https?|ftp|file|news):[^]&)\s]*[^]&).,\s\']!<a href="$&">$&</a>!g;
-    $line =~ s!info:([^]&)\s]*[^]&).,\s\'\"])!<a href="$ref?act=info&file=$1&node=Top">$&</a>!g;
-    $line =~ s!(?:\bmailto:)?([^\s()&;:{}.,\`\"][^\s()&;:{}\`\"]*\@[^\s()&;:{}\'\"]*[^\s()&;:{}.,\'\"])!<a href="mailto:$1">$&</a>!g;
-    $line =~ s!([-_.\w]+)\((\d+\w*)\)!SWMan::subst("$1($2)", $1, $2)!eg;
+    $line =~ s/\</&lt;</g;
+    $line =~ s/\>/>&gt;/g;
+
+    # --- Spot URLs (except `mailto') ---
+
+    $line =~ s! \b (http s? | ftp | file | news) :
+               [^])\s<>]* [^]<>&).,\s\']
+             !SWMan::urlsubst($&, $&)!egx;
+
+    # --- Spot email addresses (including `mailto' URLs) ---
+
+    $line =~ s! (?:\bmailto:)?
+               ([^\s()&;:<>&{}.,\`\'\"] [^\s()&;:<>&{}\`\'\"]*
+                \@
+                [^\s()&;:{}<>&\'\"]* [^\s()&;:{}<>&.,\'\"])
+             !<a href="mailto:$1">$&</a>!gx;
+
+    # --- Spot info references ---
+
+    $line =~ s! \b info: ([^]&)\s<>]* [^]&).,\s<>\'\"])
+              !<a href="$ref?act=info&file=$1&node=Top">$&</a>!gx;
+
+    # --- Spot manpage references ---
+
+    $line =~ s! ([-_.\w]+) \( (\d+\w*) \)
+             !SWMan::subst("$1($2)", $1, $2)!egx;
+
+    # --- Finally fix up the HTML properly ---
+
+    $line =~ s/\&lt\;\</&lt;/g;
+    $line =~ s/\>\&gt\;/&gt;/g;
+
     print $line;
   }
   print "</pre>\n";