normalizeText method

  1. @protected
List<XmlNode> normalizeText(
  1. List<XmlNode> nodes
)

Implementation

@protected
List<XmlNode> normalizeText(List<XmlNode> nodes) {
  final result = <XmlNode>[];
  for (final node in nodes) {
    if (node is XmlText) {
      final text = node.text.trim().replaceAll(_whitespaceOrLineTerminators, ' ');
      if (text.isNotEmpty) {
        if (result.isNotEmpty && result.last is XmlText) {
          result.last = XmlTextSyntheticImpl(result.last.text + XmlToken.whitespace + text);
        } else if (node.text != text) {
          result.add(XmlTextSyntheticImpl(text));
        } else {
          result.add(node);
        }
      }
    } else {
      result.add(node);
    }
  }
  return result;
}