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; }
protected void visitChildren(SuperNode node) { for (Node child : node.getChildren()) { child.accept(this); } }
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 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); } } }
protected <T extends Node> void visitChildren(T node) { for (Node child : node.getChildren()) { child.accept(this); } }
int col = 0; int offset = node.getStartIndex();
protected <T extends Node> void visitChildren(T node) { for (Node child : node.getChildren()) { child.accept(this); } }
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; }
int col = 0; int offset = node.getStartIndex();
Node withIndicesShifted(Node node, int delta) { if (delta != 0) { ((AbstractNode) node).shiftIndices(delta); for (Node subNode : node.getChildren()) { withIndicesShifted(subNode, delta); } } return node; }
protected <T extends Node> void visitChildren(T 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; } }
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; }
int col = 0; int offset = node.getStartIndex();
protected void fixIndices(Node node, int[] ixMap) { ((AbstractNode) node).mapIndices(ixMap); for (Node subNode : node.getChildren()) { fixIndices(subNode, ixMap); } }
public void visit(RootNode node) { for (ReferenceNode refNode : node.getReferences()) { visitChildren(refNode); references.put(normalize(printer.getString()), refNode); printer.clear(); } for (AbbreviationNode abbrNode : node.getAbbreviations()) { visitChildren(abbrNode); String abbr = printer.getString(); printer.clear(); abbrNode.getExpansion().accept(this); String expansion = printer.getString(); abbreviations.put(abbr, expansion); printer.clear(); } visitChildren(node); }
public Rule TableRow() { Var<Boolean> leadingPipe = new Var<Boolean>(Boolean.FALSE); return NodeSequence( push(new TableRowNode()), Optional('|', leadingPipe.set(Boolean.TRUE)), OneOrMore(TableCell(), addAsChild()), leadingPipe.get() || ((Node) peek()).getChildren().size() > 1 || getContext().getInputBuffer().charAt(matchEnd() - 1) == '|', Sp(), Newline() ); }
protected void visitChildren(AbstractNode node) { for (Node child : node.getChildren()) { child.accept(this); } }
public void visit(ListItemNode node) { if (node instanceof TaskListNode) { // vsch: #185 handle GitHub style task list items, these are a bit messy because the <input> checkbox needs to be // included inside the optional <p></p> first grand-child of the list item, first child is always RootNode // because the list item text is recursively parsed. Node firstChild = node.getChildren().get(0).getChildren().get(0); boolean firstIsPara = firstChild instanceof ParaNode; int indent = node.getChildren().size() > 1 ? 2 : 0; boolean startWasNewLine = printer.endsWithNewLine(); printer.println().print("<li class=\"task-list-item\">").indent(indent); if (firstIsPara) { printer.println().print("<p>"); printer.print("<input type=\"checkbox\" class=\"task-list-item-checkbox\"" + (((TaskListNode) node).isDone() ? " checked=\"checked\"" : "") + " disabled=\"disabled\"></input>"); visitChildren((SuperNode) firstChild); // render the other children, the p tag is taken care of here visitChildrenSkipFirst(node); printer.print("</p>"); } else { printer.print("<input type=\"checkbox\" class=\"task-list-item-checkbox\"" + (((TaskListNode) node).isDone() ? " checked=\"checked\"" : "") + " disabled=\"disabled\"></input>"); visitChildren(node); } printer.indent(-indent).printchkln(indent != 0).print("</li>") .printchkln(startWasNewLine); } else { printConditionallyIndentedTag(node, "li"); } }
protected void visitChildren(SuperNode node) { for (Node child : node.getChildren()) { child.accept(this); } }