nodeToOperation method

List<Operation> nodeToOperation(
  1. Node node,
  2. HtmlOperations htmlToOp
)

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) {
  List<Operation> operations = [];
  if (node is dom.Text) {
    operations.add(Operation.insert(trimText ? node.text.trim() : node.text));
  }
  if (node is dom.Element) {
    if (blackNodesList.contains(node.localName)) {
      operations
          .add(Operation.insert(trimText ? node.text.trim() : node.text));
      return operations;
    }
    List<Operation> ops = htmlToOp.resolveCurrentElement(node);
    operations.addAll(ops);
  }

  return operations;
}