private void emitOpeningTagIfRequiredByHtml5()

in java/org/jsoup/nodes/Html5Printer.java [120:166]


  private void emitOpeningTagIfRequiredByHtml5(int depth) throws IOException {
    if (isDocumentOrDoctype()) {
      return;
    }
    if (currentNode instanceof Element
        && currentNode.attributes().size() == 0
        && currentNode.attributes().dataset().isEmpty()) {
      switch (currentNode.nodeName()) {
        case "html":
          if (currentNode.childNodeSize() > 0 && !(currentNode.childNode(0) instanceof Comment)) {
            return;
          }
          break;
        case "head":
          if (hadHead) {
            return;
          }
          hadHead = true;
          if (currentNode.childNodeSize() == 0 || currentNode.childNode(0) instanceof Element) {
            return;
          }
          break;
        case "body":
          if (currentNode.childNodeSize() == 0) {
            return;
          }
          Node firstChild = currentNode.childNode(0);
          if (firstChild instanceof Comment
              || CHILDREN_THAT_MAKE_BODY_OPEN_MANDATORY.contains(firstChild.nodeName())
              || startsWithWhitespace(firstChild)) {
            break;
          }
          return;
        case "tbody":
          if (currentNode.childNodeSize() > 0
              && currentNode.childNode(0).nodeName().equals("tr")
              && !omittedTableSectionEnd) {
            return;
          }
          break;
        default:
          // ignored
      }
    }
    // This method is package-private. We intend to beseech jsoup's author to make it public.
    currentNode.outerHtmlHead(output, depth, settings);
  }