makeNode function
Implementation
FNode makeNode(String nodeType, dynamic options) {
switch (nodeType) {
case 'paragraph':
return Paragraph();
case 'link':
return Link(url: options['url'], text: options['text']);
case 'list':
final listType = options['listType'] as String? ?? 'bullet';
final list = FluentList(listType: listType);
// Create an initial ListItem with an empty Paragraph so the
// cursor has a fragment to land on.
final initialItem = ListItem(
bulletType: listType,
indexList: [1],
children: [Paragraph()],
);
list.items.add(initialItem);
return list;
case 'table':
final List<FluentRow> rows = [];
for (var i = 0; i < options['rows']; i++) {
final List<FluentCell> cells = [];
for (var j = 0; j < options['cells']; j++) {
cells.add(FluentCell()); // Default: empty paragraph
}
final currentRow = FluentRow(cells: cells);
rows.add(currentRow);
}
return FluentTable(rows: rows);
case 'image':
return FluentImage(options['src']);
case 'hr':
return HorizontalRule();
default:
return Paragraph();
}
}