maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject svn commit: r1604604 - in /maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src: main/java/org/apache/maven/doxia/siterenderer/sink/ test/java/org/apache/maven/doxia/siterenderer/
Date Sun, 22 Jun 2014 15:36:56 GMT
Author: hboutemy
Date: Sun Jun 22 15:36:56 2014
New Revision: 1604604

URL: http://svn.apache.org/r1604604
Log:
[DOXIASITETOOLS-91] generate section title anchors at beginning of section instead of end,
for better usability in web browser

Modified:
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/SiteRendererSink.java
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/AptVerifier.java
    maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/FaqVerifier.java

Modified: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/SiteRendererSink.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/SiteRendererSink.java?rev=1604604&r1=1604603&r2=1604604&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/SiteRendererSink.java
(original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/sink/SiteRendererSink.java
Sun Jun 22 15:36:56 2014
@@ -55,6 +55,8 @@ public class SiteRendererSink
 
     private StringBuilder sectionTitleBuffer;
 
+    private StringBuilder sectionTitleWriteBuffer;
+
     private boolean sectionHasID;
 
     private boolean isSectionTitle;
@@ -263,11 +265,13 @@ public class SiteRendererSink
     @Override
     protected void onSectionTitle( int depth, SinkEventAttributes attributes )
     {
-        this.sectionTitleBuffer = new StringBuilder();
         sectionHasID = ( attributes != null && attributes.isDefined ( Attribute.ID.toString()
) );
         isSectionTitle = true;
 
         super.onSectionTitle( depth, attributes );
+
+        this.sectionTitleBuffer = new StringBuilder();
+        this.sectionTitleWriteBuffer = new StringBuilder();
     }
 
     /** {@inheritDoc} */
@@ -276,20 +280,27 @@ public class SiteRendererSink
     {
         String sectionTitle = sectionTitleBuffer.toString();
         this.sectionTitleBuffer = null;
+        String sectionWriteTitle = sectionTitleWriteBuffer.toString();
+        this.sectionTitleWriteBuffer = null;
 
-        if ( !sectionHasID && !StringUtils.isEmpty( sectionTitle ) )
+        if ( !StringUtils.isEmpty( sectionTitle ) )
         {
-            String id = HtmlTools.encodeId( sectionTitle );
-            if ( ( anchorsInSectionTitle == null ) || ( !anchorsInSectionTitle.contains(
id ) ) )
+            if ( sectionHasID )
             {
-                anchor( id );
-                anchor_();
+                sectionHasID = false;
+            }
+            else
+            {
+                String id = HtmlTools.encodeId( sectionTitle );
+                if ( ( anchorsInSectionTitle == null ) || ( !anchorsInSectionTitle.contains(
id ) ) )
+                {
+                    anchor( id );
+                    anchor_();
+                }
             }
         }
-        else
-        {
-            sectionHasID = false;
-        }
+
+        super.write( sectionWriteTitle );
 
         this.isSectionTitle = false;
         anchorsInSectionTitle = null;
@@ -347,6 +358,14 @@ public class SiteRendererSink
             }
         }
 
-        super.write( txt );
+        if ( sectionTitleWriteBuffer != null )
+        {
+            // this implies we're inside a section title, collect text events for anchor
generation
+            sectionTitleWriteBuffer.append( txt );
+        }
+        else
+        {
+            super.write( txt );
+        }
     }
 }

Modified: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/AptVerifier.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/AptVerifier.java?rev=1604604&r1=1604603&r2=1604604&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/AptVerifier.java
(original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/AptVerifier.java
Sun Jun 22 15:36:56 2014
@@ -113,6 +113,9 @@ public class AptVerifier
         // Note: htmlunit strips the white space, actual result is ok
         assertEquals( "Section formatting: italicboldmono", h2.asText().trim() );
 
+        a = (HtmlAnchor) elementIterator.next();
+        assertEquals( "Section_formatting:_italic_bold_mono", a.getAttribute( "name" ) );
+
         HtmlItalic italic = (HtmlItalic) elementIterator.next();
         assertEquals( "i", italic.getTagName() );
         assertEquals( "italic", italic.asText().trim() );
@@ -125,9 +128,6 @@ public class AptVerifier
         assertEquals( "tt", tt.getTagName() );
         assertEquals( "mono", tt.asText().trim() );
 
-        a = (HtmlAnchor) elementIterator.next();
-        assertEquals( "Section_formatting:_italic_bold_mono", a.getAttribute( "name" ) );
-
         div = (HtmlDivision) elementIterator.next();
         assertEquals( "section", div.getAttribute( "class" ) );
 
@@ -136,6 +136,9 @@ public class AptVerifier
         // Note: htmlunit strips the white space, actual result is ok
         assertEquals( "SubSection formatting: italicboldmono", h3.asText().trim() );
 
+        a = (HtmlAnchor) elementIterator.next();
+        assertEquals( "SubSection_formatting:_italic_bold_mono", a.getAttribute( "name" )
);
+
         italic = (HtmlItalic) elementIterator.next();
         assertEquals( "i", italic.getTagName() );
         assertEquals( "italic", italic.asText().trim() );
@@ -148,9 +151,6 @@ public class AptVerifier
         assertEquals( "tt", tt.getTagName() );
         assertEquals( "mono", tt.asText().trim() );
 
-        a = (HtmlAnchor) elementIterator.next();
-        assertEquals( "SubSection_formatting:_italic_bold_mono", a.getAttribute( "name" )
);
-
         p = (HtmlParagraph) elementIterator.next();
         assertNotNull( p );
 

Modified: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/FaqVerifier.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/FaqVerifier.java?rev=1604604&r1=1604603&r2=1604604&view=diff
==============================================================================
--- maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/FaqVerifier.java
(original)
+++ maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/test/java/org/apache/maven/doxia/siterenderer/FaqVerifier.java
Sun Jun 22 15:36:56 2014
@@ -68,10 +68,10 @@ public class FaqVerifier
         assertEquals( h2.asText().trim(), "Oft Asked Questions" );
 
         HtmlAnchor a = (HtmlAnchor) elementIterator.next();
-        assertEquals( a.getAttribute( "name" ), "top" );
+        assertEquals( "Oft_Asked_Questions", a.getAttribute( "name" ) );
 
         a = (HtmlAnchor) elementIterator.next();
-        assertEquals( a.getAttribute( "name" ), "Oft_Asked_Questions" );
+        assertEquals( "top", a.getAttribute( "name" ) );
 
         HtmlParagraph p = (HtmlParagraph) elementIterator.next();
         element = elementIterator.next();



Mime
View raw message