extractSections method

Map<String, String> extractSections(
  1. String content
)

Implementation

Map<String, String> extractSections(String content) {
  final sectionRegex = RegExp(
    r"""@section\s*\(\s*['"](.+?)['"]\s*\)\s*([\s\S]+?)@endsection""",
  );

  sections.clear(); // clear old values

  for (final match in sectionRegex.allMatches(content)) {
    final name = match.group(1)!;
    final body = match.group(2)!.trim();
    sections[name] = body;
  }

  return sections;
}