parseChangelog method

Map<String, List<String>> parseChangelog(
  1. String content
)

Parses a changelog string in markdown format into a structured format.

Returns a map of version numbers to arrays of release notes.

Implementation

Map<String, List<String>> parseChangelog(String content) {
  try {
    if (content.isEmpty) return {};

    final releaseNotes = <String, List<String>>{};

    // Split by heading lines (## X.X.X)
    final sections = content.split(RegExp(r'^## ', multiLine: true));
    final relevantSections = sections.length > 1
        ? sections.sublist(1)
        : <String>[];

    for (final section in relevantSections) {
      final lines = section.trim().split('\n');
      if (lines.isEmpty) continue;

      final versionLine = lines[0];
      // First part before any dash is the version
      final version = versionLine.split(' - ').first.trim();
      if (version.isEmpty) continue;

      // Extract bullet points
      final notes = lines
          .sublist(1)
          .where((line) => line.trim().startsWith('- '))
          .map((line) => line.trim().substring(2).trim())
          .where((note) => note.isNotEmpty)
          .toList();

      if (notes.isNotEmpty) {
        releaseNotes[version] = notes;
      }
    }

    return releaseNotes;
  } catch (_) {
    return {};
  }
}