extractFirstCodeBlock function
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;
}