extractFirstCodeBlock function

String? extractFirstCodeBlock(
  1. String text
)

Extracts first fenced code block (lang\n...\n) or returns null.

Implementation

String? extractFirstCodeBlock(String text) {
  final RegExp fenced = RegExp(r'```[\w]*\n([\s\S]*?)```');
  final Match? m = fenced.firstMatch(text);
  return m != null ? m.group(1)?.trim() : null;
}