public Printer printchkln() { if (!endsWithNewLine()) { if (sb.length() > 0) print('\n'); for (int i = 0; i < indent; i++) print(' '); } return this; }
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); } }
@Override public void serialize(final VerbatimNode node, final Printer printer) { printer.println().print("<pre><code"); if (!StringUtils.isEmpty(node.getType())) { printAttribute(printer, "class", node.getType()); } printer.print(">"); String text = node.getText(); // print HTML breaks for all initial newlines while (text.charAt(0) == '\n') { printer.print("<br/>"); text = text.substring(1); } printer.printEncoded(text); printer.print("</code></pre>"); }
public void visit(TableCellNode node) { // String tag = inTableHeader ? "th" : "td"; List<TableColumnNode> columns = currentTableNode.getColumns(); TableColumnNode column = columns.get(Math.min(currentTableColumn, columns.size() - 1)); String pstr = printer.getString(); if (pstr.length() > 0) { if (pstr.endsWith("\n") || pstr.endsWith(" ")) { printer.print("|"); } else { printer.print(" |"); } } else { printer.print("|"); } column.accept(this); if (node.getColSpan() > 1) printer.print(" colspan=\"").print(Integer.toString(node.getColSpan())).print('"'); visitChildren(node); currentTableColumn += node.getColSpan(); }
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 void visit(SpecialTextNode node) { printer.printEncoded(node.getText()); }
protected void printBreakBeforeTag(SuperNode node, String tag) { boolean startWasNewLine = printer.endsWithNewLine(); printer.println(); printTag(node, tag); if (startWasNewLine) printer.println(); }
public ToAsciiDocSerializer(RootNode rootNode, String source) { this.printer = new Printer(); this.linguist = new Linguist(); this.autoDetectLanguageType = false; checkArgNotNull(rootNode, "rootNode"); this.rootNode = rootNode; this.source = source; }
public String toHtml(RootNode astRoot) { checkArgNotNull(astRoot, "astRoot"); astRoot.accept(this); return printer.getString(); }
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"); } }
public void visit(TableCellNode node) { // String tag = inTableHeader ? "th" : "td"; List<TableColumnNode> columns = currentTableNode.getColumns(); TableColumnNode column = columns.get(Math.min(currentTableColumn, columns.size() - 1)); String pstr = printer.getString(); if (pstr.length() > 0) { if (pstr.endsWith("\n") || pstr.endsWith(" ")) { printer.print("|"); } else { printer.print(" |"); } } else { printer.print("|"); } column.accept(this); if (node.getColSpan() > 1) printer.print(" colspan=\"").print(Integer.toString(node.getColSpan())).print('"'); visitChildren(node); currentTableColumn += node.getColSpan(); }