All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vladsch.flexmark.ast.util.HeadingCollectingVisitor Maven / Gradle / Ivy

Go to download

Core of flexmark-java (implementation of CommonMark for parsing markdown and rendering to HTML)

The newest version!
package com.vladsch.flexmark.ast.util;

import com.vladsch.flexmark.ast.Heading;
import com.vladsch.flexmark.util.ast.BlockNodeVisitor;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.ast.NodeVisitor;
import com.vladsch.flexmark.util.ast.VisitHandler;

import java.util.ArrayList;

public class HeadingCollectingVisitor {
    final private ArrayList headings = new ArrayList<>();
    final private NodeVisitor myVisitor;

    public HeadingCollectingVisitor() {
        myVisitor = new BlockNodeVisitor(
                new VisitHandler<>(Heading.class, headings::add)
        );
    }

    public void collect(Node node) {
        myVisitor.visit(node);
    }

    public ArrayList collectAndGetHeadings(Node node) {
        myVisitor.visit(node);
        return headings;
    }

    public ArrayList getHeadings() {
        return headings;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy