diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciiDocTreeVisitor.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciiDocTreeVisitor.java index b753044a..a6e76aff 100644 --- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciiDocTreeVisitor.java +++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciiDocTreeVisitor.java @@ -123,6 +123,7 @@ public Void visitStartElement(final StartElementTree node, final AsciiDocData da case "i": case "strong": case "b": + case "caption": data.newTextSpan(); break; default: @@ -142,10 +143,8 @@ public Void visitEndElement(final EndElementTree node, final AsciiDocData data) case "li": case "table": case "td": - data.popNode(); - break; case "th": - data.popNode().setContext(CellImpl.HEADER_CONTEXT); + data.popNode(); break; case "h1": case "h2": @@ -197,10 +196,14 @@ public Void visitEndElement(final EndElementTree node, final AsciiDocData data) idx += row.getCells().size(); } final Row row = new RowImpl(); - for (int i = idx; i < table.getBlocks().size(); i++) { + // Add all cells to the row, remove additional elements + for (int i = idx; i < cells.size(); ) { final StructuralNode cell = cells.get(i); if (cell instanceof Cell) { row.getCells().add((Cell) cell); + i++; + } else { + cells.remove(i); } } table.getBody().add(row); @@ -216,6 +219,9 @@ public Void visitEndElement(final EndElementTree node, final AsciiDocData data) case "b": appendSpan(data, STRONG_EMPHASIS_DELIM); break; + case "caption": + data.getCurrentNode().setTitle(data.popTextSpan()); + break; default: } return super.visitEndElement(node, data); diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/internal/TableImpl.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/internal/TableImpl.java index cb4454a2..333bb7b6 100644 --- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/internal/TableImpl.java +++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/internal/TableImpl.java @@ -35,6 +35,10 @@ public TableImpl(final ContentNode parent) { public void formatTo(final StringBuilder buffer) { final int colCount = body.isEmpty() ? 1 : body.get(0).getCells().size(); + final String title = getTitle(); + if (title != null) { + buffer.append(".").append(title).append("\n"); + } buffer.append("[cols=\""); formatColSpecifier(colCount, buffer); buffer.append("\"]\n").append("|===\n"); diff --git a/log4j-docgen/src/test/resources/AsciiDocConverterTest/JavadocExample.adoc b/log4j-docgen/src/test/resources/AsciiDocConverterTest/JavadocExample.adoc index e97c87a9..f79958e6 100644 --- a/log4j-docgen/src/test/resources/AsciiDocConverterTest/JavadocExample.adoc +++ b/log4j-docgen/src/test/resources/AsciiDocConverterTest/JavadocExample.adoc @@ -94,6 +94,7 @@ Sed varius justo eget congue lacinia. == First section +.Caption [cols="1,1"] |=== diff --git a/log4j-docgen/src/test/resources/AsciiDocConverterTest/JavadocExample.java b/log4j-docgen/src/test/resources/AsciiDocConverterTest/JavadocExample.java index b6d99710..cd20465a 100644 --- a/log4j-docgen/src/test/resources/AsciiDocConverterTest/JavadocExample.java +++ b/log4j-docgen/src/test/resources/AsciiDocConverterTest/JavadocExample.java @@ -91,6 +91,7 @@ * *

First section

* + * * * * diff --git a/src/changelog/.0.x.x/add-table-caption.xml b/src/changelog/.0.x.x/add-table-caption.xml new file mode 100644 index 00000000..86abc8d4 --- /dev/null +++ b/src/changelog/.0.x.x/add-table-caption.xml @@ -0,0 +1,7 @@ + + + Add support for table captions to JavaDoc to AsciiDoc converter. +
Caption
KeyValue