【问题标题】:Line break, new line in KDoc换行,KDoc 中的换行
【发布时间】:2018-09-08 13:51:41
【问题描述】:

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

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

这里有几个&lt;br/&gt;,我以前用它换行,就像我在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 中的界限?

【问题讨论】:

    标签: android-studio intellij-idea kotlin kdoc


    【解决方案1】:

    要添加到@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
    
    

    结果是:

    【讨论】:

      【解决方案2】:

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

      我不确定为什么 Kotlin IntellIJ 插件不支持 &lt;br/&gt;double space hack

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

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

      结果是:

      【讨论】:

      • (更新了答案——去掉了多余的&lt;br/&gt;标签)
      • 似乎KDoc在新段落中没有换行。
      • 在两个代码行之间留一个空行怎么样?我没找到。
      猜你喜欢
      • 2019-04-04
      • 1970-01-01
      • 2014-10-11
      • 1970-01-01
      • 1970-01-01
      • 2018-10-09
      • 2016-11-16
      • 2015-06-04
      相关资源
      最近更新 更多