Search code examples
documentationznai

How can I render code segments in Java callout comments, using Znai?


I'm trying to output a bit of inline "code" segment1 from a Java comment into an inline code / monospace segment into a Callout Comment (say, with either backticks, the {@code} segment, or some other way), but I can't seem to find a way to do so.

For example, let's say I have a class called ClassName defined as follows:

// The `@Generated` annotation is added by the {@code AnnotationProcessor} to
// denote that there are elements of this class that have been generated.
@Generated("pkg.name.AnnotationProcessor")
public class ClassName {
  // ...
}

Now, let's say that I include the Java class into my markdown file, like so:

:include-java: code-snippets/java/output/ClassName.java {
  title: "Title",
  commentsType: "inline",
  wrap: true
}

In this example, I'd like the "@Generated" and "AnnotationProcessor" segments to render as @Generated and AnnotationProcessor in the Callout Comment. However, it renders as `@Generated` and `AnnotationProcessor`

Screenshot: Screenshot of the issue

Additionally, if there's a way to add a Code Reference to each of these segments?


Footnotes:

1 When I say "inline code segment", I mean something like this.


Solution

  • At the moment it is not yet supported by Znai. One of the reason is transformation of comments happen on the client side (browser) while the overall markdown capabilities are only available at the docs build time.

    It seems like a good idea to have this support. Please leave a feature request in issues.