org.jsoup.nodes.TextNode.parent()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.2k)|赞(0)|评价(0)|浏览(151)

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

TextNode.parent介绍

暂无

代码示例

代码示例来源:origin: org.jsoup/jsoup

/**
 * Split this text node into two nodes at the specified string offset. After splitting, this node will contain the
 * original text up to the offset, and will have a new text node sibling containing the text after the offset.
 * @param offset string offset point to split node at.
 * @return the newly created text node containing the text after the offset.
 */
public TextNode splitText(int offset) {
  final String text = coreValue();
  Validate.isTrue(offset >= 0, "Split offset must be not be negative");
  Validate.isTrue(offset < text.length(), "Split offset must not be greater than current text length");
  String head = text.substring(0, offset);
  String tail = text.substring(offset);
  text(head);
  TextNode tailNode = new TextNode(tail);
  if (parent() != null)
    parent().addChildren(siblingIndex()+1, tailNode);
  return tailNode;
}

代码示例来源:origin: org.jsoup/jsoup

void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException {
  if (out.prettyPrint() && ((siblingIndex() == 0 && parentNode instanceof Element && ((Element) parentNode).tag().formatAsBlock() && !isBlank()) || (out.outline() && siblingNodes().size()>0 && !isBlank()) ))
    indent(accum, depth, out);
  boolean normaliseWhite = out.prettyPrint() && parent() instanceof Element
      && !Element.preserveWhitespace(parent());
  Entities.escape(accum, coreValue(), out, false, normaliseWhite, false);
}

代码示例来源:origin: org.eclipse.mylyn.docs/org.eclipse.mylyn.wikitext

private boolean isPreserveWhitespace() {
    Node parent = node.parent();
    while (parent != null) {
      if (parent.nodeName().equals("pre")) { //$NON-NLS-1$
        return true;
      }
      parent = parent.parent();
    }
    return false;
  }
}

代码示例来源:origin: stackoverflow.com

Document doc = Jsoup.connect(site).get();
 doc.body().traverse(new NodeVisitor() {
   @Override
   public void head(Node node, int depth) {
     if (node instanceof TextNode) {
       TextNode tn = ((TextNode) node);
       // Try to improve this filter for the nodes who contain
       // texts with a whitespaces
       if (tn.text().replaceAll("\\s*", "").length() > 0) {
         System.out.println("Tag:" + tn.parent().nodeName()
             + ", text:" + tn.text());
       }
     }
   }
   @Override
   public void tail(Node node, int depth) {
     // Do Nothing
   }
 });

代码示例来源:origin: DigitalPebble/storm-crawler

private static void appendNormalisedText(StringBuilder accum,
    TextNode textNode) {
  String text = textNode.getWholeText();
  if (preserveWhitespace(textNode.parent())
      || textNode instanceof CDataNode)
    accum.append(text);
  else
    StringUtil.appendNormalisedWhitespace(accum, text,
        lastCharIsWhitespace(accum));
}

代码示例来源:origin: org.eclipse.mylyn.docs/org.eclipse.mylyn.wikitext

int nonWhitespaceIndex = firstIndexOfNonWhitespace(text);
if (nonWhitespaceIndex > 0) {
  affectedParents.add(textNode.parent());
  computeBeforeTarget(element).before(textNode);
  affectedParents.add(textNode.parent());
} else if (nonWhitespaceIndex == -1) {
  computeAfterTarget(element).after(textNode);
  affectedParents.add(textNode.parent());
    computeAfterTarget(element).after(textNode);
    affectedParents.add(textNode.parent());
  } else if (lastNonWhitespaceIndex < (text.length() - 1)) {
    affectedParents.add(textNode.parent());
    computeAfterTarget(element).after(textNode);
    affectedParents.add(textNode.parent());

代码示例来源:origin: jungilhan/awesome-blogs-android

private String getTextNodeText(TextNode tn, boolean normalText) {
  String input = normalText ? tn.text() : tn.getWholeText();
  Node prev = tn.previousSibling();
  Node next = tn.nextSibling();
  boolean parentIsBlock = isBlock(tn.parent());
  if(isBlock(prev)) {
    input = ltrim(input);
  } else if(prev == null && parentIsBlock) {
    input = ltrim(input);
  } else if(normalText && prev instanceof TextNode) {
    TextNode tprev = (TextNode)prev;
    if(EMPTY_MATCHER.matcher(tprev.text()).matches()) {
      input = ltrim(input);
    }
  }
  if(input.length() > 0) {
    if(isBlock(next)) {
      input = rtrim(input);
    } else if(next == null && parentIsBlock) {
      input = rtrim(input);
    } else if(normalText && next instanceof TextNode) {
      TextNode tnext = (TextNode)next;
      if(EMPTY_MATCHER.matcher(tnext.text()).matches()) {
        input = rtrim(input);
      }
    }
  }
  return input;
}

代码示例来源:origin: org.eclipse.mylyn.docs/org.eclipse.mylyn.wikitext

normalizeTextNodes((Element) textNode.parent());

相关文章