Search in sources :

Example 11 with TextCollectingVisitor

use of com.vladsch.flexmark.ast.util.TextCollectingVisitor 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)

Example 12 with TextCollectingVisitor

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

the class YouTrackConverterNodeRenderer method render.

private void render(Image node, NodeRendererContext context, HtmlWriter html) {
    if (!context.isDoNotRenderLinks()) {
        String altText = new TextCollectingVisitor().collectAndGetText(node);
        ResolvedLink resolvedLink = context.resolveLink(LinkType.IMAGE, node.getUrl().unescape(), null);
        html.raw("!").raw(resolvedLink.getUrl()).raw("!");
    }
}
Also used : TextCollectingVisitor(com.vladsch.flexmark.ast.util.TextCollectingVisitor)

Example 13 with TextCollectingVisitor

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

the class YouTrackConverterNodeRenderer method render.

private void render(ImageRef node, NodeRendererContext context, HtmlWriter html) {
    if (!node.isDefined()) {
        // empty ref, we treat it as text
        assert !node.isDefined();
        html.text(node.getChars().unescape());
    } else {
        if (!context.isDoNotRenderLinks()) {
            Reference reference = node.getReferenceNode(referenceRepository);
            assert reference != null;
            String altText = new TextCollectingVisitor().collectAndGetText(node);
            ResolvedLink resolvedLink = context.resolveLink(LinkType.IMAGE, reference.getUrl().unescape(), null);
            html.raw("!").raw(resolvedLink.getUrl()).raw("!");
        }
    }
}
Also used : TextCollectingVisitor(com.vladsch.flexmark.ast.util.TextCollectingVisitor)

Aggregations

TextCollectingVisitor (com.vladsch.flexmark.ast.util.TextCollectingVisitor)13 Node (com.vladsch.flexmark.ast.Node)3 Attributes (com.vladsch.flexmark.util.html.Attributes)3 Heading (com.vladsch.flexmark.ast.Heading)2 EnumRefTextCollectingVisitor (com.vladsch.flexmark.ext.enumerated.reference.internal.EnumRefTextCollectingVisitor)2 ResolvedLink (com.vladsch.flexmark.html.renderer.ResolvedLink)2 Block (com.vladsch.flexmark.ast.Block)1 WikiLink (com.vladsch.flexmark.ext.wikilink.WikiLink)1 WikiNode (com.vladsch.flexmark.ext.wikilink.WikiNode)1 Parser (com.vladsch.flexmark.parser.Parser)1 AstCollectingVisitor (com.vladsch.flexmark.test.AstCollectingVisitor)1 DataHolder (com.vladsch.flexmark.util.options.DataHolder)1 MutableDataSet (com.vladsch.flexmark.util.options.MutableDataSet)1 BasedSequence (com.vladsch.flexmark.util.sequence.BasedSequence)1 Test (org.junit.Test)1