Skip to content

Commit

Permalink
Fix rendering empty tables
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero committed Oct 20, 2024
1 parent b19a53a commit 802a190
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ public void process(StructuralNode node) {
final Sink sink = getSink();
sink.table();
sink.tableRows(new int[]{JUSTIFY_LEFT}, false);
List<Row> header = tableNode.getHeader();
final List<Row> header = tableNode.getHeader();
final List<Row> rows = tableNode.getBody();

if (header.isEmpty() && rows.isEmpty()) {
return;
}

if (!header.isEmpty()) {
sink.tableRow();

Expand All @@ -58,7 +64,7 @@ public void process(StructuralNode node) {
sink.tableRow_();
}

for (Row row : tableNode.getBody()) {
for (Row row : rows) {
sink.tableRow();
for (Cell cell : row.getCells()) {
sink.tableCell();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ class TableNodeProcessorTest {
private NodeProcessor nodeProcessor;
private StringWriter sinkWriter;

@Test
void should_convert_empty_table() {
String content = "= Document tile\n" +
"\n" +
"\n" +
"== Section\n" +
"|===\n" +
"|===";

String html = process(content);

// Header for now is just first row with class=a
assertThat(html)
.isEmpty();
}

@Test
void should_convert_table_with_header() {
String content = documentWithTable(true, noCaption, emptyList());
Expand Down

0 comments on commit 802a190

Please sign in to comment.