in log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/AbstractAsciiDocTreeVisitor.java [135:228]
public Void visitEndElement(final EndElementTree node, final AsciiDocData data) {
final String elementName = node.getName().toString();
switch (elementName) {
case "p":
// Ignore closing tags.
break;
case "ol":
case "ul":
case "li":
case "table":
case "td":
case "th":
data.popNode();
break;
case "h1":
case "h2":
case "h3":
case "h4":
case "h5":
case "h6":
// Only flush the current line
if (!isEmpty(data.getCurrentLine())) {
data.newLine();
}
// The current paragraph contains the title
// We retrieve the text and empty the paragraph
final Block currentParagraph = data.getCurrentParagraph();
final String title = StringUtils.normalizeSpace(currentParagraph.convert());
currentParagraph.setLines(new ArrayList<>());
// There should be no <h1> tags
final int newLevel = "h1".equals(elementName) ? 2 : elementName.charAt(1) - '0';
data.setCurrentSectionLevel(newLevel);
data.getCurrentNode().setTitle(title);
break;
case "pre":
final Block codeBlock = data.newParagraph();
final java.util.List<String> lines = codeBlock.getLines();
// Trim common indentation and detect language
int commonIndentSize = Integer.MAX_VALUE;
for (final String line : lines) {
final int firstNotSpace = StringUtils.indexOfAnyBut(line, SPACE);
if (0 <= firstNotSpace && firstNotSpace < commonIndentSize) {
commonIndentSize = firstNotSpace;
}
}
final boolean isXml = XML_TAG.matcher(String.join(SPACE, lines)).find();
final java.util.List<String> newLines = new ArrayList<>(lines.size());
for (final String line : lines) {
newLines.add(StringUtils.substring(line, commonIndentSize));
}
codeBlock.setLines(newLines);
codeBlock.setStyle(isXml ? XML_SOURCE_STYLE : JAVA_SOURCE_STYLE);
break;
case "tr":
// We group the new cells into a row
final Table table = (Table) data.getCurrentNode();
final java.util.List<StructuralNode> cells = table.getBlocks();
// First index of the row
int idx = 0;
for (final Row row : table.getBody()) {
idx += row.getCells().size();
}
final Row row = new RowImpl();
// 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);
break;
case "code":
appendSpan(data, CODE_DELIM);
break;
case "em":
case "i":
appendSpan(data, EMPHASIS_DELIM);
break;
case "strong":
case "b":
appendSpan(data, STRONG_EMPHASIS_DELIM);
break;
case "caption":
data.getCurrentNode().setTitle(data.popTextSpan());
break;
default:
}
return super.visitEndElement(node, data);
}