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

x33g5p2x  于2022-01-18 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(147)

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

Element.addClass介绍

[英]Add a class name to this element's class attribute.
[中]将类名添加到此元素的class属性。

代码示例

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

/**
 Add the class name to every matched element's {@code class} attribute.
 @param className class name to add
 @return this
 */
public Elements addClass(String className) {
  for (Element element : this) {
    element.addClass(className);
  }
  return this;
}

代码示例来源:origin: tomoya92/pybbs

Document parse = Jsoup.parse(content);
Elements tableElements = parse.select("table");
tableElements.forEach(element -> element.addClass("table table-bordered"));
Elements aElements = parse.select("p");
if (aElements != null && aElements.size() > 0) {
    Map<String, Object> querys = StringUtil.formatParams(query);
    element.text("");
    element.addClass("embed-responsive embed-responsive-16by9");
    element.append("<iframe class='embedded_video' src='https://www.youtube.com/embed/" + querys.get("v") + "' frameborder='0' allowfullscreen></iframe>");
   } else if (href.contains("//v.youku.com/v_show/")) {
    URL aUrl = new URL(href);
    String _href = "https://player.youku.com/embed/" + aUrl.getPath().replace("/v_show/id_", "").replace(".html", "");
    element.addClass("embedded_video_wrapper");
    element.append("<iframe class='embedded_video' src='" + _href + "' frameborder='0' allowfullscreen></iframe>");

代码示例来源:origin: com.vaadin/vaadin-server

mainDiv.addClass("v-app");
mainDiv.addClass(context.getThemeName());
mainDiv.addClass(
    context.getUIClass().getSimpleName().toLowerCase(Locale.ROOT));
if (style != null && !style.isEmpty()) {
  mainDiv.attr("style", style);
mainDiv.appendElement("div").addClass("v-app-loading");
mainDiv.appendElement("noscript").append(
    "You have to enable javascript in your browser to use an application built with Vaadin.");

代码示例来源:origin: com.vaadin/vaadin-server

body.addClass(ApplicationConstants.GENERATED_BODY_CLASSNAME);

代码示例来源:origin: astamuse/asta4d

public Element addClass(String className) {
  return originElement.addClass(className);
}

代码示例来源:origin: astamuse/asta4d

@Override
  protected void configure(Element elem, String attrName, Object attrValue) {
    elem.addClass(attrValue.toString());
  }
},

代码示例来源:origin: HubSpot/jinjava

@Override
 public void tail(Node node, int depth) {
  if (node instanceof Element) {
   Element el = (Element) node;
   if (StringUtils.isBlank(el.text())) {
    el.addClass("__deleteme");
   }
  }
 }
}

代码示例来源:origin: com.wandrell.velocity/maven-site-fixer

/**
 * Transforms tables to stripped and bordered tables.
 * <p>
 * This will apply Bootstrap classes to the table.
 * 
 * @param root
 *            root element with tables to transform
 */
public final void transformTables(final Element root) {
  final Collection<Element> tables; // Tables to fix
  checkNotNull(root, "Received a null pointer as root element");
  // Table rows with <th> tags in a <tbody>
  tables = root.select("table");
  for (final Element table : tables) {
    table.addClass("table");
    table.addClass("table-striped");
    table.addClass("table-bordered");
  }
}

代码示例来源:origin: com.atlassian.confluence.ext/newcode-macro-plugin

private String addExpandCollapseHtml(String content) {
  final Document doc = Jsoup.parse(content);
  final Elements headerElements = doc.select("div.codeHeader");
  if (headerElements != null && StringUtils.isNotEmpty(headerElements.toString())) {
    final Element headerElement = headerElements.get(0);
    headerElement.addClass("hide-border-bottom");
    headerElement.child(0).addClass("code-title");
    headerElement.child(0).after(addCollapseSourceHtml());
    final Element contentElement = doc.select("div.codeContent").get(0);
    contentElement.addClass("hide-toolbar");
  } else {
    final Element contentElement = doc.select("div.codeContent").get(0);
    contentElement.before(addHeaderHtml());
    contentElement.addClass("hide-toolbar");
  }
  return doc.body().html();
}

代码示例来源:origin: lt.velykis.maven.skins/reflow-velocity-tools

element.addClass(className);

代码示例来源:origin: andriusvelykis/reflow-maven-skin

element.addClass(className);

代码示例来源:origin: io.committed.krill/krill

final Element e = document.createElement("details").addClass("footnote")
  .text(matcher.group("content"));
p.appendChild(e);

代码示例来源:origin: org.kantega.openaksess/openaksess-core

div.addClass("error");

代码示例来源:origin: org.aperteworkflow/webapi

/**
 * Add actions buttons to the output document.
 */
protected void buildActionButtons(final Document document) {
  Element actionsNode = document.createElement("div")
      //.attr("id", "actions-list")
      .attr("id", getActionsListHtmlId())
      .attr("class", "actions-view")
      .addClass("fixed-element-action-buttons");
  document.appendChild(actionsNode);
  Element genericActionButtons = document.createElement("div")
      .attr("id", getActionsGenericListHtmlId())
      .attr("class", "btn-group  pull-left actions-generic-view");
  Element specificActionButtons = document.createElement("div")
      .attr("id", getActionsSpecificListHtmlId())
      .attr("class", "btn-group  pull-right actions-process-view");
  actionsNode.appendChild(genericActionButtons);
  actionsNode.appendChild(specificActionButtons);
  document.appendElement("div").addClass("fixed-element-anchor-action-buttons");
  /* Check if the viewed object is in a terminal state */
  buildGenericActionButtons(genericActionButtons);
  if (!isViewedObjectClosed()) {
    buildSpecificActionButtons(specificActionButtons);
  }
}

代码示例来源:origin: USPTO/PatentPublicData

public void fixFigrefListItem(Element element) {
  Node next = element.nextSibling();
  String trailingTxt;
  if (next != null && next instanceof TextNode) {
    trailingTxt = ((TextNode) next).getWholeText();
  } else if (next != null && next instanceof Element) {
    trailingTxt = ((Element) next).text();
  } else {
    return;
  }
  if (trailingTxt.matches("^(, |,? and )")) {
    next = element.nextSibling().nextSibling();
    if (next.nodeName().toLowerCase().equals("b")) {
      String containedTxt = ((TextNode) next.childNode(0)).getWholeText();
      if (containedTxt.matches("[0-9]{1,2}[A-z]?")) {
        Element newEl = element.clone();
        newEl.attr("id", "FR-" + Strings.padStart(containedTxt, 4, '0'));
        newEl.attr("idref", ReferenceTagger.createFigId(containedTxt));
        newEl.tagName("a");
        newEl.addClass("figref");
        newEl.text(containedTxt);
        next.replaceWith(newEl);
        fixFigrefListItem(newEl);
      }
    }
  }
}

代码示例来源:origin: USPTO/PatentPublicData

element.attr("idref", ReferenceTagger.createFigId(element.text()));
element.tagName("a");
element.addClass("figref");
element.attr("idref", element.attr("depends_on"));
element.tagName("a");
element.addClass("claim");
element.removeAttr("depends_on");
element.attr("id", "FOR-" + Strings.padStart(String.valueOf(i), 4, '0'));
element.tagName("span");
element.addClass("formula");
newEl.addClass("math");
newEl.attr("format", "mathml");
newEl.appendChild(new TextNode(mathml));

代码示例来源:origin: USPTO/PatentPublicData

element.attr("id", "FOR-" + Strings.padStart(String.valueOf(i), 4, '0'));
element.tagName("span");
element.addClass("formula");
element.attr("idref", ReferenceTagger.createFigId(element.text()));
element.tagName("a");
element.addClass("figref");
element.attr("id", "CR-" + Strings.padStart(String.valueOf(i), 4, '0'));
element.tagName("a");
element.addClass("claim");
element.addClass("patcite");
element.addClass("nplcite");
element.addClass("crossref");
newEl.addClass("math");
newEl.attr("format", "mathml");
newEl.appendChild(new TextNode(mathml));

代码示例来源:origin: schaal/ocreader

private String extractFirstImg(Document document) {
  String firstImgString = "";
  try {
    Element child = document.body().child(0);
    // if document starts with <br>, remove it
    if (child.tagName().equals("br")) {
      Element brChild = child;
      child = child.nextElementSibling();
      brChild.remove();
    }
    while (child != null && !child.tagName().equals("img")) {
      child = child.children().first();
    }
    if (child != null) {
      child.remove();
      child.addClass("headerimg");
      firstImgString = child.toString();
    }
  } catch (IndexOutOfBoundsException e) {
    Log.e(TAG, "Body has no children", e);
  }
  return firstImgString;
}

代码示例来源:origin: USPTO/PatentPublicData

element.attr("idref", ReferenceTagger.createFigId(element.select("PDAT").text()));
element.tagName("a");
element.addClass("figref");
element.attr("id", "CR-" + Strings.padStart(String.valueOf(i), 4, '0'));
element.tagName("a");
element.addClass("claim");
newEl.addClass("math");
newEl.attr("format", "mathml");
newEl.appendChild(new TextNode(mathml));

代码示例来源:origin: theonedev/onedev

TextNode textNode = (TextNode) body.childNode(i);
Element element = new Element(Tag.valueOf("a"), "");
element.addClass("commit");
element.attr("href", commitUrl);
element.appendText(textNode.getWholeText());

相关文章

Element类方法