Package com.overzealous.remark.util

Examples of com.overzealous.remark.util.BlockWriter


    boolean numericList = node.tagName().equals("ol");
    // keep track of where we are in the list.
    int listCounter = 1;

    // we need to store this, because we're going to replace it for each li below (for padding).
    BlockWriter parentWriter = converter.output;
    parentWriter.startBlock();
    for(final Element child : node.children()) {
      // handle linebreaks between li's
      if(first) {
        first = false;
      } else {
        parentWriter.println();
      }
      // handle starting character
      if(numericList) {
        parentWriter.print(listCounter);
        parentWriter.print(". ");
        if(listCounter < 10) {
          parentWriter.print(' ');
        }
      } else {
        parentWriter.print(" *  ");
      }

      // now, recurse downward, padding the beginning of each line so it looks nice.
      converter.output = new BlockWriter(parentWriter).setPrependNewlineString("    ", true);
      converter.walkNodes(this, child, converter.blockNodes);
      listCounter++;
    }
    // cleanup
    parentWriter.endBlock();
    converter.output = parentWriter;
  }
View Full Code Here


   *
   * @param doc Document to convert
   * @param out Writer to receive the final output
   */
  public void convert(Document doc, Writer out) {
    this.output = new BlockWriter(out, true);
    this.convertImpl(doc);
  }
View Full Code Here

   *
   * @param doc Document to convert
   * @param out OutputStream to receive the final output
   */
  public void convert(Document doc, OutputStream out) {
    this.output = new BlockWriter(out, true);
    this.convertImpl(doc);
  }
View Full Code Here

   * @param doc Document to convert
   * @return The Markdown-formatted string.
   */
  public String convert(Document doc) {
    // estimate the size necessary to handle the final output
    BlockWriter bw = BlockWriter.create(DocumentConverter.calculateLength(doc, 0));
    this.output = bw;
    this.convertImpl(doc);
    return bw.toString();
  }
View Full Code Here

   * @param el The parent HTML Element whose children are being looked at.
   * @param undoLeadingEscapes If true, leading escapes are removed
   * @return The potential output string.
   */
  public String getInlineContent(NodeHandler currentNode, Element el, boolean undoLeadingEscapes) {
    BlockWriter oldOutput = output;
    output = BlockWriter.create(1000);
    walkNodes(currentNode, el, inlineNodes);
    String ret = output.toString();
    output = oldOutput;
    if(undoLeadingEscapes) {
View Full Code Here

   * @param parent The previous node walker, in case we just want to remove an element.
   * @param node    Node to handle
   * @param converter Parent converter for this object.
   */
  public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
    BlockWriter out;
    Options.FencedCodeBlocks fenced = converter.options.getFencedCodeBlocks();
    if(fenced.isEnabled()) {
      String fence = StringUtils.multiply(fenced.getSeparatorCharacter(),
                             converter.options.fencedCodeBlocksWidth);
      out = converter.output;
      converter.output.startBlock();
      out.println(fence);
      out.write(converter.cleaner.cleanCode(node));
      out.println();
      out.print(fence);
      converter.output.endBlock();
    } else {
      converter.output.startBlock();
      out = new BlockWriter(converter.output).setPrependNewlineString("    ");
      out.write(converter.cleaner.cleanCode(node));
      converter.output.endBlock();
    }
  }
View Full Code Here

    // the first child node doesn't get a linebreak
    boolean first = true;
    boolean lastNodeWasDD = false;

    // we need to store this, because we're going to replace it for each dd below (for padding).
    BlockWriter parentWriter = converter.output;

    /* Note on block handling:
     * We need a gap between each dd and the following dt, like so:
     *     term
     *     : definition
     *
     *     term
     *     : definition
     *
     * To do this, we wrap the whole thing in a start/end block. Then,
     * every time we come across a dt, we end a block and start a new one.
     * The only exception to this rule is if the first node we come to is
     * a dt - then we don't do anything.
     */
    parentWriter.startBlock();
    for(final Element child : node.children()) {

      if(child.tagName().equals("dt")) {
        // print term
        if(first) {
          // the first node is a term, so we already started a block.
          first = false;
        } else {
          // add block separation between defs and next term.
          parentWriter.endBlock();
          parentWriter.startBlock();
        }
        converter.walkNodes(this, child, converter.inlineNodes);
        parentWriter.println();
        lastNodeWasDD = false;

      } else if(child.tagName().equals("dd")) {
        // print definition
        if(first) {
          // the first node is a def, so we'll need a new block next time.
          first = false;
        }
        if(lastNodeWasDD) {
          parentWriter.println();
        }
        parentWriter.print(":   ");
        // Is this necessary?  We only allow inline, and inline is always one line, so padding is redundant.
        // Of course, we may want to offer wrapped blocks later, when hardwraps are turned off.
        converter.output = new BlockWriter(parentWriter).setPrependNewlineString("    ", true);
        converter.walkNodes(this, child, converter.blockNodes);
        converter.output = parentWriter;
       
        lastNodeWasDD = true;

      } // else, ignore, bad node
    }
    // cleanup
    parentWriter.endBlock();
  }
View Full Code Here

   * @param node    Node to handle
   * @param converter Parent converter for this object.
   */
  public void handleNode(NodeHandler parent, Element node, DocumentConverter converter) {
    int depth = Integer.parseInt(node.tagName().substring(1, 2));
    BlockWriter out = converter.output;
    out.startBlock();
    StringUtils.multiply(out, '#', depth);
    out.print(' ');
    out.print(converter.getInlineContent(this, node).replace("\n", " "));
    out.print(' ');
    StringUtils.multiply(out, '#', depth);
    if(converter.options.headerIds && node.hasAttr("id")) {
      out.printf("    {#%s}", node.attr("id"));
    }
    out.endBlock();
  }
View Full Code Here

   * @param converter Parent document converter
   * @param nodes Map of valid nodes
   */
  @SuppressWarnings({"WeakerAccess", "SameParameterValue"})
  protected void prependAndRecurse(String prepend, Element node, DocumentConverter converter, Map<String,NodeHandler> nodes) {
    BlockWriter oldOutput = converter.output;
    converter.output = new BlockWriter(oldOutput).setPrependNewlineString(prepend);
    converter.walkNodes(this, node, nodes);
    converter.output = oldOutput;
  }
View Full Code Here

      String linkId = converter.addLink(url, alt, true);
      // give a usable description based on filename whenever possible
      if(alt.length() == 0) {
        alt = linkId;
      }
      BlockWriter out = converter.output;
      if(alt.equals(linkId)) {
        out.printf("![%s][]", linkId);
      } else {
        out.printf("![%s][%s]", alt, linkId);
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.overzealous.remark.util.BlockWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.