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

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

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

Node介绍

暂无

代码示例

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

  1. /**
  2. * Visit the child nodes.
  3. *
  4. * @param parent the parent node whose children should be visited
  5. */
  6. protected void visitChildren(Node parent) {
  7. Node node = parent.getFirstChild();
  8. while (node != null) {
  9. // A subclass of this visitor might modify the node, resulting in getNext returning a different node or no
  10. // node after visiting it. So get the next node before visiting.
  11. Node next = node.getNext();
  12. node.accept(this);
  13. node = next;
  14. }
  15. }
  16. }

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

  1. @Override
  2. public void process(Text opener, Text closer, int delimiterCount) {
  3. // Wrap nodes between delimiters in ins.
  4. Node ins = new Ins();
  5. Node tmp = opener.getNext();
  6. while (tmp != null && tmp != closer) {
  7. Node next = tmp.getNext();
  8. ins.appendChild(tmp);
  9. tmp = next;
  10. }
  11. opener.insertAfter(ins);
  12. }
  13. }

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

  1. private void mergeIfNeeded(Text first, Text last, int textLength) {
  2. if (first != null && last != null && first != last) {
  3. StringBuilder sb = new StringBuilder(textLength);
  4. sb.append(first.getLiteral());
  5. Node node = first.getNext();
  6. Node stop = last.getNext();
  7. while (node != stop) {
  8. sb.append(((Text) node).getLiteral());
  9. Node unlink = node;
  10. node = node.getNext();
  11. unlink.unlink();
  12. }
  13. String literal = sb.toString();
  14. first.setLiteral(literal);
  15. }
  16. }

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

  1. public void appendChild(Node child) {
  2. child.unlink();
  3. child.setParent(this);
  4. if (this.lastChild != null) {
  5. this.lastChild.next = child;
  6. child.prev = this.lastChild;
  7. this.lastChild = child;
  8. } else {
  9. this.firstChild = child;
  10. this.lastChild = child;
  11. }
  12. }

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

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

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

  1. private void renderChildren(Node parent) {
  2. Node node = parent.getFirstChild();
  3. while (node != null) {
  4. Node next = node.getNext();
  5. context.render(node);
  6. node = next;
  7. }
  8. }
  9. }

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

  1. @Override
  2. public void render(Node node) {
  3. node.accept(this);
  4. }

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

  1. private void writeEndOfLineIfNeeded(Node node, Character c) {
  2. if (context.stripNewlines()) {
  3. if (c != null) {
  4. textContent.write(c);
  5. }
  6. if (node.getNext() != null) {
  7. textContent.whitespace();
  8. }
  9. } else {
  10. if (node.getNext() != null) {
  11. textContent.line();
  12. }
  13. }
  14. }

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

  1. private void writeLink(Node node, String title, String destination) {
  2. boolean hasChild = node.getFirstChild() != null;
  3. boolean hasTitle = title != null && !title.equals(destination);
  4. boolean hasDestination = destination != null && !destination.equals("");
  5. if (hasChild) {
  6. textContent.write('"');
  7. visitChildren(node);
  8. textContent.write('"');
  9. if (hasTitle || hasDestination) {
  10. textContent.whitespace();
  11. textContent.write('(');
  12. }
  13. }
  14. if (hasTitle) {
  15. textContent.write(title);
  16. if (hasDestination) {
  17. textContent.colon();
  18. textContent.whitespace();
  19. }
  20. }
  21. if (hasDestination) {
  22. textContent.write(destination);
  23. }
  24. if (hasChild && (hasTitle || hasDestination)) {
  25. textContent.write(')');
  26. }
  27. }

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

  1. private void mergeTextNodesBetweenExclusive(Node fromNode, Node toNode) {
  2. // No nodes between them
  3. if (fromNode == toNode || fromNode.getNext() == toNode) {
  4. return;
  5. }
  6. mergeTextNodesInclusive(fromNode.getNext(), toNode.getPrevious());
  7. }

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

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

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

  1. public void insertAfter(Node sibling) {
  2. sibling.unlink();
  3. sibling.next = this.next;
  4. if (sibling.next != null) {
  5. sibling.next.prev = sibling;
  6. }
  7. sibling.prev = this;
  8. this.next = sibling;
  9. sibling.parent = this.parent;
  10. if (sibling.next == null) {
  11. sibling.parent.lastChild = sibling;
  12. }
  13. }

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

  1. public Block getParent() {
  2. return (Block) super.getParent();
  3. }

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

  1. @Override
  2. protected void visitChildren(Node parent) {
  3. Node node = parent.getFirstChild();
  4. while (node != null) {
  5. Node next = node.getNext();
  6. context.render(node);
  7. node = next;
  8. }
  9. }

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

  1. @Override
  2. public void render(Node node) {
  3. node.accept(this);
  4. }

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

  1. private void mergeTextNodesInclusive(Node fromNode, Node toNode) {
  2. Text first = null;
  3. Text last = null;
  4. int length = 0;
  5. Node node = fromNode;
  6. while (node != null) {
  7. if (node instanceof Text) {
  8. Text text = (Text) node;
  9. if (first == null) {
  10. first = text;
  11. }
  12. length += text.getLiteral().length();
  13. last = text;
  14. } else {
  15. mergeIfNeeded(first, last, length);
  16. first = null;
  17. last = null;
  18. length = 0;
  19. }
  20. if (node == toNode) {
  21. break;
  22. }
  23. node = node.getNext();
  24. }
  25. mergeIfNeeded(first, last, length);
  26. }

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

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

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

  1. private void mergeTextNodesBetweenExclusive(Node fromNode, Node toNode) {
  2. // No nodes between them
  3. if (fromNode == toNode || fromNode.getNext() == toNode) {
  4. return;
  5. }
  6. mergeTextNodesInclusive(fromNode.getNext(), toNode.getPrevious());
  7. }

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

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

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

  1. section.appendChild(tableRow);

相关文章