Skip to content

Commit

Permalink
Add support for table captions
Browse files Browse the repository at this point in the history
  • Loading branch information
ppkarwasz committed Jun 12, 2024
1 parent e30143e commit 88363b5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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":
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Sed varius justo eget congue lacinia.
== First section
.Caption
[cols="1,1"]
|===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
* </ul>
* <h2>First section</h2>
* <table>
* <caption>Caption</caption>
* <tr>
* <th>Key</th>
* <th>Value</th>
Expand Down
7 changes: 7 additions & 0 deletions src/changelog/.0.x.x/add-table-caption.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://logging.apache.org/xml/ns"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="added">
<description format="asciidoc">Add support for table captions to JavaDoc to AsciiDoc converter.</description>
</entry>

0 comments on commit 88363b5

Please sign in to comment.