private void generateSnippetBody(@NotNull StringBuilder buffer, @NotNull PsiElement fileOrBody, @Nullable String region) {
    SnippetMarkup markup = fromElement(fileOrBody);
    if (!markup.hasMarkup(region)) {
      TextRange range = markup.getRegionRange(region);
      if (range == null) {
        buffer.append(getSpanForUnresolvedItem()).append(JavaBundle.message("javadoc.snippet.region.not.found", region))
          .append("</span>");
      }
      else if (fileOrBody instanceof PsiJavaFile) {
        // Normal Java highlighting is only for regions without markup
        generateJavaSnippetBody(buffer, fileOrBody,
                                e -> {
                                  TextRange textRange = e.getTextRange();
                                  return range.intersects(textRange) && markup.isTextPart(textRange);
                                });
      }
      else {
        buffer.append(markup.getTextWithoutMarkup(region));
      }
      return;
    }
    markup.visitSnippet(region, true, new SnippetVisitor() {
      @Override
      public void visitPlainText(@NotNull PlainText plainText,
                                 @NotNull List<@NotNull LocationMarkupNode> activeNodes) {
        String content = plainText.content();
        for (LocationMarkupNode node : activeNodes) {
          UnaryOperator<String> replacement;
          if (node instanceof Highlight highlight) {
            replacement = switch (highlight.type()) {
              case BOLD -> orig -> "<b>" + orig + "</b>";
              case ITALIC -> orig -> "<i>" + orig + "</i>";
              case HIGHLIGHTED -> {
                TextAttributes attributes =
                  EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES);
                yield orig -> getStyledSpan(true, attributes, orig);
              }
            };
          }
          else if (node instanceof Link link) {
            replacement = orig -> {
              StringBuilder buffer = new StringBuilder();
              DocumentationManagerUtil.createHyperlink(buffer, link.target(), orig, link.linkType() == LinkType.LINKPLAIN);
              return buffer.toString();
            };
          }
          else {
            throw new AssertionError(node.toString());
          }
          int pos = 0;
          StringBuilder sb = new StringBuilder();
          for (TextRange range : node.selector().ranges(content)) {
            sb.append(content, pos, range.getStartOffset());
            sb.append(replacement.apply(range.substring(content)));
            pos = range.getEndOffset();
          }
          sb.append(content, pos, content.length());
          content = sb.toString();
        }
        buffer.append(content);
      }

      @Override
      public void visitError(@NotNull ErrorMarkup errorMarkup) {
        buffer.append(getSpanForUnresolvedItem()).append("[").append(errorMarkup.message()).append("]</span>\n");
      }
    });
  }
private void generateSnippetBody(@NotNull StringBuilder buffer, @NotNull PsiElement fileOrBody, @Nullable String region)