resolveAttributeValue method

String? resolveAttributeValue(
  1. DOMElement domElement,
  2. T element,
  3. String attrName,
  4. DOMTreeMap<T> treeMap, {
  5. bool preserveClass = false,
  6. bool preserveStyle = false,
})

Implementation

String? resolveAttributeValue(
    DOMElement domElement, T element, String attrName, DOMTreeMap<T> treeMap,
    {bool preserveClass = false, bool preserveStyle = false}) {
  var attr = domElement.getAttribute(attrName)!;
  var attrVal = attr.getValue(_domContext, treeMap);

  if (preserveClass && attrName == 'class') {
    var prev = getAttribute(element, attrName);
    if (prev != null && prev.isNotEmpty) {
      attrVal =
          attrVal != null && attrVal.isNotEmpty ? '$prev $attrVal' : prev;
    }
  } else if (preserveStyle && attrName == 'style') {
    var prev = getAttribute(element, attrName);
    if (prev != null && prev.isNotEmpty) {
      if (attrVal != null && attrVal.isNotEmpty) {
        attrVal = !prev.endsWith(';') ? '$prev; $attrVal' : '$prev $attrVal';
      } else {
        attrVal = prev;
      }
    }
  } else if ((attrName == 'src' || attrName == 'href') &&
      attrVal != null &&
      attrVal.isNotEmpty) {
    var attrVal2 = resolveSource(attrVal);

    if (attrVal != attrVal2) {
      setAttribute(element, '$attrName-original', attrVal);
      attrVal = attrVal2;
    }
  } else if (attr.isBoolean && DOMAttribute.isBooleanAttribute(attrName)) {
    if (attrVal != 'true') {
      return null;
    }
  }

  return attrVal;
}