Search code examples
dartcomments

Dart doc comment escape square brackets


I have a simple enum with a doc comment wanting to display [] inside the comment:

/// Define the brackets used when displaying a `List` in a cell.
///
/// Supported bracket types are:
/// * parentheses: ()
/// * curly: {}
/// * square: []
enum ListBrackets {
  /// Use parentheses
  parentheses,
  /// Use curly brackets
  curly,
  /// Use square brackets
  square;
}

However all i get is: Define the brackets used when displaying a List in a cell. Supported bracket types are: parentheses: () curly: {} square:

Any help is appreciated


Solution

  • Escape the square brackets with a \:

    /// Define the brackets used when displaying a `List` in a cell.
    ///
    /// Supported bracket types are:
    /// * parentheses: ()
    /// * curly: {}
    /// * square: \[\]
    enum ListBrackets {
      /// Use parentheses
      parentheses,
      /// Use curly brackets
      curly,
      /// Use square brackets
      square;
    }
    

    (You could also only escape the first one: \[] but I prefer to escape both!)