public Rule FencedCodeBlock() { StringBuilderVar text = new StringBuilderVar(); Var<Integer> markerLength = new Var<Integer>(); return NodeSequence( CodeFence(markerLength), TestNot(CodeFence(markerLength)), // prevent empty matches ZeroOrMore(BlankLine(), text.append('\n')), OneOrMore(TestNot(Newline(), CodeFence(markerLength)), ANY, text.append(matchedChar())), Newline(), push(new VerbatimNode(text.appended('\n').getString(), popAsString())), CodeFence(markerLength), drop() ); }
public Rule Verbatim() { StringBuilderVar text = new StringBuilderVar(); StringBuilderVar line = new StringBuilderVar(); return NodeSequence( OneOrMore( ZeroOrMore(BlankLine(), line.append('\n')), Indent(), push(currentIndex()), OneOrMore( FirstOf( Sequence('\t', line.append(repeat(' ', 4-(currentIndex()-1-(Integer)peek())%4))), Sequence(NotNewline(), ANY, line.append(matchedChar())) ) ), Newline(), text.appended(line.getString()).append('\n') && line.clearContents() && drop() ), push(new VerbatimNode(text.getString())) ); }
/** * Overrides the default implementation to set the language to "no-highlight" no * language is specified. If highlighting is disabled or auto-highlighting is enabled, * this method just calls the default implementation. * * @param node The AST node. */ @Override public void visit(VerbatimNode node) { if ( options.isHighlightEnabled() && !options.isAutoHighlightEnabled() && node.getType().isEmpty() ) { VerbatimNode noHighlightNode = new VerbatimNode(node.getText(), "no-highlight"); noHighlightNode.setStartIndex(node.getStartIndex()); noHighlightNode.setEndIndex(node.getEndIndex()); super.visit(noHighlightNode); } else { super.visit(node); } } }