attrHandler function

Object? attrHandler(
  1. Parser parser,
  2. Element source, {
  3. required String selectr,
  4. required String attr,
})

Implementation

Object? attrHandler(
  Parser parser,
  Element source, {
  required String selectr,
  required String attr,
}) {
  if (parser.multiple) {
    List<Element> selector = source.querySelectorAll(selectr);
    if (selector.isNotEmpty) {
      List<String> result = [];
      for (final sel in selector) {
        String? attribute = sel.attributes[attr];
        if (attribute != null) {
          result.add(attribute.toString());
        }
      }
      return result;
    }
  } else {
    Element? selector = source.querySelector(selectr);
    if (selector != null) {
      String? attribute = selector.attributes[attr];
      if (attribute != null) {
        return attribute.toString();
      }
    }
  }
  return null;
}