divToOp method

  1. @override
List<Operation> divToOp(
  1. Element element
)
override

Converts a div HTML element (<div>) to Delta operations.

Implementation

@override
List<Operation> divToOp(dom.Element element) {
  final Delta delta = Delta();
  Map<String, dynamic> attributes = {};

  if (element.attributes.containsKey('style')) {
    final String style = element.attributes['style']!;
    final styleAttributes = parseStyleAttribute(style);
    attributes.addAll(styleAttributes);
  }
  for (final node in element.nodes) {
    if (node.nodeType == dom.Node.TEXT_NODE) {
      delta.insert(node.text);
    } else if (node.nodeType == dom.Node.ELEMENT_NODE) {
      final ops = resolveCurrentElement(node as dom.Element);
      for (final op in ops) {
        delta.insert(op.data, op.attributes);
      }
      if (node.isParagraph) {
        delta.insert('\n');
      }
    }
  }

  return delta.toList();
}