Skip to content

Commit 8c3cc52

Browse files
committed
Improve support for table headers
1 parent 51994c8 commit 8c3cc52

File tree

5 files changed

+15
-26
lines changed

5 files changed

+15
-26
lines changed

log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciidocTreeVisitor.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ public Void visitEndElement(final EndElementTree node, final AsciidocData data)
155155
case "ul":
156156
case "li":
157157
case "table":
158-
case "th":
159158
case "td":
160159
data.popNode();
161160
break;
161+
case "th":
162+
data.popNode().setContext(CellImpl.HEADER_CONTEXT);
163+
break;
162164
case "h1":
163165
case "h2":
164166
case "h3":
@@ -205,26 +207,17 @@ public Void visitEndElement(final EndElementTree node, final AsciidocData data)
205207
final java.util.List<StructuralNode> cells = table.getBlocks();
206208
// First index of the row
207209
int idx = 0;
208-
for (final Row row : table.getHeader()) {
209-
idx += row.getCells().size();
210-
}
211210
for (final Row row : table.getBody()) {
212211
idx += row.getCells().size();
213212
}
214213
final Row row = new RowImpl();
215-
String context = CellImpl.BODY_CONTEXT;
216214
for (int i = idx; i < table.getBlocks().size(); i++) {
217215
final StructuralNode cell = cells.get(i);
218-
context = cell.getContext();
219216
if (cell instanceof Cell) {
220217
row.getCells().add((Cell) cell);
221218
}
222219
}
223-
if (CellImpl.HEADER_CONTEXT.equals(context)) {
224-
table.getHeader().add(row);
225-
} else {
226-
table.getBody().add(row);
227-
}
220+
table.getBody().add(row);
228221
break;
229222
case "code":
230223
appendSpan(data, CODE_DELIM);

log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AsciidocData.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public StructuralNode pushChildNode(final Function<? super StructuralNode, ? ext
179179
return currentNode = child;
180180
}
181181

182-
public void popNode() {
182+
public StructuralNode popNode() {
183183
final StructuralNode currentNode = this.currentNode;
184184

185185
final StructuralNode parent = (StructuralNode) currentNode.getParent();
@@ -190,5 +190,6 @@ public void popNode() {
190190
newParagraph(parent);
191191

192192
this.currentNode = parent;
193+
return currentNode;
193194
}
194195
}

log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/internal/CellImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public CellImpl(final ContentNode parent) {
3737
public void formatTo(final StringBuilder buffer) {
3838
if (getBlocks().size() > 1) {
3939
buffer.append('a');
40+
} else if (HEADER_CONTEXT.equals(getContext())) {
41+
buffer.append('h');
4042
}
4143
buffer.append("| ");
4244
getBlocks().forEach(node -> {

log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/internal/TableImpl.java

+6-13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
public final class TableImpl extends StructuralNodeImpl implements Table {
2828

29-
private final List<Row> header = new ArrayList<>();
3029
private final List<Row> body = new ArrayList<>();
3130

3231
public TableImpl(final ContentNode parent) {
@@ -35,17 +34,11 @@ public TableImpl(final ContentNode parent) {
3534

3635
@Override
3736
public void formatTo(final StringBuilder buffer) {
38-
final int colCount = header.isEmpty()
39-
? body.isEmpty() ? 1 : body.get(0).getCells().size()
40-
: header.get(0).getCells().size();
37+
final int colCount = body.isEmpty() ? 1 : body.get(0).getCells().size();
4138

4239
buffer.append("[cols=\"");
4340
formatColSpecifier(colCount, buffer);
44-
if (!header.isEmpty()) {
45-
buffer.append("\",options=\"headers");
46-
}
4741
buffer.append("\"]\n").append("|===\n");
48-
getHeader().forEach(row -> formatRow(row, buffer));
4942
getBody().forEach(row -> formatRow(row, buffer));
5043
buffer.append("\n|===\n");
5144
}
@@ -70,11 +63,6 @@ private void formatRow(final Row row, final StringBuilder buffer) {
7063
});
7164
}
7265

73-
@Override
74-
public List<Row> getHeader() {
75-
return header;
76-
}
77-
7866
@Override
7967
public List<Row> getBody() {
8068
return body;
@@ -83,6 +71,11 @@ public List<Row> getBody() {
8371
//
8472
// All methods below this line are not implemented.
8573
//
74+
@Override
75+
public List<Row> getHeader() {
76+
throw new UnsupportedOperationException();
77+
}
78+
8679
@Override
8780
public List<Row> getFooter() {
8881
throw new UnsupportedOperationException();

log4j-docgen/src/test/resources/expected/processor/JavadocExample.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Sed varius justo eget congue lacinia.
8888
8989
== First section
9090
91-
[cols="1,1",options="headers"]
91+
[cols="1,1"]
9292
|===
9393
9494
h| Key

0 commit comments

Comments
 (0)