elementParser function
Implementation
Data? elementParser({
required Parser parser,
required Data parentData,
required Map<String, Object> allData,
required bool debug,
}) {
printLog("----------------------------------", debug, color: LogColor.yellow);
printLog("ID: ${parser.id} Parser: Element", debug, color: LogColor.cyan);
List<Element>? element = getElementObject(parentData);
if (element == null || element.isEmpty) {
printLog(
"Element Parser: Element not found!",
debug,
color: LogColor.red,
);
return null;
}
Element document;
if (element.length == 1) {
document = element[0];
} else {
throw UnimplementedError("Multiple elements not supported");
}
for (final sel in parser.selector) {
printLog("Element Selector: $sel", debug, color: LogColor.cyan);
String selector;
if (sel.contains("<slot>")) {
selector = inject("slot", allData, sel);
printLog(
"Element Selector Modified: $selector",
debug,
color: LogColor.green,
);
} else {
selector = sel;
}
Object? data = elemHandler(parser, document, selector: selector);
if (data != null && data != [] && data != "") {
return Data(parentData.url, data);
}
}
printLog(
"Element Parser: No data found!",
debug,
color: LogColor.orange,
);
return null;
}