imgToOp method

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

Converts an image HTML element (<img>) to Delta operations.

Implementation

@override
List<Operation> imgToOp(dom.Element element) {
  final String src = element.getSafeAttribute('src');
  final String styles = element.getSafeAttribute('style');
  final attributes =
      parseImageStyleAttribute(styles, element.getSafeAttribute('align'));
  if (src.isNotEmpty) {
    return [
      Operation.insert(
        {'image': src},
        styles.isEmpty
            ? null
            : {
                'style': attributes.entries
                    .map((entry) => '${entry.key}:${entry.value}')
                    .toList()
                    .join(';'),
              },
      )
    ];
  }
  return [];
}