getText method

  1. @override
String getText({
  1. String separator = '',
  2. bool strip = false,
})
inherited

Returns the text of an element.

Same like bs4element.string.

- separator - Strings will be concatenated using this separator.

- strip If true, strings will be stripped before being concatenated (strips whitespace from the beginning and end of each bit of text). false by default.

Implementation

@override
String getText({String separator = '', bool strip = false}) {
  if (separator.isEmpty && !strip) {
    return element?.text ?? _bs4.text;
  }

  final texts = _bs4.nextParsedAll
      .where((node) => node.nodeType == Node.TEXT_NODE)
      .map((textNode) => strip ? textNode.data.trim() : textNode.data)
      .toList()
    ..removeWhere((e) => e.isEmpty);

  return texts.join(separator);
}