Search in sources :

Example 16 with Node

use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.

the class TitleExtract method findTitle.

private static 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.ast.Node) Block(com.vladsch.flexmark.ast.Block)

Example 17 with Node

use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.

the class DumpSpecReader method addSpecExample.

@Override
protected void addSpecExample(SpecExample example) {
    DataHolder options;
    boolean ignoredCase = false;
    try {
        options = testCase.getOptions(example, example.getOptionsSet());
    } catch (AssumptionViolatedException ignored) {
        ignoredCase = true;
        options = null;
    }
    if (options != null && options.get(FAIL)) {
        ignoredCase = true;
    }
    String parseSource = example.getSource();
    if (options != null && options.get(RenderingTestCase.NO_FILE_EOL)) {
        parseSource = trimTrailingEOL(parseSource);
    }
    Node node = testCase.parser().withOptions(options).parse(parseSource);
    final String actualHTML = testCase.renderer().withOptions(options).render(node);
    final String actualAST = testCase.ast(node);
    String html = !ignoredCase && testCase.useActualHtml() ? actualHTML : example.getHtml();
    String ast = example.getAst() == null ? null : (!ignoredCase ? actualAST : example.getAst());
    // allow other formats to accumulate
    testCase.addSpecExample(example, node, options, ignoredCase, actualHTML, actualAST);
    // include source so that diff can be used to update spec
    addSpecExample(sb, example.getSource(), html, ast, example.getOptionsSet(), testCase.includeExampleCoords(), example.getSection(), example.getExampleNumber());
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) DataHolder(com.vladsch.flexmark.util.options.DataHolder) Node(com.vladsch.flexmark.ast.Node)

Example 18 with Node

use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.

the class RenderingTestCase method assertRendering.

protected void assertRendering(String source, String expectedHtml, String optionsSet) {
    DataHolder options = optionsSet == null ? null : getOptions(example(), optionsSet);
    String parseSource = source;
    if (options != null && options.get(NO_FILE_EOL)) {
        parseSource = DumpSpecReader.trimTrailingEOL(parseSource);
    }
    Node node = parser().withOptions(options).parse(parseSource);
    String html = renderer().withOptions(options).render(node);
    testCase(node, options);
    actualHtml(html, optionsSet);
    boolean useActualHtml = useActualHtml();
    // include source for better assertion errors
    String expected;
    String actual;
    if (example() != null && example().getSection() != null) {
        StringBuilder outExpected = new StringBuilder();
        DumpSpecReader.addSpecExample(outExpected, source, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        expected = outExpected.toString();
        StringBuilder outActual = new StringBuilder();
        DumpSpecReader.addSpecExample(outActual, source, useActualHtml ? html : expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        actual = outActual.toString();
    } else {
        expected = DumpSpecReader.addSpecExample(source, expectedHtml, "", optionsSet);
        actual = DumpSpecReader.addSpecExample(source, useActualHtml ? html : expectedHtml, "", optionsSet);
    }
    specExample(expected, actual, optionsSet);
    if (options != null && options.get(FAIL)) {
        thrown.expect(ComparisonFailure.class);
    }
    assertEquals(expected, actual);
}
Also used : DataHolder(com.vladsch.flexmark.util.options.DataHolder) Node(com.vladsch.flexmark.ast.Node)

Example 19 with Node

use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.

the class NodeCollectingVisitor method visitChildren.

private void visitChildren(final Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        // A subclass of this visitor might modify the node, resulting in getNext returning a different node or no
        // node after visiting it. So get the next node before visiting.
        Node next = node.getNext();
        visit(node);
        node = next;
    }
}
Also used : Node(com.vladsch.flexmark.ast.Node)

Example 20 with Node

use of com.vladsch.flexmark.ast.Node in project flexmark-java by vsch.

the class TextNodeConverter method insertMergedBefore.

// insert and clear list
public void insertMergedBefore(Node sibling) {
    mergeList();
    for (Node node : list) {
        sibling.insertBefore(node);
    }
    clear();
}
Also used : Node(com.vladsch.flexmark.ast.Node)

Aggregations

Node (com.vladsch.flexmark.ast.Node)87 Parser (com.vladsch.flexmark.parser.Parser)29 HtmlRenderer (com.vladsch.flexmark.html.HtmlRenderer)21 Test (org.junit.Test)19 MutableDataSet (com.vladsch.flexmark.util.options.MutableDataSet)14 DataHolder (com.vladsch.flexmark.util.options.DataHolder)11 List (java.util.List)8 BasedSequence (com.vladsch.flexmark.util.sequence.BasedSequence)6 MutableDataHolder (com.vladsch.flexmark.util.options.MutableDataHolder)5 Text (com.vladsch.flexmark.ast.Text)3 TextCollectingVisitor (com.vladsch.flexmark.ast.util.TextCollectingVisitor)3 Extension (com.vladsch.flexmark.Extension)2 Block (com.vladsch.flexmark.ast.Block)2 CustomNode (com.vladsch.flexmark.ast.CustomNode)2 Document (com.vladsch.flexmark.ast.Document)2 Heading (com.vladsch.flexmark.ast.Heading)2 DocxRenderer (com.vladsch.flexmark.docx.converter.internal.DocxRenderer)2 MacroClose (com.vladsch.flexmark.ext.xwiki.macros.MacroClose)2 AstCollectingVisitor (com.vladsch.flexmark.test.AstCollectingVisitor)2 Attributes (com.vladsch.flexmark.util.html.Attributes)2