Skip to content

Commit

Permalink
[DOXIA-497] Fix rendering links and paragraphs inside tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Kurz authored and slachiewicz committed Jul 15, 2018
1 parent c99e7a4 commit d65da7e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public class AptSink
/** tableCaptionFlag. */
private boolean tableCaptionFlag;

/** tableCellFlag. */
private boolean tableCellFlag;

/** headerFlag. */
private boolean headerFlag;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}
Expand All @@ -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} */
Expand Down Expand Up @@ -696,6 +711,7 @@ public void tableCell( boolean headerRow )
{
buffer.append( TABLE_CELL_SEPARATOR_MARKUP );
}
tableCellFlag = true;
}

/** {@inheritDoc} */
Expand All @@ -715,6 +731,7 @@ public void tableHeaderCell_()
*/
private void endTableCell()
{
tableCellFlag = false;
buffer.append( TABLE_CELL_SEPARATOR_MARKUP );
cellCount++;
}
Expand Down Expand Up @@ -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 ) );
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit d65da7e

Please sign in to comment.