addSection method

Future<MemoryFile> addSection(
  1. String path, {
  2. required String heading,
  3. required String content,
  4. int level = 2,
})

Add a section to a memory file.

Implementation

Future<MemoryFile> addSection(
  String path, {
  required String heading,
  required String content,
  int level = 2,
}) async {
  final existing = _files[path];
  final currentContent = existing?.content ?? '';

  final newSection = '\n\n${'#' * level} $heading\n\n$content';
  final updated = currentContent + newSection;

  return save(path, updated);
}