createTableCells function

List<TABLENode> createTableCells(
  1. Object? rowCells, [
  2. bool header = false
])

Implementation

List<TABLENode> createTableCells(Object? rowCells, [bool header = false]) {
  if (rowCells is Iterable) {
    rowCells = rowCells.asList;
  }

  if (rowCells is List) {
    if (listMatchesAll(
        rowCells,
        (dynamic e) =>
            (!header && e is TDElement) || (header && e is THElement))) {
      return rowCells.whereType<TABLENode>().toList();
    } else if (listMatchesAll(
        rowCells, (dynamic e) => _domHTML.isHtmlNode(e))) {
      var tdList = rowCells.where((e) {
        var tag = _domHTML.getNodeTag(e);
        return (tag == 'td' || tag == 'th');
      });
      var list = tdList
          .map((e) => DOMNode.from(e))
          .nonNulls
          .whereType<TABLENode>()
          .toList();
      return list;
    }
  } else if (rowCells is TDElement || rowCells is THElement) {
    return [rowCells as TABLENode];
  }

  if (rowCells != null && rowCells is! Iterable) {
    rowCells = [rowCells];
  }

  List list;
  if (header) {
    list = $tags('th', rowCells as Iterable?);
  } else {
    list = $tags('td', rowCells as Iterable?);
  }

  return list.cast<TABLENode>().toList();
}