nodeToOperation method
Converts a single DOM node into Delta operations using htmlToOp
.
Processes a single DOM node
and converts it into Delta operations using the provided htmlToOp
instance.
Parameters:
node
: The DOM node to convert into Delta operations.
Returns: A list of Operation objects representing the formatted content of the node.
Example:
final node = dparser.parseFragment('<strong>Hello</strong>');
final operations = converter.nodeToOperation(node.firstChild!, converter.htmlToOp);
print(operations); // Output: [Operation{insert: "Hello", attributes: {bold: true}}]
Implementation
List<Operation> nodeToOperation(
dom.Node node,
HtmlOperations htmlToOp, [
bool nextIsBlock = false,
]) {
List<Operation> operations = [];
if (node is dom.Text) {
operations
.add(Operation.insert(node.text));
}
if (node is dom.Element) {
if (blackNodesList.contains(node.localName)) {
if (nextIsBlock) operations.add(Operation.insert('\n'));
operations.add(
Operation.insert(node.text));
return operations;
}
List<Operation> ops = htmlToOp.resolveCurrentElement(node);
operations.addAll(ops);
if (nextIsBlock) operations.add(Operation.insert('\n'));
}
return operations;
}