import re
import inspect


def extract_code_blocks_from_md(docstr):
    """
    Extract code blocks from markdown content.
    """
    code_blocks = []
    pat = re.compile(r"```i?python[23]?(.*?)```", re.MULTILINE + re.DOTALL)
    for cbit in pat.finditer(docstr):
        code_blocks.append(inspect.cleandoc(cbit.group()))
    # logger.info('extracted %d code blocks.', len(code_blocks))
    return code_blocks