换行符,KDOC中的新行

bvk5enib  于 2022-10-07  发布在  其他
关注(0)|答案(3)|浏览(362)

假设我们有记录在案的字符串

/**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中所做的那样,但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的底线?

qncylg1j

qncylg1j1#

KDOC格式使用Markdown语法而不是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:
 */

结果是:

lx0bsm1f

lx0bsm1f2#

为了补充@hotkey的答案,你还可以使用三个反引号,因为支持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

结果是:

yruzcnhs

yruzcnhs3#

可以在列表中使用破折号。在这种情况下,不需要空行。

相关问题