Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOXIA-497] Fix rendering links and paragraphs inside tables #13

Merged
merged 1 commit into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}