本文整理了Java中org.jsoup.nodes.Element.unwrap()
方法的一些代码示例,展示了Element.unwrap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.unwrap()
方法的具体详情如下:
包路径:org.jsoup.nodes.Element
类名称:Element
方法名:unwrap
暂无
代码示例来源:origin: org.jsoup/jsoup
/**
* Removes the matched elements from the DOM, and moves their children up into their parents. This has the effect of
* dropping the elements but keeping their children.
* <p>
* This is useful for e.g removing unwanted formatting elements but keeping their contents.
* </p>
*
* E.g. with HTML: <p>{@code <div><font>One</font> <font><a href="/">Two</a></font></div>}</p>
* <p>{@code doc.select("font").unwrap();}</p>
* <p>HTML = {@code <div>One <a href="/">Two</a></div>}</p>
*
* @return this (for chaining)
* @see Node#unwrap
*/
public Elements unwrap() {
for (Element element : this) {
element.unwrap();
}
return this;
}
代码示例来源:origin: astamuse/asta4d
public Node unwrap() {
return originElement.unwrap();
}
代码示例来源:origin: com.wandrell.velocity/maven-site-fixer
/**
* Finds a set of elements through a CSS selector and unwraps them.
* <p>
* This allows removing elements without losing their contents.
*
* @param root
* root element for the selection
* @param selector
* CSS selector for the elements to unwrap
*/
public final void unwrap(final Element root, final String selector) {
final Iterable<Element> elements; // Elements to unwrap
checkNotNull(root, "Received a null pointer as root element");
checkNotNull(selector, "Received a null pointer as selector");
// Selects and iterates over the elements
elements = root.select(selector);
for (final Element element : elements) {
element.unwrap();
}
}
代码示例来源:origin: stackoverflow.com
public static String unWrapTag(String html, String tagName, String attribute, String matchRegEx) {
Validate.notNull(html, "html must be non null");
Validate.isTrue(StringUtils.isNotBlank(tagName), "tagName must be non blank");
if (StringUtils.isNotBlank(attribute)) {
Validate.notNull(matchRegEx, "matchRegEx must be non null when an attribute is provided");
}
Document doc = Jsoup.parse(html);
OutputSettings outputSettings = doc.outputSettings();
outputSettings.prettyPrint(false);
Elements elements = doc.getElementsByTag(tagName);
for (Element element : elements) {
if(StringUtils.isBlank(attribute)){
element.unwrap();
}else{
String attr = element.attr(attribute);
if(!StringUtils.isBlank(attr)){
String newData = attr.replaceAll(matchRegEx, "");
if(StringUtils.isBlank(newData)){
element.unwrap();
}
}
}
}
return doc.html();
}
代码示例来源:origin: chimbori/crux
private static void replaceLineBreaksWithSpaces(Element topNode) {
for (Element brNextToBrElement : topNode.select("br + br")) {
brNextToBrElement.remove();
}
for (Element brElement : topNode.select("br")) {
if (brElement.previousSibling() != null) {
brElement.previousSibling().after(" • ");
} else {
brElement.parent().append(" • ");
}
brElement.unwrap();
}
}
代码示例来源:origin: starlightknight/swagger-confluence
linkElement.unwrap();
代码示例来源: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;
}
代码示例来源: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: starlightknight/swagger-confluence
innerTocElement.unwrap();
代码示例来源:origin: perfectsense/dari
paragraph.unwrap();
代码示例来源:origin: perfectsense/brightspot-cms
paragraph.unwrap();
内容来源于网络,如有侵权,请联系作者删除!