KDoc: Insert code snippet

孤人 提交于 2019-12-08 14:34:00

问题


How do I insert a code snippet in KDoc, Kotlin's default documentation tool?

In Java, I can use the following:

/**
 * Example usage:
 *
 * <pre>
 * <code>&#64;JavaAnnotation
 * public void foo() {
 *     // Code
 * }
 * </code>
 * </pre>
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface JavaAnnotation {}

There seems to be no equivalent in Kotlin. I tried using Markdown, but inserting 2 spaces after line end does not line-break.


回答1:


You can use triple backticks:

/**
 * Example usage:
 *
 * ```
 * @JavaAnnotation
 * public void foo() {
 *     // Code
 * }
 * ```
 */


来源:https://stackoverflow.com/questions/40400593/kdoc-insert-code-snippet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!