Search in sources :

Example 1 with MutableDataSet

use of com.vladsch.flexmark.util.data.MutableDataSet in project configuration-as-code-plugin by jenkinsci.

the class JenkinsConfiguredWithReadmeRule method transformFencedCodeBlockFromMarkdownToString.

private List<String> transformFencedCodeBlockFromMarkdownToString(InputStream markdownContent) throws IOException {
    ArrayList<String> results = new ArrayList<>();
    final MutableDataSet FORMAT_OPTIONS = new MutableDataSet();
    FORMAT_OPTIONS.set(Parser.EXTENSIONS, OPTIONS.get(Parser.EXTENSIONS));
    Reader targetReader = new InputStreamReader(markdownContent);
    Node document = PARSER.parseReader(targetReader);
    TextCollectingVisitor textCollectingVisitor = new TextCollectingVisitor();
    Node fencedCodeBlock = document.getChildOfType(FencedCodeBlock.class);
    while (fencedCodeBlock != null) {
        results.add(textCollectingVisitor.collectAndGetText(fencedCodeBlock));
        fencedCodeBlock = fencedCodeBlock.getNextAny(FencedCodeBlock.class);
    }
    return results;
}
Also used : TextCollectingVisitor(com.vladsch.flexmark.ast.util.TextCollectingVisitor) InputStreamReader(java.io.InputStreamReader) Node(com.vladsch.flexmark.util.ast.Node) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) MutableDataSet(com.vladsch.flexmark.util.data.MutableDataSet) FencedCodeBlock(com.vladsch.flexmark.ast.FencedCodeBlock)

Aggregations

FencedCodeBlock (com.vladsch.flexmark.ast.FencedCodeBlock)1 TextCollectingVisitor (com.vladsch.flexmark.ast.util.TextCollectingVisitor)1 Node (com.vladsch.flexmark.util.ast.Node)1 MutableDataSet (com.vladsch.flexmark.util.data.MutableDataSet)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1