简体   繁体   中英

escape character in dart comments

I want to describe a half-opened period [start, end) in a comment where both, start and end refer to a parameter of a method:

/// Gets all items within period [[start],[end])

Which is displayed by intelij like this:

在此处输入图像描述

Using \ as escape character has the same problem: 在此处输入图像描述

What is the escape character in dart comments? The official documentation seems not to state how to escape the [ .

I don't know the escape character you're talking about, but you can add an extra pair of brackets after the single bracket you want to show:

/// Gets all items within period [[][start],[end])

It will look like this:

在此处输入图像描述

and when you hover your mouse over the method:

在此处输入图像描述

Normally square brackets denote identifiers that dartdoc should automatically generate links for. If you want literal square brackets in the generated documentation, you can escape them with a backslash:

/// Gets all items within period \[[start],[end])

For example, the following comment :

/// A fraction in the range \[0, 1\] that represents what proportion of the
/// widget is visible (assuming rectangular bounding boxes).

Generates: https://pub.dev/documentation/visibility_detector/latest/visibility_detector/VisibilityInfo/visibleFraction.html

I also need to comment brackets as part of a range.

I ended up escaping the whole line with 3 backticks (```)

The disadvantage is I cannot refer to any parameters/methods in that (code) comment, but on the bright side the comment is still very readable in the code.

If you need to refer the parameters, an extra line might be added to do this

Eg:

/// ```
/// Gets all items within period [start,end]
/// ```
///
/// The referred values are [start], [end]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM