private @Nls String sanitizeHtml(@Nls StringBuilder buffer) {
    String text = buffer.toString();
    if (text.isEmpty()) return null;
    if (myElement != null) {  // PSI element refs can't be resolved without a context
      StringBuilder result = new StringBuilder();
      int lastRef = 0;

      if (text.toUpperCase(Locale.ROOT).contains("HREF=\"")) {
        PsiFile fromText = PsiFileFactory.getInstance(myProject)
          .createFileFromText("DUMMY__.html", HtmlFileType.INSTANCE, text, System.currentTimeMillis(), false);
        Collection<XmlTag> tags = PsiTreeUtil.findChildrenOfType(fromText, XmlTag.class);
        for (XmlTag tag : tags) {
          if (!tag.getName().toLowerCase(Locale.ROOT).equals("a")) {
            continue;
          }
          final XmlAttribute hrefAttribute = tag.getAttribute(HREF_ATTRIBUTE_NAME);
          if (hrefAttribute == null) {
            continue;
          }
          XmlAttributeValue hrefAttributeValueElement = hrefAttribute.getValueElement();
          if (hrefAttributeValueElement == null) {
            continue;
          }
          int groupStart = hrefAttributeValueElement.getValueTextRange().getStartOffset();
          int groupEnd = hrefAttributeValueElement.getValueTextRange().getEndOffset();
          result.append(text, lastRef, groupStart);
          String href = text.substring(groupStart, groupEnd);
          String reference = "";
          try {
            reference = createReferenceForRelativeLink(href, myElement);
          }
          catch (IndexNotReadyException e) {
            LOG.debug(e);
            result.replace(result.length() - 6, result.length(), "wrong-href=\""); // display text instead of link
          }
          result.append(ObjectUtils.notNull(reference, href));
          lastRef = groupEnd;
        }
      }

      if (lastRef > 0) {  // don't copy text over if there are no matches
        result.append(text, lastRef, text.length());
        text = result.toString(); //NON-NLS
      }
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug("Generated JavaDoc:");
      LOG.debug(text);
    }

    text = StringUtil.replaceIgnoreCase(text, "<p/>", "<p></p>"); //NON-NLS
    text = StringUtil.replace(text, "/>", ">");
    return text;
  }
private @Nls String sanitizeHtml(@Nls StringBuilder buffer)