public Rule Space() { return NodeSequence(OneOrMore(Spacechar()), push(new TextNode(" "))); }
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 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()); }
/** * 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; }
public Rule TerminalEndline() { return NodeSequence(Sp(), Newline(), Test(EOI), push(new TextNode("\n"))); }
@Override public String toString() { return super.toString() + " '" + StringUtils.escape(getText()) + '\''; }
public Rule Str() { return NodeSequence(OneOrMore(NormalChar()), push(new TextNode(match()))); }
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); } } }
@MemoMismatches public Rule UlOrStarLine() { // This keeps the parser from getting bogged down on long strings of '*', '_' or '~', // or strings of '*', '_' or '~' with space on each side: return NodeSequence( FirstOf(CharLine('_'), CharLine('*'), CharLine('~')), push(new TextNode(match())) ); }
/** * 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 Rule Entity() { return NodeSequence( Sequence('&', FirstOf(HexEntity(), DecEntity(), CharEntity()), ';'), push(new TextNode(match())) ); }
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; }
public Rule NormalEndline() { return Sequence( Sp(), Newline(), TestNot( FirstOf( BlankLine(), '>', AtxStart(), Sequence(ZeroOrMore(NotNewline(), ANY), Newline(), FirstOf(NOrMore('=', 3), NOrMore('-', 3)), Newline()), FencedCodeBlock() ) ), ext(HARDWRAPS) ? toRule(push(new SimpleNode(Type.Linebreak))) : toRule(push(new TextNode(" "))) ); }
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( tn.getText() ); }