org.jsoup.nodes.TextNode#text ( )源码实例Demo

下面列出了org.jsoup.nodes.TextNode#text ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Xndroid   文件: OutputFormatter.java
private void appendTextSkipHidden(Element e, StringBuilder accum, int indent) {
    for (Node child : e.childNodes()) {
        if (unlikely(child)) {
            continue;
        }
        if (child instanceof TextNode) {
            TextNode textNode = (TextNode) child;
            String txt = textNode.text();
            accum.append(txt);
        } else if (child instanceof Element) {
            Element element = (Element) child;
            if (accum.length() > 0 && element.isBlock()
                    && !lastCharIsWhitespace(accum))
                accum.append(' ');
            else if (element.tagName().equals("br"))
                accum.append(' ');
            appendTextSkipHidden(element, accum, indent + 1);
        }
    }
}
 
源代码2 项目: zongtui-webcrawler   文件: ElementOperator.java
@Override
public String operate(Element element) {
    int index = 0;
    StringBuilder accum = new StringBuilder();
    for (Node node : element.childNodes()) {
        if (node instanceof TextNode) {
            TextNode textNode = (TextNode) node;
            if (group == 0) {
                accum.append(textNode.text());
            } else if (++index == group) {
                return textNode.text();
            }
        }
    }
    return accum.toString();
}
 
源代码3 项目: JumpGo   文件: OutputFormatter.java
private void appendTextSkipHidden(Element e, StringBuilder accum, int indent) {
    for (Node child : e.childNodes()) {
        if (unlikely(child)) {
            continue;
        }
        if (child instanceof TextNode) {
            TextNode textNode = (TextNode) child;
            String txt = textNode.text();
            accum.append(txt);
        } else if (child instanceof Element) {
            Element element = (Element) child;
            if (accum.length() > 0 && element.isBlock()
                    && !lastCharIsWhitespace(accum))
                accum.append(' ');
            else if (element.tagName().equals("br"))
                accum.append(' ');
            appendTextSkipHidden(element, accum, indent + 1);
        }
    }
}
 
源代码4 项目: jinjava   文件: TruncateHtmlFilter.java
@Override
public void head(Node node, int depth) {
  if (node instanceof TextNode) {
    TextNode text = (TextNode) node;
    String textContent = text.text();

    if (textLen >= maxTextLen) {
      text.text("");
    } else if (textLen + textContent.length() > maxTextLen) {
      int ptr = maxTextLen - textLen;
      if (!killwords) {
        ptr = Functions.movePointerToJustBeforeLastWord(ptr, textContent) - 1;
      }

      text.text(textContent.substring(0, ptr) + ending);
      textLen = maxTextLen;
    } else {
      textLen += textContent.length();
    }
  }
}
 
源代码5 项目: xsoup   文件: ElementOperator.java
@Override
public String operate(Element element) {
    int index = 0;
    StringBuilder accum = new StringBuilder();
    for (Node node : element.childNodes()) {
        if (node instanceof TextNode) {
            TextNode textNode = (TextNode) node;
            if (group == 0) {
                accum.append(textNode.text());
            } else if (++index == group) {
                return textNode.text();
            }
        }
    }
    return accum.toString();
}
 
源代码6 项目: FairEmail   文件: HtmlHelper.java
static void cleanup(Document d) {
    // https://www.chromestatus.com/feature/5756335865987072
    // Some messages contain 100 thousands of Apple spaces
    for (Element aspace : d.select(".Apple-converted-space")) {
        Node next = aspace.nextSibling();
        if (next instanceof TextNode) {
            TextNode tnode = (TextNode) next;
            tnode.text(" " + tnode.text());
            aspace.remove();
        } else
            aspace.replaceWith(new TextNode(" "));
    }
}
 
源代码7 项目: FairEmail   文件: HtmlHelper.java
static boolean truncate(Document d, boolean reformat) {
    int max = (reformat ? MAX_FORMAT_TEXT_SIZE : MAX_FULL_TEXT_SIZE);

    int length = 0;
    int images = 0;
    for (Element elm : d.select("*")) {
        if ("img".equals(elm.tagName()))
            images++;

        boolean skip = false;
        for (Node child : elm.childNodes()) {
            if (child instanceof TextNode) {
                TextNode tnode = ((TextNode) child);
                String text = tnode.getWholeText();

                if (length < max) {
                    if (length + text.length() >= max) {
                        text = text.substring(0, max - length) + " ...";
                        tnode.text(text);
                        skip = true;
                    }
                } else {
                    if (skip)
                        tnode.text("");
                }

                length += text.length();
            }
        }

        if (length >= max && !skip)
            elm.remove();
    }

    Log.i("Message size=" + length + " images=" + images);

    return (length >= max);
}
 
源代码8 项目: M2Doc   文件: M2DocHTMLParser.java
/**
 * Inserts the text of the given {@link TextNode}.
 * 
 * @param parent
 *            the parent {@link MList}
 * @param context
 *            the {@link Context}
 * @param node
 *            the {@link TextNode}
 */
private void insertText(MList parent, final Context context, TextNode node) {
    final String text = node.text();
    if (!text.trim().isEmpty()) {
        if (context.linkTargetURI == null) {
            final MText mText = new MTextImpl(text, context.style);
            parent.add(mText);
        } else {
            context.style.setForegroundColor(LINK_COLOR);
            final MHyperLink mLink = new MHyperLinkImpl(text, context.style, context.linkTargetURI.toString());
            parent.add(mLink);
        }
    }
}
 
源代码9 项目: ContentExtractor   文件: ContentExtractor.java
public CountInfo(TextNode tNode) {
    this.tNode = tNode;
    String text = tNode.text();
    this.textCount = TextUtils.countText(text);
    this.puncCount = TextUtils.countPunc(text);
}
 
源代码10 项目: WordCount   文件: ContentExtractor.java
public CountInfo(TextNode tNode) {
    this.tNode = tNode;
    String text = tNode.text();
    this.textCount = TextUtils.countText(text);
    this.puncCount = TextUtils.countPunc(text);
}
 
 方法所在类
 同类方法