Java Code Examples for org.commonmark.node.Node#getFirstChild()

The following examples show how to use org.commonmark.node.Node#getFirstChild() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MentionNodeRenderer.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
private void renderChildren(Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        Node next = node.getNext();
        context.render(node);
        node = next;
    }
}
 
Example 2
Source File: CommonmarkSourcePositions.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Range get(Node node) {
	Range range = positionsMap.get(node);
	if (range == null && node.getFirstChild() != null) {
		// use startOffset of first child and endOffset of last child
		Range firstRange = get(node.getFirstChild());
		Range lastRange = get(node.getLastChild());
		if (firstRange != null && lastRange != null) {
			range = new Range(firstRange.start, lastRange.end);
			positionsMap.put(node, range);
		}
	}
	return range;
}
 
Example 3
Source File: CommonmarkPreviewRenderer.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void printNode(StringBuilder buf, String indent, Node node) {
	buf.append(indent).append(node.getClass().getSimpleName()).append('[');
	Range range = toSourcePositions().get(node);
	if (range != null)
		buf.append(range.start).append(", ").append(range.end);
	buf.append("]");
	printAttributes(buf, node);
	buf.append('\n');

	indent += "    ";
	for (Node child = node.getFirstChild(); child != null; child = child.getNext())
		printNode(buf, indent, child);
}
 
Example 4
Source File: TableTextContentNodeRenderer.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderChildren(Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        Node next = node.getNext();

        // For last cell in row, we dont render the delimiter.
        if (node instanceof TableCell && next == null) {
            renderLastCell((TableCell) node);
        } else {
            context.render(node);
        }

        node = next;
    }
}
 
Example 5
Source File: TableHtmlNodeRenderer.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderChildren(Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        Node next = node.getNext();
        context.render(node);
        node = next;
    }
}
 
Example 6
Source File: FencedCodeBlockParserTest.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void backtickInfo() {
    Node document = PARSER.parse("```info ~ test\ncode\n```");
    FencedCodeBlock codeBlock = (FencedCodeBlock) document.getFirstChild();
    assertEquals("info ~ test", codeBlock.getInfo());
    assertEquals("code\n", codeBlock.getLiteral());
}
 
Example 7
Source File: Nodes.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static List<Node> getChildren(Node parent) {
    List<Node> children = new ArrayList<>();
    for (Node child = parent.getFirstChild(); child != null; child = child.getNext()) {
        children.add(child);
    }
    return children;
}
 
Example 8
Source File: SpecBenchmark.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static long parse(List<String> examples) {
    long length = 0;
    for (String example : examples) {
        Node document = PARSER.parse(example);
        length += document.getFirstChild() == document.getLastChild() ? 0 : 1;
    }
    return length;
}
 
Example 9
Source File: TaskListItemHtmlNodeRenderer.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderChildren(Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        Node next = node.getNext();
        context.render(node);
        node = next;
    }
}
 
Example 10
Source File: InsTextContentNodeRenderer.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderChildren(Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        Node next = node.getNext();
        context.render(node);
        node = next;
    }
}
 
Example 11
Source File: InsHtmlNodeRenderer.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderChildren(Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        Node next = node.getNext();
        context.render(node);
        node = next;
    }
}
 
Example 12
Source File: StrikethroughTextContentNodeRenderer.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderChildren(Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        Node next = node.getNext();
        context.render(node);
        node = next;
    }
}
 
Example 13
Source File: StrikethroughHtmlNodeRenderer.java    From commonmark-java with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderChildren(Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        Node next = node.getNext();
        context.render(node);
        node = next;
    }
}
 
Example 14
Source File: InlineParserUtils.java    From Markwon with Apache License 2.0 5 votes vote down vote up
public static void mergeChildTextNodes(Node node) {
    // No children or just one child node, no need for merging
    if (node.getFirstChild() == node.getLastChild()) {
        return;
    }

    mergeTextNodesInclusive(node.getFirstChild(), node.getLastChild());
}
 
Example 15
Source File: MarkwonVisitorImpl.java    From Markwon with Apache License 2.0 5 votes vote down vote up
@Override
public void visitChildren(@NonNull Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        // A subclass of this visitor might modify the node, resulting in getNext returning a different node or no
        // node after visiting it. So get the next node before visiting.
        Node next = node.getNext();
        node.accept(this);
        node = next;
    }
}
 
Example 16
Source File: MarkwonReducer.java    From Markwon with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public List<Node> reduce(@NonNull Node root) {

    final List<Node> list;

    // we will extract all blocks that are direct children of Document
    Node node = root.getFirstChild();

    // please note, that if there are no children -> we will return a list with
    // single element (which was supplied)
    if (node == null) {
        list = Collections.singletonList(root);
    } else {

        list = new ArrayList<>();

        Node temp;

        while (node != null) {
            list.add(node);
            temp = node.getNext();
            node.unlink();
            node = temp;
        }
    }

    return list;
}
 
Example 17
Source File: DumpNodes.java    From Markwon with Apache License 2.0 5 votes vote down vote up
private static void visitChildren(@NonNull Visitor visitor, @NonNull Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        // A subclass of this visitor might modify the node, resulting in getNext returning a different node or no
        // node after visiting it. So get the next node before visiting.
        Node next = node.getNext();
        node.accept(visitor);
        node = next;
    }
}
 
Example 18
Source File: EmojiNodeRenderer.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
private void renderChildren(Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
        Node next = node.getNext();
        context.render(node);
        node = next;
    }
}
 
Example 19
Source File: TableBlockHtmlRenderer.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
private void renderChildren(Node node) {
  for (Node child = node.getFirstChild(); child != null; child = child.getNext()) {
    context.render(child);
  }
}