convert method
Converts input
and returns the result of the conversion.
Implementation
@override
Document convert(Delta input) {
final iterator = input.iterator;
final document = Document.blank(withInitialText: false);
Node node = paragraphNode();
int index = 0;
while (iterator.moveNext()) {
final op = iterator.current;
final attributes = op.attributes;
if (op is TextInsert) {
if (op.text == _newLineSymbol) {
if (attributes != null) {
node = _applyListStyleIfNeeded(node, attributes);
node = _applyHeadingStyleIfNeeded(node, attributes);
node = _applyBlockquoteIfNeeded(node, attributes);
_applyIndentIfNeeded(node, attributes);
}
if (_isIndentBulletedList(attributes)) {
final level = _indentLevel(attributes);
final path = [
...nestedLists[level - 1]!.last.path,
nestedLists[level]!.length - 1,
];
document.insert(path, [node]);
} else {
document.insert([index++], [node]);
}
node = paragraphNode();
} else {
final texts = op.text.split('\n');
if (texts.length > 1) {
node.delta?.insert(texts[0]);
document.insert([index++], [node]);
node = paragraphNode(delta: Delta()..insert(texts[1]));
} else {
_applyStyle(node, op.text, attributes);
}
}
} else {
throw UnsupportedError('only support text insert operation');
}
}
if (index == 0) {
document.insert([index], [node]);
}
return document;
}