from static method

DOMNode? from(
  1. Object? entry
)

Creates a DOMNode from dynamic parameter entry.

entry Can be a DOMNode, a String with HTML, a Text, a Function or an external element.

Implementation

static DOMNode? from(Object? entry) {
  if (entry == null) {
    return null;
  } else if (entry is DOMNode) {
    return entry;
  } else if (_domHTML.isHtmlNode(entry)) {
    return _domHTML.toDOMNode(entry);
  } else if (entry is Iterable) {
    var l = entry.asList;
    if (l.isEmpty) return null;
    l = entry.nonNulls.toList();
    if (l.isEmpty) return null;
    return DOMNode.from(l.single);
  } else if (entry is String) {
    if (isHTMLElement(entry)) {
      return parseHTML(entry)!.single;
    } else if (hasHTMLEntity(entry) || hasHTMLTag(entry)) {
      return parseHTML('<span>$entry</span>')!.single;
    } else {
      return TextNode.toTextNode(entry);
    }
  } else if (entry is num || entry is bool) {
    return TextNode(entry.toString());
  } else if (entry is DOMElementGenerator ||
      entry is DOMElementGeneratorFunction) {
    return ExternalElementNode(entry);
  } else {
    return ExternalElementNode(entry);
  }
}