attributesFromText method

Map<String, String> attributesFromText(
  1. String tag,
  2. String parseTarget
)

Implementation

Map<String, String> attributesFromText(String tag, String parseTarget) {
  final RegExp attrRegExp = RegExp(
    '([a-zA-Z_:][-a-zA-Z0-9_:.]*)\\s*=\\s*("([^"]*)"|\'([^\']*)\')',
    caseSensitive: false,
  );

  final attributes = <String, String>{};

  for (final match in attrRegExp.allMatches(parseTarget)) {
    final attrName = match.group(1);
    final attrValue =
        match.group(3) ??
        match.group(4); // 3 = double-quoted, 4 = single-quoted
    if (attrName != null && attrValue != null) {
      attributes[attrName] = attrValue;
    }
  }

  return attributes;
}