From 802a190e3165337ded1779c04697276aeed2c77e Mon Sep 17 00:00:00 2001 From: Abel Salgado Romero Date: Sun, 20 Oct 2024 12:07:52 +0200 Subject: [PATCH] Fix rendering empty tables --- .../parser/processors/TableNodeProcessor.java | 10 ++++++++-- .../processors/TableNodeProcessorTest.java | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessor.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessor.java index 9bfbf5f0..4cfbb378 100644 --- a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessor.java +++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessor.java @@ -44,7 +44,13 @@ public void process(StructuralNode node) { final Sink sink = getSink(); sink.table(); sink.tableRows(new int[]{JUSTIFY_LEFT}, false); - List header = tableNode.getHeader(); + final List header = tableNode.getHeader(); + final List rows = tableNode.getBody(); + + if (header.isEmpty() && rows.isEmpty()) { + return; + } + if (!header.isEmpty()) { sink.tableRow(); @@ -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(); diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessorTest.java index 7e7cf496..662bd653 100644 --- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessorTest.java +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessorTest.java @@ -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());