KDoc中的换行和新行是怎样的呢?

32
假设我们有这样的记录字符串。
/** 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中也是如此)的输出中是这样的: enter image description here

在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中换行?


如果有人正在寻找此功能,请在https://youtrack.jetbrains.com/issue/KTIJ-6702上投票! - TWiStErRob
3个回答

38

KDoc格式使用Markdown语法而不是HTML,基本的Markdown没有提供在不开启新段落的情况下换行的方法。

我不确定为什么Kotlin IntellIJ插件不支持<br/>或者双空格hack

如果开启新段落也可以的话,只需跳过一个空行:

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

结果是:

enter image description here


更新了答案 - 删除了多余的<br/>标签 - hotkey
似乎KDoc不会将新段落中的行考虑在内。 - Lore
8
在两行代码之间留空行怎么样?我找不到它。 - Thracian
双空格不是黑客技巧,而是在文档中描述的一项功能。 - TWiStErRob

10

除了@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


结果如下:

结果是:

enter image description here


1
加反引号表示加一 - Arpit Patel

3

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

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接