/** * This method checks if the last parsed character or sequence is a valid prefix for a closing char for * an emph or strong sequence. */ protected boolean isLegalEmphOrStrongClosePos(){ Object lastItem = peek(); if ( StrongEmphSuperNode.class.equals( lastItem.getClass() ) ){ List<Node> children = ((StrongEmphSuperNode) lastItem).getChildren(); if(children.size() < 1) return true; lastItem = children.get( children.size()-1 ); Class<?> lastClass = lastItem.getClass(); if( TextNode.class.equals(lastClass) ) return !((TextNode) lastItem).getText().endsWith(" "); if( SimpleNode.class.equals(lastClass) ) return !((SimpleNode) lastItem).getType().equals(SimpleNode.Type.Linebreak); } return true; }
@Override public String toString() { return super.toString() + " '" + StringUtils.escape(getText()) + '\''; }
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); } } }
/** * 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) ); }
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; }
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 printTag(TextNode node, String tag) { printer.print('<').print(tag).print('>'); printer.printEncoded(node.getText()); printer.print('<').print('/').print(tag).print('>'); }
@Override public boolean f(TextNode node, Node parent, int index) { alt.add(node.getText()); return true; } });
@Override public boolean f(TextNode node, Node parent, int index) { alt.add(node.getText()); return true; } });
@Override public boolean f(TextNode node, Node parent, int index) { alt.add(node.getText()); return true; } });
@Override public boolean f(TextNode node, Node parent, int index) { alt.add(node.getText()); return true; } });
@Override public void visit(TextNode tn) { _buffer.append( replaceProperties(tn.getText()) ); }
@Override public boolean f(TextNode node, Node parent, int index) { alt.add(replaceProperties(node.getText())); return true; } });
public void visit(TextNode node) { if (escapeText) { this.printer.printEncoded(node.getText()); } else { super.visit(node); } }
@Override public void process(int level, Node node, InvocationContext context) { TextNode tNode = (TextNode) node; context.append(new Chunk(tNode.getText(), context.peekFont())); } }
public void visit(TextNode textNode) { int lineNumber = getLineNumberFromStartIndex(textNode.getStartIndex()); // to sentence, if sentence breaker appear // append remain sentence, if sentence breaker not appear addCandidateSentence( getLineNumberFromStartIndex(textNode.getStartIndex()), textNode.getText(), textNode.getStartIndex() - getLineStartIndex(lineNumber)); // for printChildrenToString printer.print(textNode.getText()); }
@Override public void process(int level, Node node, InvocationContext context) { TextNode tNode = (TextNode) node; RichText text = new RichText(tNode.getText(), context.peekFont()); ITextContext iTextContext = context.iTextContext(); iTextContext.emit(text); } }