[GitHub] asfgit closed pull request #13: [DOXIA-497] Fix rendering links and paragraphs inside tables

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] asfgit closed pull request #13: [DOXIA-497] Fix rendering links and paragraphs inside tables

GitBox
asfgit closed pull request #13: [DOXIA-497] Fix rendering links and paragraphs inside tables
URL: https://github.com/apache/maven-doxia/pull/13
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java b/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java
index 97467476..3747370f 100644
--- a/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java
+++ b/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java
@@ -65,6 +65,9 @@
     /**  tableCaptionFlag. */
     private boolean tableCaptionFlag;
 
+    /**  tableCellFlag. */
+    private boolean tableCellFlag;
+
     /**  headerFlag. */
     private boolean headerFlag;
 
@@ -164,6 +167,7 @@ protected void init()
         this.date = null;
         this.startFlag = true;
         this.tableCaptionFlag = false;
+        this.tableCellFlag = false;
         this.headerFlag = false;
         this.bufferFlag = false;
         this.itemFlag = false;
@@ -518,7 +522,11 @@ public void pageBreak()
     /** {@inheritDoc} */
     public void paragraph()
     {
-        if ( itemFlag )
+        if ( tableCellFlag )
+        {
+            // ignore paragraphs in table cells
+        }
+        else if ( itemFlag )
         {
             write( EOL + EOL + "  " + listNestingIndent );
         }
@@ -531,7 +539,14 @@ public void paragraph()
     /** {@inheritDoc} */
     public void paragraph_()
     {
-        write( EOL + EOL );
+     if ( tableCellFlag )
+     {
+     // ignore paragraphs in table cells
+     }
+     else
+     {
+     write( EOL + EOL );
+     }
     }
 
     /** {@inheritDoc} */
@@ -696,6 +711,7 @@ public void tableCell( boolean headerRow )
         {
             buffer.append( TABLE_CELL_SEPARATOR_MARKUP );
         }
+        tableCellFlag = true;
     }
 
     /** {@inheritDoc} */
@@ -715,6 +731,7 @@ public void tableHeaderCell_()
      */
     private void endTableCell()
     {
+        tableCellFlag = false;
         buffer.append( TABLE_CELL_SEPARATOR_MARKUP );
         cellCount++;
     }
@@ -928,7 +945,14 @@ public void unknown( String name, Object[] requiredParams, SinkEventAttributes a
     protected void write( String text )
     {
         startFlag = false;
-        writer.write( unifyEOLs( text ) );
+        if ( tableCellFlag )
+        {
+         buffer.append( text );
+     }
+        else
+        {
+         writer.write( unifyEOLs( text ) );
+     }
     }
 
     /**
diff --git a/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java b/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java
index af310e9a..812f4965 100644
--- a/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java
+++ b/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptSinkTest.java
@@ -275,4 +275,58 @@ protected String getCommentBlock( String text )
     {
         return "~~" + text;
     }
+
+    /**
+     * test for DOXIA-497.
+     */
+    public void testLinksAndParagraphsInTableCells()
+    {
+        final String linkTarget = "target";
+        final String linkText = "link";
+        final String paragraphText = "paragraph text";
+        final Sink sink = getSink();
+        sink.table();
+        sink.tableRow();
+        sink.tableCell();
+        sink.link(linkTarget);
+        sink.text(linkText);
+        sink.link_();
+        sink.tableCell_();
+        sink.tableCell();
+        sink.paragraph();
+        sink.text(paragraphText);
+        sink.paragraph_();
+        sink.tableCell_();
+        sink.tableRow_();
+        sink.table_();
+        sink.flush();
+        sink.close();
+
+        String expected = EOL + AptMarkup.TABLE_ROW_START_MARKUP +
+                AptMarkup.MINUS +
+                AptMarkup.MINUS +
+                AptMarkup.TABLE_ROW_START_MARKUP +
+                AptMarkup.STAR +
+                EOL +
+                AptMarkup.LEFT_CURLY_BRACKET +
+                AptMarkup.LEFT_CURLY_BRACKET +
+                AptMarkup.LEFT_CURLY_BRACKET +
+                linkTarget +
+                AptMarkup.RIGHT_CURLY_BRACKET +
+                linkText +
+                AptMarkup.RIGHT_CURLY_BRACKET +
+                AptMarkup.RIGHT_CURLY_BRACKET +
+                AptMarkup.TABLE_CELL_SEPARATOR_MARKUP +
+                paragraphText +
+                AptMarkup.TABLE_CELL_SEPARATOR_MARKUP +
+                EOL +
+                AptMarkup.TABLE_ROW_START_MARKUP +
+                AptMarkup.MINUS +
+                AptMarkup.MINUS +
+                AptMarkup.TABLE_ROW_START_MARKUP +
+                AptMarkup.STAR +
+                EOL;
+
+        assertEquals("Wrong link or paragraph markup in table cell", expected, getSinkContent());
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]