import re


def remove_empty_lines_starting_cell(text: str) -> str:
    """Remove empty lines from start of cell.

    --- before ---
    # %% comment

    first_code = 'here'
    --- after ---
    # %% comment
    first_code = 'here'
    """
    # (?:\n\s*){2,} = non-capturing group for two or more new lines containing
    # only optional white space
    return re.sub(r"(?m)^(# %%[^\n]*)(?:\n\s*){2,}", r"\g<1>\n", text)