Search in sources :

Example 6 with DataHolder

use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.

the class ComboAppHtmlAttributeParserTest method assertRendering.

// reverse source and html
@Override
protected void assertRendering(String source, String expectedHtml, String optionsSet) {
    DataHolder options = optionsSet == null ? null : getOptions(example(), optionsSet);
    String parseSource = expectedHtml;
    if (options != null && options.get(NO_FILE_EOL)) {
        parseSource = DumpSpecReader.trimTrailingEOL(parseSource);
    }
    Node node = parser().withOptions(options).parse(parseSource);
    String renderedResult = renderer().withOptions(options).render(node);
    String expectedResult = source;
    actualSource(renderedResult, 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, expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        expected = outExpected.toString();
        StringBuilder outActual = new StringBuilder();
        DumpSpecReader.addSpecExample(outActual, useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        actual = outActual.toString();
    } else {
        expected = DumpSpecReader.addSpecExample(expectedResult, expectedHtml, "", optionsSet);
        actual = DumpSpecReader.addSpecExample(useActualHtml ? renderedResult : expectedResult, 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 7 with DataHolder

use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.

the class ComboHtmlAttributeParserIssueTest method assertRendering.

// reverse source and html
@Override
protected void assertRendering(String source, String expectedHtml, String optionsSet) {
    DataHolder options = optionsSet == null ? null : getOptions(example(), optionsSet);
    String parseSource = expectedHtml;
    if (options != null && options.get(NO_FILE_EOL)) {
        parseSource = DumpSpecReader.trimTrailingEOL(parseSource);
    }
    Node node = parser().withOptions(options).parse(parseSource);
    String renderedResult = renderer().withOptions(options).render(node);
    String expectedResult = source;
    actualSource(renderedResult, 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, expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        expected = outExpected.toString();
        StringBuilder outActual = new StringBuilder();
        DumpSpecReader.addSpecExample(outActual, useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        actual = outActual.toString();
    } else {
        expected = DumpSpecReader.addSpecExample(expectedResult, expectedHtml, "", optionsSet);
        actual = DumpSpecReader.addSpecExample(useActualHtml ? renderedResult : expectedResult, 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 8 with DataHolder

use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.

the class ComboHtmlParserIssueTest method assertRendering.

// reverse source and html
@Override
protected void assertRendering(String source, String expectedHtml, String optionsSet) {
    DataHolder options = optionsSet == null ? null : getOptions(example(), optionsSet);
    String parseSource = expectedHtml;
    if (options != null && options.get(NO_FILE_EOL)) {
        parseSource = DumpSpecReader.trimTrailingEOL(parseSource);
    }
    Node node = parser().withOptions(options).parse(parseSource);
    String renderedResult = renderer().withOptions(options).render(node);
    String expectedResult = source;
    actualSource(renderedResult, 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, expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        expected = outExpected.toString();
        StringBuilder outActual = new StringBuilder();
        DumpSpecReader.addSpecExample(outActual, useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
        actual = outActual.toString();
    } else {
        expected = DumpSpecReader.addSpecExample(expectedResult, expectedHtml, "", optionsSet);
        actual = DumpSpecReader.addSpecExample(useActualHtml ? renderedResult : expectedResult, 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 9 with DataHolder

use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.

the class CustomContextDataSample method main.

public static void main(String[] args) {
    final DataHolder options = PegdownOptionsAdapter.flexmarkOptions(Extensions.ALL, CustomExtension.create());
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    String markdown = "";
    XhtmlContent xhtmlContent = null;
    // You can re-use parser and renderer instances
    Document document = (Document) parser.parse(markdown);
    document.set(XHTML_CONTENT, xhtmlContent);
    // "<p>This is <em>Sparta</em></p>\n"
    String html = renderer.render(document);
    System.out.println(html);
}
Also used : DataHolder(com.vladsch.flexmark.util.options.DataHolder) MutableDataHolder(com.vladsch.flexmark.util.options.MutableDataHolder) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Document(com.vladsch.flexmark.ast.Document) Parser(com.vladsch.flexmark.parser.Parser)

Example 10 with DataHolder

use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.

the class TextCollectingVisitorTest method test_basic.

@Test
public void test_basic() {
    DataHolder options = new MutableDataSet().set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create()));
    Parser parser = Parser.builder(options).build();
    String markdown = "| First Header  | Second Header |\n" + "| ------------- | ------------- |\n" + "| Content Cell  | Content Cell  |\n" + "\n" + "| Left-aligned | Center-aligned | Right-aligned |\n" + "| :---         |     :---:      |          ---: |\n" + "| git status   | git status     | git status    |\n" + "| git diff     | git diff       | git diff      |\n" + "";
    Node document = parser.parse(markdown);
    TextCollectingVisitor collectingVisitor = new TextCollectingVisitor();
    final String text = collectingVisitor.collectAndGetText(document);
    System.out.println(text);
    final String astText = new AstCollectingVisitor().collectAndGetAstText(document);
    System.out.println(astText);
}
Also used : TextCollectingVisitor(com.vladsch.flexmark.ast.util.TextCollectingVisitor) DataHolder(com.vladsch.flexmark.util.options.DataHolder) AstCollectingVisitor(com.vladsch.flexmark.test.AstCollectingVisitor) Node(com.vladsch.flexmark.ast.Node) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Aggregations

DataHolder (com.vladsch.flexmark.util.options.DataHolder)13 Node (com.vladsch.flexmark.ast.Node)11 Parser (com.vladsch.flexmark.parser.Parser)2 MutableDataSet (com.vladsch.flexmark.util.options.MutableDataSet)2 Document (com.vladsch.flexmark.ast.Document)1 TextCollectingVisitor (com.vladsch.flexmark.ast.util.TextCollectingVisitor)1 HtmlRenderer (com.vladsch.flexmark.html.HtmlRenderer)1 AstCollectingVisitor (com.vladsch.flexmark.test.AstCollectingVisitor)1 MutableDataHolder (com.vladsch.flexmark.util.options.MutableDataHolder)1 AssumptionViolatedException (org.junit.AssumptionViolatedException)1 ComparisonFailure (org.junit.ComparisonFailure)1 Test (org.junit.Test)1