Search in sources :

Example 71 with Node

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

the class YamlFrontMatterTest method complexValues.

@Test
public void complexValues() {
    final String input = "---" + "\nsimple: value" + "\nliteral: |" + "\n  hello markdown!" + "\n" + "\n  literal literal" + "\nlist:" + "\n    - value1" + "\n    - value2" + "\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(3, data.size());
    assertTrue(data.containsKey("simple"));
    assertEquals(1, data.get("simple").size());
    assertEquals("value", data.get("simple").get(0));
    assertTrue(data.containsKey("literal"));
    assertEquals(1, data.get("literal").size());
    assertEquals("hello markdown!\n\nliteral literal", data.get("literal").get(0));
    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 72 with Node

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

the class YamlFrontMatterTest method literalValue1.

@Test
public void literalValue1() {
    final String input = "---" + "\nliteral: |" + "\n  hello markdown!" + "\n  literal thing..." + "\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!\nliteral thing...", 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 73 with Node

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

the class YouTubeLinkNodePostProcessor method process.

@Override
public void process(NodeTracker state, Node node) {
    if (node instanceof Link) {
        Node previous = node.getPrevious();
        if (previous instanceof Text) {
            final BasedSequence chars = previous.getChars();
            if (chars.endsWith("@") && chars.isContinuedBy(node.getChars())) {
                // trim previous chars to remove '@'
                previous.setChars(chars.subSequence(0, chars.length() - 1));
                YouTubeLink youTubeLink = new YouTubeLink((Link) node);
                youTubeLink.takeChildren(node);
                node.unlink();
                previous.insertAfter(youTubeLink);
                state.nodeRemoved(node);
                state.nodeAddedWithChildren(youTubeLink);
            }
        }
    }
}
Also used : YouTubeLink(com.vladsch.flexmark.ext.youtube.embedded.YouTubeLink) Node(com.vladsch.flexmark.ast.Node) BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence) Text(com.vladsch.flexmark.ast.Text) Link(com.vladsch.flexmark.ast.Link) YouTubeLink(com.vladsch.flexmark.ext.youtube.embedded.YouTubeLink)

Example 74 with Node

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

the class MacroBlockParser method closeBlock.

@Override
public void closeBlock(ParserState state) {
    // first line is macro open and possibly close
    if (oneLine) {
        List<BasedSequence> lines = new ArrayList<BasedSequence>();
        Macro macro = (Macro) block.getFirstChild();
        Node node = block.getLastChild();
        BasedSequence contentLine;
        if (node instanceof MacroClose) {
            contentLine = macro.getChars().baseSubSequence(macro.getEndOffset(), node.getStartOffset());
        } else {
            contentLine = macro.getChars().baseSubSequence(macro.getEndOffset(), macro.getEndOffset());
        }
        lines.add(contentLine);
        block.setContent(lines);
    } else {
        // last line is close, first line is open
        if (hadClose) {
            final List<BasedSequence> lines = content.getLines();
            block.setContent(lines);
        } else {
            final List<BasedSequence> lines = content.getLines();
            block.setContent(lines.subList(0, lines.size()));
        }
    }
    block.setCharsFromContent();
    content = null;
}
Also used : MacroClose(com.vladsch.flexmark.ext.xwiki.macros.MacroClose) Macro(com.vladsch.flexmark.ext.xwiki.macros.Macro) BasedSequence(com.vladsch.flexmark.util.sequence.BasedSequence) Node(com.vladsch.flexmark.ast.Node) ArrayList(java.util.ArrayList)

Example 75 with Node

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

the class MarkdownWriter method tailBlankLine.

public MarkdownWriter tailBlankLine(int count) {
    Node node = context.getCurrentNode();
    if (isLastBlockQuoteChild(node)) {
        if (getPushedPrefixCount() > 0) {
            // clear pending lines so pop prefix is not delayed, if PREFIX_AFTER_PENDING_EOL is enabled
            flush(-1);
            popPrefix();
            pushPrefix();
        }
    }
    blankLine(count);
    return this;
}
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