snippetParser function

List<String> snippetParser(
  1. String text, [
  2. List<String>? snippets
])

Implementation

List<String> snippetParser(String text, [List<String>? snippets]) {
  const delimiter = '```dart';
  const delimeterEnd = '```';

  snippets ??= <String>[];
  final value = text.trimLeft();

  final startIndex = value.indexOf(delimiter);

  if (startIndex == -1) {
    return snippets;
  }

  final closeIndex = value.indexOf(delimeterEnd, startIndex + delimiter.length);

  if (closeIndex == -1) {
    return snippets;
  }

  final snippet = value.substring(startIndex + delimiter.length, closeIndex);

  snippets.add(snippet);

  return snippetParser(
    value.substring(closeIndex + delimeterEnd.length),
    snippets,
  );
}