convert method

  1. @override
String convert(
  1. String input
)
override

Converts the input delta to Markdown.

Implementation

@override
String convert(String input) {
  markdownBuffer = StringBuffer();
  lineBuffer = StringBuffer();
  currentInlineStyle = Style();
  currentBlockLines = <String>[];

  final inputJson = jsonDecode(input) as List<dynamic>?;
  if (inputJson is! List<dynamic>) {
    throw ArgumentError('Unexpected formatting of the input delta string.');
  }
  final delta = Delta.fromJson(inputJson);
  final iterator = DeltaIterator(delta);

  while (iterator.hasNext) {
    final operation = iterator.next();

    if (operation.data is String) {
      final operationData = operation.data as String;

      if (!operationData.contains('\n')) {
        _handleInline(lineBuffer, operationData, operation.attributes);
      } else {
        _handleLine(operationData, operation.attributes);
      }
    } else if (operation.data is Map<String, dynamic>) {
      _handleEmbed(operation.data as Map<String, dynamic>);
    } else {
      throw ArgumentError('Unexpected formatting of the input delta string.');
    }
  }

  _handleBlock(currentBlockStyle); // Close the last block

  return markdownBuffer.toString();
}