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;
}
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());
}
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);
}
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;
}
}
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();
}
Aggregations