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 974674764..3747370f3 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 @@ public class AptSink /** 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 af310e9af..812f4965b 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()); + } }