maven-doxia-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ltheu...@apache.org
Subject svn commit: r555417 - /maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java
Date Wed, 11 Jul 2007 22:14:35 GMT
Author: ltheussl
Date: Wed Jul 11 15:14:33 2007
New Revision: 555417

URL: http://svn.apache.org/viewvc?view=rev&rev=555417
Log:
DOXIA-47: fix local anchors/links.

Modified:
    maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java

Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java?view=diff&rev=555417&r1=555416&r2=555417
==============================================================================
--- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java
(original)
+++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlSink.java
Wed Jul 11 15:14:33 2007
@@ -645,38 +645,46 @@
 
     public void link( String name )
     {
-        if ( !headFlag )
-        {
-            if ( isExternalLink( name ) )
-            {
-                write( "<a href=\"" + HtmlTools.escapeHTML( name ) + "\" class=\"externalLink\">"
);
-            }
-            else
-            {
-                write( "<a href=\"" + HtmlTools.escapeHTML( name ) + "\">" );
-            }
-        }
+        link( name, null );
     }
 
     public void link( String name, String target )
     {
         if ( !headFlag )
         {
-            if ( isExternalLink( name ) )
+
+            String targ = "";
+            if ( target != null )
+            {
+                targ = " target=\"" + target + "\"";
+            }
+
+            if ( StructureSink.isExternalLink( name ) )
             {
-                write( "<a href=\"" + HtmlTools.escapeHTML( name ) + "\" class=\"externalLink\"
target=\"" + target +
-                    "\">" );
+                String clas = "";
+                if ( isExternalLink( name ) )
+                {
+                    clas = " class=\"externalLink\"";
+                }
+                write( "<a href=\"" + HtmlTools.escapeHTML( name ) + "\"" + clas + targ
+ ">" );
             }
             else
             {
-                write( "<a href=\"" + HtmlTools.escapeHTML( name ) + "\" target=\"" +
target + "\">" );
+                write( "<a href=\"#" + HtmlTools.escapeHTML( name ) + "\"" + targ + ">"
);
             }
         }
     }
 
-    private static boolean isExternalLink( String href )
+    /* StructureSink.isExternalLink also treats links to other documents as
+     * external links, those should not have a class="externalLink" attribute.
+     */
+    private boolean isExternalLink( String href )
     {
-        return href.toLowerCase().startsWith( "http" ) || href.toLowerCase().startsWith(
"https" );
+        String text = href.toLowerCase();
+        return ( text.indexOf( "http:/" ) == 0 || text.indexOf( "https:/" ) == 0
+            || text.indexOf( "ftp:/" ) == 0 || text.indexOf( "mailto:" ) == 0
+            || text.indexOf( "file:/" ) == 0 );
+
     }
 
     public void link_()



Mime
View raw message