Search in sources :

Example 41 with Node

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

the class TablesTest method attributeProviderIsApplied.

@Test
public void attributeProviderIsApplied() {
    AttributeProviderFactory factory = new IndependentAttributeProviderFactory() {

        @Override
        public AttributeProvider create(LinkResolverContext context) {
            return new AttributeProvider() {

                @Override
                public void setAttributes(Node node, AttributablePart part, Attributes attributes) {
                    if (node instanceof TableBlock) {
                        attributes.replaceValue("test", "block");
                    } else if (node instanceof TableHead) {
                        attributes.replaceValue("test", "head");
                    } else if (node instanceof TableBody) {
                        attributes.replaceValue("test", "body");
                    } else if (node instanceof TableRow) {
                        attributes.replaceValue("test", "row");
                    } else if (node instanceof TableCell) {
                        attributes.replaceValue("test", "cell");
                    }
                }
            };
        }
    };
    HtmlRenderer renderer = HtmlRenderer.builder().attributeProviderFactory(factory).extensions(EXTENSIONS).build();
    String rendered = renderer.render(PARSER.parse("Abc|Def\n---|---\n1|2"));
    assertThat(rendered, is("<table test=\"block\">\n" + "<thead test=\"head\">\n" + "<tr test=\"row\"><th test=\"cell\">Abc</th><th test=\"cell\">Def</th></tr>\n" + "</thead>\n" + "<tbody test=\"body\">\n" + "<tr test=\"row\"><td test=\"cell\">1</td><td test=\"cell\">2</td></tr>\n" + "</tbody>\n" + "</table>\n"));
}
Also used : Node(com.vladsch.flexmark.ast.Node) Attributes(com.vladsch.flexmark.util.html.Attributes) AttributablePart(com.vladsch.flexmark.html.renderer.AttributablePart) AttributeProviderFactory(com.vladsch.flexmark.html.AttributeProviderFactory) IndependentAttributeProviderFactory(com.vladsch.flexmark.html.IndependentAttributeProviderFactory) IndependentAttributeProviderFactory(com.vladsch.flexmark.html.IndependentAttributeProviderFactory) LinkResolverContext(com.vladsch.flexmark.html.renderer.LinkResolverContext) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) AttributeProvider(com.vladsch.flexmark.html.AttributeProvider) Test(org.junit.Test)

Example 42 with Node

use of com.vladsch.flexmark.ast.Node 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 43 with Node

use of com.vladsch.flexmark.ast.Node 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 44 with Node

use of com.vladsch.flexmark.ast.Node 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 45 with Node

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

the class BoundsIntegrationTest method parse.

private void parse(String input) {
    try {
        Node parsed = PARSER.parse(input);
        // Parsing should always return a node
        assertNotNull(parsed);
    } catch (Exception e) {
        throw new AssertionError("Parsing failed, input: " + input, e);
    }
}
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