private void emitClosingTagIfRequiredByHtml5()

in java/org/jsoup/nodes/Html5Printer.java [168:274]


  private void emitClosingTagIfRequiredByHtml5(int depth) throws IOException {
    omittedTableSectionEnd = false;
    if (isDocumentOrDoctype()) {
      return;
    }
    Node nextSibling = currentNode.nextSibling();
    if (currentNode instanceof Element) {
      switch (currentNode.nodeName()) {
        case "html":
        case "body":
          if (!(nextSibling instanceof Comment)) {
            return;
          }
          break;
        case "head":
          if (hadHeadClose) {
            return;
          }
          hadHeadClose = true;
          if (!(nextSibling instanceof Comment && startsWithWhitespace(nextSibling))) {
            return;
          }
          break;
        case "li":
          if (nextSibling == null || nextSibling.nodeName().equals("li")) {
            return;
          }
          break;
        case "dt":
          if (nextSibling != null
              && (nextSibling.nodeName().equals("dt") || nextSibling.nodeName().equals("dd"))) {
            return;
          }
          break;
        case "dd":
          if (nextSibling == null
              || nextSibling.nodeName().equals("dt")
              || nextSibling.nodeName().equals("dd")) {
            return;
          }
          break;
        case "p":
          if (!currentNode.parent().nodeName().equals("a")
              || nextSibling == null
              || SIBLINGS_THAT_MAKE_P_CLOSE_OPTIONAL.contains(nextSibling.nodeName())) {
            return;
          }
          break;
        case "rb":
        case "rt":
        case "rtc":
        case "rp":
          if (nextSibling == null
              || nextSibling.nodeName().equals("rb")
              || nextSibling.nodeName().equals("rtc")
              || nextSibling.nodeName().equals("rp")
              || (nextSibling.nodeName().equals("rt") && !currentNode.nodeName().equals("rtc"))) {
            return;
          }
          break;
        case "optgroup":
          if (nextSibling == null || nextSibling.nodeName().equals("optgroup")) {
            return;
          }
          break;
        case "option":
          if (nextSibling == null
              || nextSibling.nodeName().equals("option")
              || nextSibling.nodeName().equals("optgroup")) {
            return;
          }
          break;
        case "thead":
        case "tbody":
          if (nextSibling == null
              || nextSibling.nodeName().equals("tbody")
              || nextSibling.nodeName().equals("tfoot")) {
            omittedTableSectionEnd = true;
            return;
          }
          break;
        case "tfoot":
          if (nextSibling == null || nextSibling.nodeName().equals("tbody")) {
            omittedTableSectionEnd = true;
            return;
          }
          break;
        case "tr":
          if (nextSibling == null || nextSibling.nodeName().equals("tr")) {
            return;
          }
          break;
        case "td":
        case "th":
          if (nextSibling == null
              || nextSibling.nodeName().equals("tr")
              || nextSibling.nodeName().equals("th")) {
            return;
          }
          break;
        default:
          // ignored
      }
    }
    // This method is package-private. We intend to beseech jsoup's author to make it public.
    currentNode.outerHtmlTail(output, depth, settings);
  }