convert method

  1. @override
Document convert(
  1. List<Op> input
)
override

Converts input and returns the result of the conversion.

Implementation

@override
Document convert(List<Op> input) {
  // First group or split ops by lines (\n) because each line maps to a
  // BoustroParagraph.
  final paragraphs = <Paragraph>[];
  for (final line in _groupByLines(input)) {
    final first = line.ops.firstOrNull;
    if (first is InsertObjectOp) {
      assert(line.ops.length == 1,
          'InsertObjectOp was not in its own paragraph.');

      final key = first.type;
      final decoder = embedDecoders[key];
      if (decoder == null) {
        throw ArgumentError.value(
            input, 'input', 'Attribute with missing codec: ${first.type}.');
      }

      final embed = decoder(first.value.asMap());
      paragraphs.add(embed);
    } else {
      final paragraph = _opsToLine(line);
      paragraphs.add(paragraph);
    }
  }

  return Document(paragraphs);
}