protected void visitChildren(SuperNode node) { for (Node child : node.getChildren()) { child.accept(this); } }
protected void visitChildrenSkipFirst(SuperNode node) { boolean first = true; for (Node child : node.getChildren()) { if (!first) child.accept(this); first = false; } }
boolean fixFirstItem(SuperNode listNode) { List<Node> items = listNode.getChildren(); if (items.size() == 1 && items.get(0) instanceof ListItemNode) { wrapFirstItemInPara((SuperNode) items.get(0)); } return true; }
/** * This method checks if current position is a legal start position for a * strong or emph sequence by checking the last parsed character(-sequence). */ protected boolean isLegalEmphOrStrongStartPos(){ if( currentIndex() == 0 ) return true; Object lastItem = peek(1); Class<?> lastClass = lastItem.getClass(); SuperNode supernode; while( SuperNode.class.isAssignableFrom(lastClass) ) { supernode = (SuperNode) lastItem; if(supernode.getChildren().size() < 1 ) return true; lastItem = supernode.getChildren().get( supernode.getChildren().size()-1 ); lastClass = lastItem.getClass(); } return ( TextNode.class.equals(lastClass) && ( (TextNode) lastItem).getText().endsWith(" ") ) || ( SimpleNode.class.equals(lastClass) ) || ( java.lang.Integer.class.equals(lastClass) ); }
SuperNode wrapFirstSubItemInPara(SuperNode item) { Node firstItemFirstChild = item.getChildren().get(0); if (firstItemFirstChild.getChildren().size() == 1) { Node firstGrandChild = firstItemFirstChild.getChildren().get(0); if (firstGrandChild instanceof ListItemNode) { wrapFirstItemInPara((SuperNode)firstGrandChild); } } return item; }
public void collectChildrensText(SuperNode node, AnchorNodeInfo nodeInfo) { for (Node child : node.getChildren()) { // accumulate all the text if (child.getClass() == TextNode.class || child.getClass() == SpecialTextNode.class) { nodeInfo.text.append(((TextNode) child).getText()); if (nodeInfo.startIndex == 0) { nodeInfo.startIndex = child.getStartIndex(); } nodeInfo.endIndex = child.getEndIndex(); } else if (child instanceof SuperNode) { collectChildrensText((SuperNode) child, nodeInfo); } } }
public boolean addAsChild() { SuperNode parent = (SuperNode) peek(1); List<Node> children = parent.getChildren(); Node child = popAsNode(); if (child.getClass() == TextNode.class && !children.isEmpty()) { Node lastChild = children.get(children.size() - 1); if (lastChild.getClass() == TextNode.class) { // collapse peer TextNodes TextNode last = (TextNode) lastChild; TextNode current = (TextNode) child; last.append(current.getText()); last.setEndIndex(current.getEndIndex()); return true; } } children.add(child); return true; }
boolean setListItemIndices() { SuperNode listItem = (SuperNode) getContext().getValueStack().peek(); List<Node> children = listItem.getChildren(); listItem.setStartIndex(children.get(0).getStartIndex()); listItem.setEndIndex(children.get(children.size() - 1).getEndIndex()); return true; }
boolean wrapFirstItemInPara(SuperNode item) { Node firstItemFirstChild = item.getChildren().get(0); ParaNode paraNode = new ParaNode(firstItemFirstChild.getChildren()); paraNode.setStartIndex(firstItemFirstChild.getStartIndex()); paraNode.setEndIndex(firstItemFirstChild.getEndIndex()); // vsch: wrap the para in RootNode so that it is identical to the rest of the list items if they are loose, otherwise it creates differences in html serialization of task items RootNode rootNode = new RootNode(); rootNode.setStartIndex(paraNode.getStartIndex()); rootNode.setEndIndex(paraNode.getEndIndex()); rootNode.getChildren().add(paraNode); item.getChildren().set(0, rootNode); return true; }
public boolean wrapInAnchor() { if (ext(ANCHORLINKS | EXTANCHORLINKS)) { SuperNode node = (SuperNode) peek(); List<Node> children = node.getChildren(); if (ext(EXTANCHORLINKS)) { if (children.size() > 0) { AnchorNodeInfo nodeInfo = new AnchorNodeInfo(); collectChildrensText(node, nodeInfo); String text = nodeInfo.text.toString().trim(); if (text.length() > 0) { AnchorLinkNode anchor = new AnchorLinkNode(text, ""); anchor.setStartIndex(nodeInfo.startIndex); anchor.setEndIndex(nodeInfo.endIndex); children.add(0, anchor); } } } else { if (children.size() == 1) { Node child = children.get(0); if (child instanceof TextNode) { AnchorLinkNode anchor = new AnchorLinkNode(((TextNode) child).getText()); anchor.setStartIndex(child.getStartIndex()); anchor.setEndIndex(child.getEndIndex()); children.set(0, anchor); } } } } return true; }
protected void printConditionallyIndentedTag(SuperNode node, String tag) { if (node.getChildren().size() > 1) { printer.println().print('<').print(tag).print('>').indent(+2); visitChildren(node); printer.indent(-2).println().print('<').print('/').print(tag).print('>'); } else { boolean startWasNewLine = printer.endsWithNewLine(); printer.println().print('<').print(tag).print('>'); visitChildren(node); printer.print('<').print('/').print(tag).print('>').printchkln(startWasNewLine); } }
public Rule DefinitionList() { return NodeSequence( // test for successful definition list match before actually building it to reduce backtracking TestNot(Spacechar()), Test( OneOrMore(TestNot(BlankLine()), TestNot(DefListBullet()), OneOrMore(NotNewline(), ANY), Newline()), ZeroOrMore(BlankLine()), DefListBullet() ), push(new DefinitionListNode()), OneOrMore( push(new SuperNode()), OneOrMore(DefListTerm(), addAsChild()), OneOrMore(Definition(), addAsChild()), ((SuperNode)peek(1)).getChildren().addAll(popAsNode().getChildren()), Optional(BlankLine()) ) ); }
protected void visitChildren(SuperNode node) { for (Node child : node.getChildren()) { child.accept(this); } }