def indent(level):
    """For use as a mako filter.

    Returns a function that indents a block of text to the provided level.
    """

    def indent_text_to_level(text, level):
        result = ""
        indentation = level * "  "
        for line in text.splitlines(True):
            result = result + indentation + line
        return result

    return lambda text: indent_text_to_level(text, level)