lines static method

String lines(
  1. Object? value
)

Format multi-line text for placement inside a HTML element.

Any line breaks in the string is replaced by a <br/> break element. Each line is escaped using text. If there is only one line (i.e. there is no new line) no break elements are added.

The string representation is produced by invoking toString on the value.

If value is null, the empty string is returned.

Implementation

static String lines(Object? value) {
  if (value != null) {
    final buf = StringBuffer();
    var started = false;

    for (var line in value.toString().split('\n')) {
      if (started) {
        buf.write('<br/>');
      } else {
        started = true;
      }
      buf.write(HEsc.text(line));
    }
    return buf.toString();
  } else {
    return '';
  }
}