本文整理了Java中org.jsoup.nodes.Element.wrap()
方法的一些代码示例,展示了Element.wrap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.wrap()
方法的具体详情如下:
包路径:org.jsoup.nodes.Element
类名称:Element
方法名:wrap
[英]Wrap the supplied HTML around this element.
[中]将提供的HTML环绕此元素。
代码示例来源:origin: org.jsoup/jsoup
/**
Wrap the supplied HTML around each matched elements. For example, with HTML
{@code <p><b>This</b> is <b>Jsoup</b></p>},
<code>doc.select("b").wrap("<i></i>");</code>
becomes {@code <p><i><b>This</b></i> is <i><b>jsoup</b></i></p>}
@param html HTML to wrap around each element, e.g. {@code <div class="head"></div>}. Can be arbitrarily deep.
@return this (for chaining)
@see Element#wrap
*/
public Elements wrap(String html) {
Validate.notEmpty(html);
for (Element element : this) {
element.wrap(html);
}
return this;
}
代码示例来源:origin: apache/usergrid
plainText = Jsoup.parse( htmlText ).body().wrap( "<pre></pre>" ).text();
代码示例来源:origin: astamuse/asta4d
public Element wrap(String html) {
return originElement.wrap(html);
}
代码示例来源:origin: stackoverflow.com
for (Element element : doc.body().select("a"))
element.wrap("<xmp></xmp>");
代码示例来源:origin: stackoverflow.com
Element p = doc.select("p").first();
p.wrap("<b>");
System.out.println(doc);
代码示例来源:origin: stackoverflow.com
for (Element element : doc.body().select("a"))
element.wrap("<xmp>split-me-here</xmp>split-me-here");
doc = Jsoup.parse(doc.html());
int cnt = 0;
List<String> splitText = Arrays.asList(doc.body().text().split("split-me-here"));
for (String text : splitText) {
cnt++;
if (!text.contains("</a>"))
System.out.println(cnt + "." + text.trim());
}
代码示例来源:origin: aint/laverna-android
/**
* A method which wraps a table element with div blocks to make table responsive.
* @param doc a document to parse.
*/
private void makeTablesResponsive(Document doc) {
for (Element element : doc.getElementsByTag(TABLE_TAG)) {
element.wrap(TABLE_WRAP_DIV_TAG);
}
}
代码示例来源:origin: stackoverflow.com
String str = "<span class=\"episode-number\">1</span><span class=\"episode-number\">1</span>";
Document doc = Jsoup.parse(str);
for(Element e: doc.select(".episode-number"))
e.wrap("<b></b>");
System.out.println(doc);
代码示例来源:origin: stackoverflow.com
File input = new File("input.html");
Document doc = Jsoup.parse(input, "UTF-8", "");
Element span = doc.select("span:containsOwn(Campaign0)").first();
span.wrap("<a href=\"First.html\"></a>");
span = doc.select("span:containsOwn(Campaign1)").first();
span.wrap("<a href=\"Second.html\"></a>");
String html = doc.html();
BufferedWriter htmlWriter =
new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output.html"), "UTF-8"));
htmlWriter.write(html);
htmlWriter.close();
代码示例来源:origin: com.wandrell.velocity/maven-site-fixer
/**
* Finds a set of elements through a CSS selector and wraps them with the
* received wrapper element.
*
* @param root
* root element for the selection
* @param selector
* CSS selector for the elements to wrap
* @param wrapper
* HTML to use for wrapping the selected elements
*/
public final void wrap(final Element root, final String selector,
final String wrapper) {
final Iterable<Element> elements; // Selected elements
checkNotNull(root, "Received a null pointer as root element");
checkNotNull(selector, "Received a null pointer as selector");
checkNotNull(wrapper, "Received a null pointer as HTML wrap");
// Selects and iterates over the elements
elements = root.select(selector);
for (final Element element : elements) {
element.wrap(wrapper);
}
}
代码示例来源:origin: andriusvelykis/reflow-maven-skin
element.wrap(wrapHtml);
代码示例来源:origin: lt.velykis.maven.skins/reflow-velocity-tools
element.wrap(wrapHtml);
代码示例来源:origin: uk.gov.dstl.baleen/baleen-collectionreaders
last.wrap(ASIDE);
} else {
allSiblings.get(i).wrap(ASIDE);
last.wrap(ASIDE);
代码示例来源:origin: dstl/baleen
last.wrap(ASIDE);
} else {
allSiblings.get(i).wrap(ASIDE);
last.wrap(ASIDE);
代码示例来源:origin: basis-technology-corp/Java-readability
private void handleDoubleBr() {
Elements doubleBrs = document.select("br + br");
for (Element br : doubleBrs) {
// we hope that there's a 'p' up there....
Elements parents = br.parents();
Element parent = null;
for (Element aparent : parents) {
if (aparent.tag().getName().equals("p")) {
parent = aparent;
break;
}
}
if (parent == null) {
parent = br.parent();
parent.wrap("<p></p>");
}
// now it's safe to make the change.
String inner = parent.html();
inner = Patterns.REPLACE_BRS.matcher(inner).replaceAll("</p><p>");
parent.html(inner);
}
}
代码示例来源:origin: andriusvelykis/reflow-maven-skin
private static Element wrapInner(Element element, String html) {
// wrap everything into an additional <div> for wrapping
// otherwise there may be problems, e.g. with <body> element
Element topDiv = new Element(Tag.valueOf("div"), "");
for (Element topElem : element.children()) {
// add all elements in the body to the `topDiv`
topElem.remove();
topDiv.appendChild(topElem);
}
// add topDiv to the body
element.appendChild(topDiv);
// wrap topDiv
topDiv.wrap(html);
// now unwrap topDiv - will remove it from the hierarchy
topDiv.unwrap();
return element;
}
代码示例来源:origin: lt.velykis.maven.skins/reflow-velocity-tools
private static Element wrapInner(Element element, String html) {
// wrap everything into an additional <div> for wrapping
// otherwise there may be problems, e.g. with <body> element
Element topDiv = new Element(Tag.valueOf("div"), "");
for (Element topElem : element.children()) {
// add all elements in the body to the `topDiv`
topElem.remove();
topDiv.appendChild(topElem);
}
// add topDiv to the body
element.appendChild(topDiv);
// wrap topDiv
topDiv.wrap(html);
// now unwrap topDiv - will remove it from the hierarchy
topDiv.unwrap();
return element;
}
内容来源于网络,如有侵权,请联系作者删除!