@SuppressWarnings("HardCodedStringLiteral")
  @Internal
  @Contract(pure = true)
  public static @Nls String decorate(@Nls @NotNull String text, @Nullable HtmlChunk location, @Nullable HtmlChunk links,
                                     @Nullable String downloadDocumentationActionLink) {
    text = StringUtil.replaceIgnoreCase(text, "</html>", "");
    text = StringUtil.replaceIgnoreCase(text, "</body>", "");

    var document = Jsoup.parse(text);
    if (document.select("." + CLASS_DEFINITION + ", ." + CLASS_CONTENT + ", ." + CLASS_SECTIONS).isEmpty()) {
      int bodyStart = findContentStart(text);
      if (bodyStart > 0) {
        text = text.substring(0, bodyStart) +
               CONTENT_START +
               text.substring(bodyStart) +
               CONTENT_END;
      }
      else {
        text = CONTENT_START + text + CONTENT_END;
      }
      // reparse the document
      document = Jsoup.parse(text);
    }

    DocumentationHtmlUtil.removeEmptySections$intellij_platform_lang_impl(document);

    if (downloadDocumentationActionLink != null) {
      document.body().appendChild(
        new Element("div")
          .addClass(CLASS_DOWNLOAD_DOCUMENTATION)
          .appendChildren(Arrays.asList(
            new Element("icon").attr("src", "AllIcons.Plugins.Downloads"),
            new TextNode(" "),
            new Element("a").attr("href", downloadDocumentationActionLink)
              .text(CodeInsightBundle.message("documentation.download.button.label"))
          )));
    }
    if (location != null) {
      document.body().append(getBottom().child(location).toString());
    }
    if (links != null) {
      document.body().append(getBottom().child(links).toString());
    }

    document.select("." + CLASS_DEFINITION + ", ." + CLASS_CONTENT + ", ." + CLASS_SECTIONS).forEach(
      div -> {
        var nextSibling = div.nextElementSibling();
        if (nextSibling == null) {
          return;
        }
        if (nextSibling.hasClass(CLASS_DEFINITION)
            || (nextSibling.hasClass(CLASS_CONTENT) && !div.hasClass(CLASS_SECTIONS))
            || (div.hasClass(CLASS_DEFINITION)
                && (
                  nextSibling.hasClass(CLASS_SECTIONS)
                  || nextSibling.hasClass(CLASS_BOTTOM)
                  || nextSibling.hasClass(CLASS_DOWNLOAD_DOCUMENTATION)
                ))) {
          div.after(new Element("hr"));
        }
      }
    );
    DocumentationHtmlUtil.addParagraphsIfNeeded$intellij_platform_lang_impl(
      document, "." + CLASS_CONTENT + ", table." + CLASS_SECTIONS + " td[valign=top]");
    DocumentationHtmlUtil.addExternalLinkIcons$intellij_platform_lang_impl(document);
    document.outputSettings().prettyPrint(false);
    return document.html();
  }

@SuppressWarnings("HardCodedStringLiteral")
  @Internal
  @Contract(pure = true)
  public static @Nls String decorate(@Nls @NotNull String text, @Nullable HtmlChunk location, @Nullable HtmlChunk links,
                                     @Nullable String downloadDocumentationActionLink)