org.commonmark.node.Node类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(94)

本文整理了Java中org.commonmark.node.Node类的一些代码示例,展示了Node类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node类的具体详情如下:
包路径:org.commonmark.node.Node
类名称:Node

Node介绍

暂无

代码示例

代码示例来源:origin: atlassian/commonmark-java

/**
   * Visit the child nodes.
   *
   * @param parent the parent node whose children should be visited
   */
  protected void visitChildren(Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
      // A subclass of this visitor might modify the node, resulting in getNext returning a different node or no
      // node after visiting it. So get the next node before visiting.
      Node next = node.getNext();
      node.accept(this);
      node = next;
    }
  }
}

代码示例来源:origin: atlassian/commonmark-java

@Override
  public void process(Text opener, Text closer, int delimiterCount) {
    // Wrap nodes between delimiters in ins.
    Node ins = new Ins();

    Node tmp = opener.getNext();
    while (tmp != null && tmp != closer) {
      Node next = tmp.getNext();
      ins.appendChild(tmp);
      tmp = next;
    }

    opener.insertAfter(ins);
  }
}

代码示例来源:origin: atlassian/commonmark-java

private void mergeIfNeeded(Text first, Text last, int textLength) {
  if (first != null && last != null && first != last) {
    StringBuilder sb = new StringBuilder(textLength);
    sb.append(first.getLiteral());
    Node node = first.getNext();
    Node stop = last.getNext();
    while (node != stop) {
      sb.append(((Text) node).getLiteral());
      Node unlink = node;
      node = node.getNext();
      unlink.unlink();
    }
    String literal = sb.toString();
    first.setLiteral(literal);
  }
}

代码示例来源:origin: atlassian/commonmark-java

public void appendChild(Node child) {
  child.unlink();
  child.setParent(this);
  if (this.lastChild != null) {
    this.lastChild.next = child;
    child.prev = this.lastChild;
    this.lastChild = child;
  } else {
    this.firstChild = child;
    this.lastChild = child;
  }
}

代码示例来源:origin: atlassian/commonmark-java

private void mergeChildTextNodes(Node node) {
  // No children or just one child node, no need for merging
  if (node.getFirstChild() == node.getLastChild()) {
    return;
  }
  mergeTextNodesInclusive(node.getFirstChild(), node.getLastChild());
}

代码示例来源:origin: atlassian/commonmark-java

private void renderChildren(Node parent) {
    Node node = parent.getFirstChild();
    while (node != null) {
      Node next = node.getNext();
      context.render(node);
      node = next;
    }
  }
}

代码示例来源:origin: atlassian/commonmark-java

@Override
public void render(Node node) {
  node.accept(this);
}

代码示例来源:origin: atlassian/commonmark-java

private void writeEndOfLineIfNeeded(Node node, Character c) {
  if (context.stripNewlines()) {
    if (c != null) {
      textContent.write(c);
    }
    if (node.getNext() != null) {
      textContent.whitespace();
    }
  } else {
    if (node.getNext() != null) {
      textContent.line();
    }
  }
}

代码示例来源:origin: atlassian/commonmark-java

private void writeLink(Node node, String title, String destination) {
  boolean hasChild = node.getFirstChild() != null;
  boolean hasTitle = title != null && !title.equals(destination);
  boolean hasDestination = destination != null && !destination.equals("");
  if (hasChild) {
    textContent.write('"');
    visitChildren(node);
    textContent.write('"');
    if (hasTitle || hasDestination) {
      textContent.whitespace();
      textContent.write('(');
    }
  }
  if (hasTitle) {
    textContent.write(title);
    if (hasDestination) {
      textContent.colon();
      textContent.whitespace();
    }
  }
  if (hasDestination) {
    textContent.write(destination);
  }
  if (hasChild && (hasTitle || hasDestination)) {
    textContent.write(')');
  }
}

代码示例来源:origin: atlassian/commonmark-java

private void mergeTextNodesBetweenExclusive(Node fromNode, Node toNode) {
  // No nodes between them
  if (fromNode == toNode || fromNode.getNext() == toNode) {
    return;
  }
  mergeTextNodesInclusive(fromNode.getNext(), toNode.getPrevious());
}

代码示例来源:origin: atlassian/commonmark-java

private void appendNode(Node node) {
  block.appendChild(node);
}

代码示例来源:origin: atlassian/commonmark-java

public void insertAfter(Node sibling) {
  sibling.unlink();
  sibling.next = this.next;
  if (sibling.next != null) {
    sibling.next.prev = sibling;
  }
  sibling.prev = this;
  this.next = sibling;
  sibling.parent = this.parent;
  if (sibling.next == null) {
    sibling.parent.lastChild = sibling;
  }
}

代码示例来源:origin: atlassian/commonmark-java

public Block getParent() {
  return (Block) super.getParent();
}

代码示例来源:origin: atlassian/commonmark-java

@Override
protected void visitChildren(Node parent) {
  Node node = parent.getFirstChild();
  while (node != null) {
    Node next = node.getNext();
    context.render(node);
    node = next;
  }
}

代码示例来源:origin: atlassian/commonmark-java

@Override
public void render(Node node) {
  node.accept(this);
}

代码示例来源:origin: atlassian/commonmark-java

private void mergeTextNodesInclusive(Node fromNode, Node toNode) {
  Text first = null;
  Text last = null;
  int length = 0;
  Node node = fromNode;
  while (node != null) {
    if (node instanceof Text) {
      Text text = (Text) node;
      if (first == null) {
        first = text;
      }
      length += text.getLiteral().length();
      last = text;
    } else {
      mergeIfNeeded(first, last, length);
      first = null;
      last = null;
      length = 0;
    }
    if (node == toNode) {
      break;
    }
    node = node.getNext();
  }
  mergeIfNeeded(first, last, length);
}

代码示例来源:origin: gsvigruha/cosyan

private static void markdownToHtml(String resourcesDir) throws IOException {
 File docRoot = new File(resourcesDir + File.separator + "doc");
 Collection<File> files = FileUtils.listFiles(docRoot, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).stream()
   .sorted((f1, f2) -> f1.getName().compareTo(f2.getName())).collect(Collectors.toList());
 JSONArray items = new JSONArray();
 String webRoot = "web" + File.separator + "app" + File.separator + "help";
 for (File markdown : files) {
  Parser parser = Parser.builder().build();
  Node document = parser.parse(FileUtils.readFileToString(markdown, Charset.defaultCharset()));
  HtmlRenderer renderer = HtmlRenderer.builder().build();
  String suffix = markdown.getAbsolutePath().substring(docRoot.getAbsolutePath().length() + 1, markdown.getAbsolutePath().length() - 3);
  File html = new File(webRoot + File.separator + suffix + ".html");
  FileUtils.writeStringToFile(html, renderer.render(document), Charset.defaultCharset());
  JSONObject object = new JSONObject();
  object.put("url", suffix);
  object.put("title", ((Text) document.getFirstChild().getFirstChild()).getLiteral());
  items.put(object);
 }
 FileUtils.writeStringToFile(new File(webRoot + File.separator + "list"), items.toString(), Charset.defaultCharset());
}

代码示例来源:origin: com.atlassian.commonmark/commonmark

private void mergeTextNodesBetweenExclusive(Node fromNode, Node toNode) {
  // No nodes between them
  if (fromNode == toNode || fromNode.getNext() == toNode) {
    return;
  }
  mergeTextNodesInclusive(fromNode.getNext(), toNode.getPrevious());
}

代码示例来源:origin: com.atlassian.commonmark/commonmark

private void mergeChildTextNodes(Node node) {
  // No children or just one child node, no need for merging
  if (node.getFirstChild() == node.getLastChild()) {
    return;
  }
  mergeTextNodesInclusive(node.getFirstChild(), node.getLastChild());
}

代码示例来源:origin: atlassian/commonmark-java

section.appendChild(tableRow);

相关文章

微信公众号

最新文章

更多