convert method

  1. @override
List<Operation> convert(
  1. Element element, {
  2. Map<String, dynamic>? currentAttributes,
})
override

Converts a 'pullquote' HTML element into Delta operations.

Parameters:

  • element: The 'pullquote' HTML element to convert.
  • currentAttributes: Optional map of current attributes to apply to the Delta operation.

Returns: A list of Delta operations representing the converted 'pullquote' element.

Example:

final element = dom.Element.html('<pullquote data-author="John Doe">This is a pullquote</pullquote>');
final operations = PullquoteBlock().convert(element);

Implementation

@override
List<Operation> convert(dom.Element element,
    {Map<String, dynamic>? currentAttributes}) {
  final Delta delta = Delta();
  final Map<String, dynamic> attributes =
      currentAttributes != null ? Map.from(currentAttributes) : {};

  final author = element.attributes['data-author'];
  final style = element.attributes['data-style'];

  // Build the text content of the pullquote
  String text = 'Pullquote: "${element.text}"';
  if (author != null) {
    text += ' by $author';
  }

  // Apply formatting based on 'data-style' attribute
  if (style != null && style.toLowerCase() == 'italic') {
    attributes['italic'] = true;
  }

  // Insert the formatted text into Delta operations
  delta.insert(text, attributes);
  delta.insert('\n'); // Ensure a newline after the pullquote

  return delta.toList();
}