Search in sources :

Example 1 with Block

use of com.vladsch.flexmark.util.ast.Block in project gerrit by GerritCodeReview.

the class MarkdownFormatter method findTitle.

private String findTitle(Node root) {
    if (root instanceof Heading) {
        Heading h = (Heading) root;
        if (h.getLevel() == 1 && h.hasChildren()) {
            TextCollectingVisitor collectingVisitor = new TextCollectingVisitor();
            return collectingVisitor.collectAndGetText(h);
        }
    }
    if (root instanceof Block && root.hasChildren()) {
        Node child = root.getFirstChild();
        while (child != null) {
            String title = findTitle(child);
            if (title != null) {
                return title;
            }
            child = child.getNext();
        }
    }
    return null;
}
Also used : TextCollectingVisitor(com.vladsch.flexmark.ast.util.TextCollectingVisitor) Heading(com.vladsch.flexmark.ast.Heading) Node(com.vladsch.flexmark.util.ast.Node) Block(com.vladsch.flexmark.util.ast.Block)

Aggregations

Heading (com.vladsch.flexmark.ast.Heading)1 TextCollectingVisitor (com.vladsch.flexmark.ast.util.TextCollectingVisitor)1 Block (com.vladsch.flexmark.util.ast.Block)1 Node (com.vladsch.flexmark.util.ast.Node)1