import re


def ensure_two_blank_lines_preceding_cell(text: str) -> str:
    """Ensure every cell delimiters has two preceding blank lines.
    Adds/deletes lines if there are less/more.

    --- before ---
    # %%
    some_code = 'here'
    # %%
    --- after ---
    # %%
    some_code = 'here'


    # %%
    """
    return re.sub(r"(?m)\n+^# %%", r"\n\n\n# %%", text)