private void generateValue(StringBuilder buffer,
                             PsiElement[] elements,
                             int startIndex,
                             InheritDocProvider<PsiElement[]> provider) {
    int predictOffset = startIndex < elements.length ? elements[startIndex].getTextOffset() + elements[startIndex].getText().length() : 0;
    StringBuilder htmlCodeBlockContents = null;
    Pair<String, String> htmlCodeBlockDelimiters = null;
    for (int i = startIndex; i < elements.length; i++) {
      if (elements[i].getTextOffset() > predictOffset) {
        if (htmlCodeBlockContents != null) {
          htmlCodeBlockContents.append(' ');
        }
        else {
          buffer.append(' ');
        }
      }
      predictOffset = elements[i].getTextOffset() + elements[i].getText().length();
      PsiElement element = elements[i];
      if (element instanceof PsiInlineDocTag tag) {
        String tagName = tag.getName();
        if (htmlCodeBlockContents != null) {
          if (CODE_TAG.equals(tagName)) {
            StringBuilder value = new StringBuilder();
            generateLiteralValue(value, tag, false);
            int offset = !value.isEmpty() && value.charAt(0) == ' ' ? 1 : 0;
            htmlCodeBlockContents.append(value, offset, value.length());
            continue;
          }
          else {
            buffer.append(htmlCodeBlockDelimiters.first);
            appendPlainText(buffer, htmlCodeBlockContents.toString());
            htmlCodeBlockContents = null;
            htmlCodeBlockDelimiters = null;
          }
        }
        switch (tagName) {
          case LINK_TAG -> generateLinkValue(tag, buffer, false);
          case LITERAL_TAG -> generateLiteralValue(buffer, tag, true);
          case CODE_TAG, SYSTEM_PROPERTY_TAG -> generateCodeValue(tag, buffer);
          case LINKPLAIN_TAG -> generateLinkValue(tag, buffer, true);
          case INHERIT_DOC_TAG -> {
            if (provider == null) continue;
            Pair<PsiElement[], InheritDocProvider<PsiElement[]>> inheritInfo = provider.getInheritDoc();
            if (inheritInfo != null) {
              generateValue(buffer, inheritInfo.first, inheritInfo.second);
            }
          }
          case DOC_ROOT_TAG -> buffer.append(getDocRoot());
          case VALUE_TAG -> generateValueValue(tag, buffer, element);
          case INDEX_TAG -> generateIndexValue(buffer, tag);
          case SUMMARY_TAG -> generateLiteralValue(buffer, tag, false);
          case SNIPPET_TAG -> generateSnippetValue(buffer, tag);
          case RETURN_TAG -> generateInlineReturnValue(buffer, tag, provider);
          default -> generateUnknownInlineTagValue(buffer, tag);
        }
      }
      else {
        String text;
        if (element instanceof PsiWhiteSpace) {
          text = getWhitespacesBeforeLFWhenLeadingAsterisk(element);
        }
        else {
          text = element.getText();
        }
        if (element.getPrevSibling() instanceof PsiInlineDocTag tag
            && htmlCodeBlockContents == null
            && isCodeBlock(tag)) {
          // Remove following </pre> fragment and whitespaces
          text = StringUtil.trimStart(StringUtil.trimLeading(text), "</pre>");
        }
        if (htmlCodeBlockContents != null) {
          htmlCodeBlockContents = appendHtmlCodeBlockContents(
            text, buffer, htmlCodeBlockContents, htmlCodeBlockDelimiters
          );
        }
        else {
          var delimitersWithIndex = findHtmlCodeBlockDelimitersAndIndex(text);
          if (delimitersWithIndex != null) {
            htmlCodeBlockDelimiters = delimitersWithIndex.first;
            int blockStart = delimitersWithIndex.second;
            appendPlainText(buffer, text.substring(0, blockStart));
            htmlCodeBlockContents = appendHtmlCodeBlockContents(
              text.substring(blockStart + htmlCodeBlockDelimiters.first.length()), buffer,
              new StringBuilder(), htmlCodeBlockDelimiters
            );
          }
          else {
            appendPlainText(buffer, text);
          }
        }
      }
    }
    if (htmlCodeBlockContents != null) {
      buffer.append(htmlCodeBlockDelimiters.first);
      appendPlainText(buffer, htmlCodeBlockContents.toString());
    }
  }
private void generateValue(StringBuilder buffer,
                             PsiElement[] elements,
                             int startIndex,
                             InheritDocProvider<PsiElement[]> provider)