extractCodeBlocks function
Extract fenced code blocks from Markdown text.
Returns a list of (language, code) pairs.
Implementation
List<({String language, String code})> extractCodeBlocks(String text) {
final re = RegExp(r'```(\w*)\n([\s\S]*?)```', multiLine: true);
return re.allMatches(text).map((m) {
return (language: m.group(1) ?? '', code: m.group(2) ?? '');
}).toList();
}