Author: ltheussl Date: Sat May 17 00:01:52 2008 New Revision: 657299 URL: http://svn.apache.org/viewvc?rev=657299&view=rev Log: [DOXIA-208] Adapt link/anchor handling in apt module. Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptParserTest.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java?rev=657299&r1=657298&r2=657299&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java Sat May 17 00:01:52 2008 @@ -462,13 +462,7 @@ String linkAnchor = getTraversedAnchor( text, i + 1, end ); - if ( !DoxiaUtils.isValidId( linkAnchor ) ) - { - // debug only: anchors in apt may contain spaces - getLog().debug( "Modified anchor name: " + linkAnchor ); - - linkAnchor = DoxiaUtils.encodeId( linkAnchor ); - } + linkAnchor = AptUtils.encodeAnchor( linkAnchor ); sink.anchor( linkAnchor ); } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java?rev=657299&r1=657298&r2=657299&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java Sat May 17 00:01:52 2008 @@ -24,6 +24,7 @@ import java.util.Stack; import org.apache.maven.doxia.sink.AbstractTextSink; + import org.codehaus.plexus.util.StringUtils; /** @@ -725,7 +726,7 @@ if ( !headerFlag ) { write( LINK_START_1_MARKUP ); - text( name ); + text( name.startsWith( "#" ) ? name.substring( 1 ) : name ); write( LINK_START_2_MARKUP ); } } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java?rev=657299&r1=657298&r2=657299&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptUtils.java Sat May 17 00:01:52 2008 @@ -57,9 +57,9 @@ * ie is not a link within the same document. * * @param link The link to check. - * @return True if the link (ignoring case) starts with either of the - * following: "http:/", "https:/", "ftp:/", "mailto:", "file:/", - * "../" or "./". Note that Windows style separators "\" are not allowed + * @return True if the link (ignoring case) starts with either "http:/", + * "https:/", "ftp:/", "mailto:", "file:/", "../", "./" or contains the + * string "://". Note that Windows style separators "\" are not allowed * for URIs, see http://www.ietf.org/rfc/rfc2396.txt , section 2.4.3. */ public static boolean isExternalLink( String link ) @@ -69,7 +69,7 @@ return ( text.indexOf( "http:/" ) == 0 || text.indexOf( "https:/" ) == 0 || text.indexOf( "ftp:/" ) == 0 || text.indexOf( "mailto:" ) == 0 || text.indexOf( "file:/" ) == 0 || text.indexOf( "../" ) == 0 - || text.indexOf( "./" ) == 0 ); + || text.indexOf( "./" ) == 0 || text.indexOf( "://" ) != -1 ); } /** @@ -79,6 +79,9 @@ * * @param text The text to transform. * @return The text with all non-LetterOrDigit characters removed. + * @deprecated This method was used for the original apt format, which + * removed all non alphanumeric characters from anchors. + * Use {@link #encodeAnchor(String)} instead. */ public static String linkToKey( String text ) { @@ -97,6 +100,57 @@ return buffer.toString(); } + /** + * Construct a valid anchor. This is a simplified version of + * {@link org.apache.maven.doxia.util.DoxiaUtils#encodeId(String)} + * to ensure the anchor is a valid Doxia id. + * The procedure is identical to the one in + * {@link org.apache.maven.doxia.util.HtmlTools#encodeId(String)}: + * + *