resolveCurrentElement method

List<Operation> resolveCurrentElement(
  1. Element element, [
  2. int indentLevel = 0
])

Resolves the current HTML element into Delta operations.

Determines the type of HTML element and converts it into corresponding Delta operations.

Parameters:

  • element: The HTML element to convert into Delta operations.

Returns: A list of Delta operations corresponding to the HTML element.

Implementation

List<Operation> resolveCurrentElement(dom.Element element,
    [int indentLevel = 0]) {
  List<Operation> ops = [];
  if (element.localName == null) {
    return ops..add(Operation.insert(element.text));
  }
  // Inlines
  //
  // the current element could be into a <li> then it's node can be
  // a <strong> or a <em>, or even a <span> then we first need to verify
  // if a inline an store into it to parse the attributes as we need
  if (isInline(element.localName!)) {
    final Delta delta = Delta();
    final Map<String, dynamic> attributes = {};
    if (element.isStrong) attributes['bold'] = true;
    if (element.isItalic) attributes['italic'] = true;
    if (element.isUnderline) attributes['underline'] = true;
    if (element.isStrike) attributes['strike'] = true;
    if (element.isSubscript) attributes['script'] = 'sub';
    if (element.isSuperscript) attributes['script'] = 'super';
    for (final node in element.nodes) {
      processNode(node, attributes, delta, customBlocks: customBlocks);
    }
    ops.addAll(delta.toList());
  }
  // Blocks
  if (element.isBreakLine) ops.addAll(brToOp(element));
  if (element.isParagraph) ops.addAll(paragraphToOp(element));
  if (element.isHeader) ops.addAll(headerToOp(element));
  if (element.isList) ops.addAll(listToOp(element, indentLevel));
  if (element.isSpan) ops.addAll(spanToOp(element));
  if (element.isLink) ops.addAll(linkToOp(element));
  if (element.isImg) ops.addAll(imgToOp(element));
  if (element.isVideo) ops.addAll(videoToOp(element));
  if (element.isBlockquote) ops.addAll(blockquoteToOp(element));
  if (element.isCodeBlock) ops.addAll(codeblockToOp(element));
  if (element.isDivBlock) ops.addAll(divToOp(element));
  return ops;
}