toHtmlText method

String toHtmlText()

Convert to HTML Text.

Implementation

String toHtmlText() {
  if (this == null) {
    throw ArgumentError('string: $this');
  }
  return this!.replaceAllMapped(RegExp(r'([<>&])'), (match) {
    final char = match.group(1)!;
    if (char == '<') {
      return '&lt;';
    } else if (char == '>') {
      return '&gt;';
    } else if (char == '&') {
      return '&amp;';
    } else {
      return char;
    }
  });
}