def code_block(text):
    """Create a markdown formatted code block containing the given text"""
    text = '\n' + text
    for char in ['\n', '\r']:
        text = text.replace(char, '\n    ')
    return text