6

I want to add a comment like this

  /**
   * @param scrollFraction In range [0..1].
   */

But Dokka/Kdoc interprets stuff inside square brackets as a reference. This leads to badly rendered comments when you check the function's documentation in the IDE or generate the docs. How can I escape square brackets/other symbols in Dokka/Kdoc?

Dmitry Ryadnenko
  • 22,222
  • 4
  • 42
  • 56

2 Answers2

11

You should be able to do it using ` symbol, like this:

 /**
  * @param scrollFraction In range `[0..1]`.
  */

However, using ` symbol will show everything in between as a code block.

To just use square brackets without a reference inside, use HTML symbols, like [ and ] from the @yuvgin's answer.

Demigod
  • 5,073
  • 3
  • 31
  • 49
  • 2
    This also typesets the contents within backticks in a code font, instead of the regular font. Therefore this answer solves the issue of the question, while introducing its own issue. – Erik Oct 21 '20 at 15:35
11

You can use HTML escaping:

 /**
   * @param scrollFraction In range [0..1].
   */

should output in Dokka as range [0..1]., since [ escapes as [ and ] escapes as ].

Note this will not work inside a section of inline code (between grave accents - like this).
For such cases use square brackets ([ and ]) normally, as was suggested in Demigod's answer.

yuvgin
  • 1,322
  • 1
  • 12
  • 27