【问题标题】:escape character in dart comments飞镖评论中的转义字符
【发布时间】:2021-03-17 15:06:36
【问题描述】:

我想在评论中描述一个半开期[start, end),其中startend 都指的是方法的参数:

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

intelij 是这样显示的:

使用\ 作为转义字符有同样的问题:

dart cmets 中的转义字符是什么? official documentation 似乎没有说明如何逃避[

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    我不知道你说的转义字符,但是你可以在你想显示的单个括号之后添加一对额外的括号:

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

    看起来像这样:

    当您将鼠标悬停在方法上时:

    【讨论】:

    • 我们最终这样做了。感觉超级奇怪,但至少提供了所需的文档结果。但是,在阅读文档的代码时会感到奇怪。
    【解决方案2】:

    通常方括号表示 dartdoc 应该自动为其生成链接的标识符。如果你想在生成的文档中使用方括号,你可以用反斜杠转义它们:

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

    例如the following comment:

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

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

    【讨论】:

    • \[[start] 也完全显示为绿色,如问题图片所示。但这可能是 intellij 显示插件中的错误。
    【解决方案3】:

    我还需要将括号作为范围的一部分进行注释。

    我最终用 3 个反引号 (```) 转义了整行

    缺点是我无法在该(代码)注释中引用任何参数/方法,但从好的方面来说,该注释在代码中仍然非常可读。

    如果您需要引用参数,可能会添加额外的行来执行此操作

    例如:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-24
      • 1970-01-01
      • 2019-03-17
      • 1970-01-01
      • 1970-01-01
      • 2020-12-07
      相关资源
      最近更新 更多