Search in sources :

Example 66 with Node

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

the class EnumeratedReferenceNodeRenderer method render.

private void render(EnumeratedReferenceLink node, NodeRendererContext context, HtmlWriter html) {
    final String text = node.getText().toString();
    if (text.isEmpty()) {
        // placeholder for ordinal
        html.text(String.valueOf(ordinal));
    } else {
        Node referenceFormat = enumeratedOrdinals.getFormatNode(text);
        int wasOrdinal = ordinal;
        ordinal = enumeratedOrdinals.getOrdinal(text);
        if (referenceFormat != null) {
            String title = new EnumRefTextCollectingVisitor(ordinal).collectAndGetText(referenceFormat);
            html.withAttr().attr("href", "#" + text).attr("title", title).tag("a");
            context.renderChildren(referenceFormat);
            html.tag("/a");
        } else {
            // no format, just output type space ordinal
            final String defaultText = String.format("%s %d", EnumeratedReferences.getType(text), ordinal);
            html.withAttr().attr("href", "#" + text).attr("title", defaultText).tag("a");
            html.text(defaultText);
            html.tag("/a");
        }
        ordinal = wasOrdinal;
    }
}
Also used : Node(com.vladsch.flexmark.ast.Node)

Example 67 with Node

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

the class ComboAutolinkSpecTest method testSpecTxt.

@Test
public void testSpecTxt() throws Exception {
    if (!example.isFullSpecExample())
        return;
    final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build();
    final Parser PARSER = Parser.builder(OPTIONS).build();
    String source = readResource("/spec.txt");
    Node node = PARSER.parse(source);
// String html = readResource("/table.html");
// assertRendering(source, html);
}
Also used : Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Example 68 with Node

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

the class YamlFrontMatterTest method literalValue2.

@Test
public void literalValue2() {
    final String input = "---" + "\nliteral: |" + "\n  - hello markdown!" + "\n---" + "\n" + "\ngreat";
    final String rendered = "<p>great</p>\n";
    AbstractYamlFrontMatterVisitor visitor = new AbstractYamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    visitor.visit(document);
    Map<String, List<String>> data = visitor.getData();
    assertEquals(1, data.size());
    assertTrue(data.containsKey("literal"));
    assertEquals(1, data.get("literal").size());
    assertEquals("- hello markdown!", data.get("literal").get(0));
    assertRendering(input, rendered);
}
Also used : Node(com.vladsch.flexmark.ast.Node) List(java.util.List) Test(org.junit.Test)

Example 69 with Node

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

the class YamlFrontMatterTest method listValues.

@Test
public void listValues() {
    final String input = "---" + "\nlist:" + "\n  - value1" + "\n  - value2" + "\n..." + "\n" + "\ngreat";
    final String rendered = "<p>great</p>\n";
    AbstractYamlFrontMatterVisitor visitor = new AbstractYamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    visitor.visit(document);
    Map<String, List<String>> data = visitor.getData();
    assertEquals(1, data.size());
    assertTrue(data.containsKey("list"));
    assertEquals(2, data.get("list").size());
    assertEquals("value1", data.get("list").get(0));
    assertEquals("value2", data.get("list").get(1));
    assertRendering(input, rendered);
}
Also used : Node(com.vladsch.flexmark.ast.Node) List(java.util.List) Test(org.junit.Test)

Example 70 with Node

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

the class YamlFrontMatterTest method nonMatchedStartTag.

@Test
public void nonMatchedStartTag() {
    final String input = "----\n" + "test";
    final String rendered = "<hr />\n<p>test</p>\n";
    AbstractYamlFrontMatterVisitor visitor = new AbstractYamlFrontMatterVisitor();
    Node document = PARSER.parse(input);
    visitor.visit(document);
    Map<String, List<String>> data = visitor.getData();
    assertTrue(data.isEmpty());
    assertRendering(input, rendered);
}
Also used : Node(com.vladsch.flexmark.ast.Node) List(java.util.List) Test(org.junit.Test)

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