extractCodeBlocks static method

List<String> extractCodeBlocks(
  1. String markdown
)

Extract the contents of all fenced code blocks from markdown.

Returns the raw code inside each block, without the fence markers or language tag.

Implementation

static List<String> extractCodeBlocks(String markdown) {
  return _codeBlockPattern
      .allMatches(markdown)
      .map((m) => m.group(1)!.trim())
      .where((block) => block.isNotEmpty)
      .toList();
}