toText static method

String toText(
  1. Object? nodes
)

Converts nodes to a text String.

Implementation

static String toText(Object? nodes) {
  if (nodes == null) return '';

  if (nodes is String) {
    return nodes;
  } else if (nodes is DOMNode) {
    return nodes.text;
  } else if (_domHTML.isHtmlNode(nodes)) {
    return _domHTML.getNodeText(nodes);
  } else if (nodes is Iterable) {
    nodes = nodes.asList;
    if (nodes.isEmpty) {
      return '';
    } else if (nodes.length == 1) {
      return toText(nodes.first);
    } else {
      return nodes.map(toText).join('');
    }
  } else if (nodes is Map) {
    return toText(nodes.values);
  } else {
    return nodes.toString();
  }
}