textParser function

Data? textParser(
  1. Parser parser,
  2. Data parentData,
  3. Map<String, Object> allData,
  4. bool debug,
)

Implementation

Data? textParser(
  Parser parser,
  Data parentData,
  Map<String, Object> allData,
  bool debug,
) {
  printLog("----------------------------------", debug, color: LogColor.yellow);
  printLog("ID: ${parser.id} Parser: Text", debug, color: LogColor.cyan);
  List<Element>? element = getElementObject(parentData);
  if (element == null || element.isEmpty) {
    printLog(
      "Text 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("Text Selector: $sel", debug, color: LogColor.cyan);
    String selector;
    if (sel.contains("<slot>")) {
      selector = inject("slot", allData, sel);
      printLog(
        "Text Selector Modified: $selector",
        debug,
        color: LogColor.green,
      );
    } else {
      selector = sel;
    }
    Object? data = textHandler(parser, document, selectr: selector);
    if (data != null && data != [] && data != "") {
      return Data(parentData.url, data);
    }
  }
  printLog(
    "Text Parser: No data found!",
    debug,
    color: LogColor.orange,
  );
  return null;
}