换行符,KDoc 中的新行

Line break, new line in KDoc

假设我们有这样的记录字符串

/** retrieve a state of the service
* <br/> HTTP code 200 - normal state
* <br/> HTTP code 403 - some recoverable state:
const val SERVICE_STATE = "servicestate" */

这里有几个<br/>,我用它来换行,就像我在java中做的那样,但是[=25=的输出]AndroidStudio(在 InteliJIdea 中似乎相同)是

与 java 正确解析和显示:

/** retrieve a state of the service
 * <br/> HTTP code 200 - normal state
 * <br/> HTTP code 403 - some recoverable state */
public static final String SERVICE_STATE = "servicestate";

我能否以某种方式使用 kotlin 和 IntelijIdea 实现相同的效果,也许 kotlin 有另一个选项来打破 KDoc 中的界限?

KDoc 格式 uses Markdown syntax 而不是 HTML,基本 Markdown 不提供在不开始新段落的情况下换行的方法。

我不确定为什么 Kotlin IntellIJ 插件不支持 <br/>double space hack.

如果可以开始一个新段落,只需跳过一个空行:

/** 
 * retrieve a state of the service
 *
 * HTTP code 200 - normal state
 *
 * HTTP code 403 - some recoverable state:
 */

结果是:

要添加到 ,您还可以使用三重反引号,因为支持 Markdown:

/**
 * Returns masked complement, i.e. expected value in the [maskBits] bits instead of a negative number because of
 * 2's complement representation
 *
 * For example, for 9:
 * ```
 *  Binary representation:         00...01001
 *  Complement:                    11...10110 which is -10
 *  Masking with 4 bits:  and with 00...01111
 *  So we get:                     00...00110 which is the expected bitwise complement
 * ```
 * @param maskBits Number of bits to mask the complement to
 * @return Decimal representation of the masked complement
 */
fun Int.inv(maskBits: Int) = inv() and 2.pow(maskBits) - 1

结果是: