def apply_min_indent()

in src/kernels/_vendored/convert_rst_to_mdx.py [0:0]


def apply_min_indent(text, min_indent):
    """
    Make sure all lines in a text are have a minimum indentation.

    Args:
        text (`str`): The text to treat.
        min_indent (`int`): The minimal indentation.

    Returns:
        `str`: The processed text.
    """
    lines = text.split("\n")
    idx = 0
    while idx < len(lines):
        if is_empty_line(lines[idx]):
            idx += 1
            continue
        indent = find_indent(lines[idx])
        if indent < min_indent:
            while idx < len(lines) and (
                find_indent(lines[idx]) >= indent or is_empty_line(lines[idx])
            ):
                if not is_empty_line(lines[idx]):
                    lines[idx] = " " * (min_indent - indent) + lines[idx]
                idx += 1
        else:
            idx += 1

    return "\n".join(lines)