paragraphToOp method
Converts a paragraph HTML element (<p>
) to Delta operations.
Implementation
@override
List<Operation> paragraphToOp(dom.Element element) {
final Delta delta = Delta();
final attributes = element.attributes;
Map<String, dynamic> inlineAttributes = {};
Map<String, dynamic> blockAttributes = {};
// Process the style attribute
if (attributes.containsKey('style') ||
attributes.containsKey('align') ||
attributes.containsKey('dir')) {
final String style = attributes['style'] ?? '';
final String? styles2 = attributes['align'];
final String? styles3 = attributes['dir'];
final styleAttributes = parseStyleAttribute(style);
final alignAttribute = parseStyleAttribute(styles2 ?? '');
final dirAttribute = parseStyleAttribute(styles3 ?? '');
styleAttributes.addAll({...alignAttribute, ...dirAttribute});
if (styleAttributes.containsKey('align') ||
styleAttributes.containsKey('direction') ||
styleAttributes.containsKey('indent')) {
blockAttributes['align'] = styleAttributes['align'];
blockAttributes['direction'] = styleAttributes['direction'];
blockAttributes['indent'] = styleAttributes['indent'];
styleAttributes.remove('align');
styleAttributes.remove('direction');
styleAttributes.remove('indent');
}
inlineAttributes.addAll(styleAttributes);
}
final nodes = element.nodes;
//this store into all nodes into a paragraph, and
//ensure getting all attributes or tags into a paragraph
for (final node in nodes) {
processNode(node, inlineAttributes, delta,
addSpanAttrs: true, customBlocks: customBlocks);
}
if (blockAttributes.isNotEmpty) {
blockAttributes.removeWhere((key, value) => value == null);
delta.insert('\n', blockAttributes);
}
return delta.toList();
}