applyCollector static method
Implementation
static String? applyCollector(dom.Element element, String collector) {
final matcher = RegExp('\\\${(@)?(?<name>.+)}').firstMatch(collector);
if (matcher == null) {
throw FormatException('the patterns for collector is invalid');
}
final isAttribute = matcher.group(1) != null;
final name = matcher.namedGroup('name');
if (isAttribute) {
return element.attributes[name]?.trim();
}
switch (name) {
case 'parent()':
return element.parent?.outerHtml;
case 'html()':
return element.innerHtml;
case 'outerHtml()':
return element.outerHtml;
case 'text()':
return element.text;
default:
return null;
}
}